@@ -23,20 +23,14 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
2323 const minilua_mod = b .createModule (.{
2424 .target = b .graph .host , // Use host target for cross build
2525 .optimize = .ReleaseSafe ,
26+ .link_libc = true ,
27+ .sanitize_c = .off ,
2628 });
2729 const minilua = b .addExecutable (.{
2830 .name = "minilua" ,
2931 .root_module = minilua_mod ,
3032 });
31- minilua .linkLibC ();
32- // FIXME: remove branch when zig-0.15 is released and 0.14 can be dropped
33- const builtin = @import ("builtin" );
34- if (builtin .zig_version .major == 0 and builtin .zig_version .minor < 15 ) {
35- minilua .root_module .sanitize_c = false ;
36- } else {
37- minilua .root_module .sanitize_c = .off ;
38- }
39- minilua .addCSourceFile (.{ .file = upstream .path ("src/host/minilua.c" ) });
33+ minilua .root_module .addCSourceFile (.{ .file = upstream .path ("src/host/minilua.c" ) });
4034
4135 // Generate the buildvm_arch.h file using minilua
4236 const dynasm_run = b .addRunArtifact (minilua );
@@ -108,42 +102,42 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
108102 const vm_mod = b .createModule (.{
109103 .target = b .graph .host , // Use host target for cross build
110104 .optimize = .ReleaseSafe ,
105+ .link_libc = true ,
106+ .sanitize_c = .off ,
111107 });
112108 const buildvm = b .addExecutable (.{
113109 .name = "buildvm" ,
114110 .root_module = vm_mod ,
115111 });
116- buildvm .linkLibC ();
117- // FIXME: remove branch when zig-0.15 is released and 0.14 can be dropped
118- if (builtin .zig_version .major == 0 and builtin .zig_version .minor < 15 ) {
119- buildvm .root_module .sanitize_c = false ;
120- } else {
121- buildvm .root_module .sanitize_c = .off ;
122- }
123112
124113 // Needs to run after the buildvm_arch.h and luajit.h files are generated
125114 buildvm .step .dependOn (& dynasm_run .step );
126115 buildvm .step .dependOn (& genversion_run .step );
127116
128117 const buildvm_c_flags : []const []const u8 = switch (target .result .cpu .arch ) {
129118 .aarch64 , .aarch64_be = > &.{ "-DLUAJIT_TARGET=LUAJIT_ARCH_arm64" , "-DLJ_ARCH_HASFPU=1" , "-DLJ_ABI_SOFTFP=0" },
130- .x86_64 = > &.{ "-DLUAJIT_TARGET=LUAJIT_ARCH_X64" },
119+ .x86_64 = > &.{"-DLUAJIT_TARGET=LUAJIT_ARCH_X64" },
131120 else = > &.{},
132121 };
133122
134- buildvm .addCSourceFiles (.{
123+ const buildvm_windows_c_flags : []const []const u8 = if (target .result .os .tag == .windows )
124+ &.{"-DLUAJIT_OS=1" }
125+ else
126+ &.{};
127+
128+ buildvm .root_module .addCSourceFiles (.{
135129 .root = .{ .dependency = .{
136130 .dependency = upstream ,
137131 .sub_path = "" ,
138132 } },
139133 .files = &.{ "src/host/buildvm_asm.c" , "src/host/buildvm_fold.c" , "src/host/buildvm_lib.c" , "src/host/buildvm_peobj.c" , "src/host/buildvm.c" },
140- .flags = buildvm_c_flags ,
134+ .flags = std . mem . concat ( b . allocator , [] const u8 , &.{ buildvm_c_flags , buildvm_windows_c_flags }) catch @panic ( "OOM!" ) ,
141135 });
142136
143- buildvm .addIncludePath (upstream .path ("src" ));
144- buildvm .addIncludePath (upstream .path ("src/host" ));
145- buildvm .addIncludePath (buildvm_arch_h .dirname ());
146- buildvm .addIncludePath (luajit_h .dirname ());
137+ buildvm .root_module . addIncludePath (upstream .path ("src" ));
138+ buildvm .root_module . addIncludePath (upstream .path ("src/host" ));
139+ buildvm .root_module . addIncludePath (buildvm_arch_h .dirname ());
140+ buildvm .root_module . addIncludePath (luajit_h .dirname ());
147141
148142 // Use buildvm to generate files and headers used in the final vm
149143 const buildvm_bcdef = b .addRunArtifact (buildvm );
@@ -208,19 +202,19 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
208202 library .step .dependOn (& buildvm_folddef .step );
209203 library .step .dependOn (& buildvm_ljvm .step );
210204
211- library .linkLibC () ;
205+ library .is_linking_libc = true ;
212206
213207 lib .addCMacro ("LUAJIT_UNWIND_EXTERNAL" , "" );
214208
215209 lib .linkSystemLibrary ("unwind" , .{});
216210
217- library .addIncludePath (upstream .path ("src" ));
218- library .addIncludePath (luajit_h .dirname ());
219- library .addIncludePath (bcdef_header .dirname ());
220- library .addIncludePath (ffdef_header .dirname ());
221- library .addIncludePath (libdef_header .dirname ());
222- library .addIncludePath (recdef_header .dirname ());
223- library .addIncludePath (folddef_header .dirname ());
211+ library .root_module . addIncludePath (upstream .path ("src" ));
212+ library .root_module . addIncludePath (luajit_h .dirname ());
213+ library .root_module . addIncludePath (bcdef_header .dirname ());
214+ library .root_module . addIncludePath (ffdef_header .dirname ());
215+ library .root_module . addIncludePath (libdef_header .dirname ());
216+ library .root_module . addIncludePath (recdef_header .dirname ());
217+ library .root_module . addIncludePath (folddef_header .dirname ());
224218
225219 lib .addCSourceFiles (.{
226220 .root = .{ .dependency = .{
@@ -230,12 +224,7 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
230224 .files = & luajit_vm ,
231225 });
232226
233- // FIXME: remove branch when zig-0.15 is released and 0.14 can be dropped
234- if (builtin .zig_version .major == 0 and builtin .zig_version .minor < 15 ) {
235- lib .sanitize_c = false ;
236- } else {
237- lib .sanitize_c = .off ;
238- }
227+ lib .sanitize_c = .off ;
239228
240229 library .installHeader (upstream .path ("src/lua.h" ), "lua.h" );
241230 library .installHeader (upstream .path ("src/lualib.h" ), "lualib.h" );
0 commit comments