@@ -4,7 +4,7 @@ const builtin = @import("builtin");
4
4
const Build = std .Build ;
5
5
const Step = Build .Step ;
6
6
const Compile = Step .Compile ;
7
- const LazyPath = Step .LazyPath ;
7
+ const LazyPath = Build .LazyPath ;
8
8
const Target = std .Target ;
9
9
const ResolvedTarget = std .Build .ResolvedTarget ;
10
10
const CrossTarget = std .zig .CrossTarget ;
@@ -21,18 +21,18 @@ const pathRel = fs.path.relative;
21
21
/// When updating this, make sure to adjust SetupZig.cmake
22
22
const recommended_zig_version = "0.14.0" ;
23
23
24
- comptime {
25
- if (! std .mem .eql (u8 , builtin .zig_version_string , recommended_zig_version )) {
26
- @compileError (
27
- "" ++
28
- "Bun requires Zig version " ++ recommended_zig_version ++ ", but you have " ++
29
- builtin .zig_version_string ++ ". This is automatically configured via Bun's " ++
30
- "CMake setup. You likely meant to run `bun run build`. If you are trying to " ++
31
- "upgrade the Zig compiler, edit ZIG_COMMIT in cmake/tools/SetupZig.cmake or " ++
32
- "comment this error out." ,
33
- );
34
- }
35
- }
24
+ // comptime {
25
+ // if (!std.mem.eql(u8, builtin.zig_version_string, recommended_zig_version)) {
26
+ // @compileError(
27
+ // "" ++
28
+ // "Bun requires Zig version " ++ recommended_zig_version ++ ", but you have " ++
29
+ // builtin.zig_version_string ++ ". This is automatically configured via Bun's " ++
30
+ // "CMake setup. You likely meant to run `bun run build`. If you are trying to " ++
31
+ // "upgrade the Zig compiler, edit ZIG_COMMIT in cmake/tools/SetupZig.cmake or " ++
32
+ // "comment this error out.",
33
+ // );
34
+ // }
35
+ // }
36
36
37
37
const zero_sha = "0000000000000000000000000000000000000000" ;
38
38
@@ -93,6 +93,7 @@ const BunBuildOptions = struct {
93
93
opts .addOption (bool , "baseline" , this .isBaseline ());
94
94
opts .addOption (bool , "enable_logs" , this .enable_logs );
95
95
opts .addOption ([]const u8 , "reported_nodejs_version" , b .fmt ("{}" , .{this .reported_nodejs_version }));
96
+ opts .addOption (bool , "zig_self_hosted_backend" , this .no_llvm );
96
97
97
98
const mod = opts .createModule ();
98
99
this .cached_options_module = mod ;
@@ -198,10 +199,7 @@ pub fn build(b: *Build) !void {
198
199
199
200
const bun_version = b .option ([]const u8 , "version" , "Value of `Bun.version`" ) orelse "0.0.0" ;
200
201
201
- b .reference_trace = ref_trace : {
202
- const trace = b .option (u32 , "reference-trace" , "Set the reference trace" ) orelse 24 ;
203
- break :ref_trace if (trace == 0 ) null else trace ;
204
- };
202
+ b .reference_trace = b .reference_trace orelse 32 ;
205
203
206
204
const obj_format = b .option (ObjectFormat , "obj_format" , "Output file for object files" ) orelse .obj ;
207
205
@@ -388,7 +386,22 @@ pub fn build(b: *Build) !void {
388
386
// zig build translate-c-headers
389
387
{
390
388
const step = b .step ("translate-c" , "Copy generated translated-c-headers.zig to zig-out" );
391
- step .dependOn (& b .addInstallFile (getTranslateC (b , b .graph .host , .Debug ).getOutput (), "translated-c-headers.zig" ).step );
389
+ for ([_ ]TargetDescription {
390
+ .{ .os = .windows , .arch = .x86_64 },
391
+ .{ .os = .mac , .arch = .x86_64 },
392
+ .{ .os = .mac , .arch = .aarch64 },
393
+ .{ .os = .linux , .arch = .x86_64 },
394
+ .{ .os = .linux , .arch = .aarch64 },
395
+ .{ .os = .linux , .arch = .x86_64 , .musl = true },
396
+ .{ .os = .linux , .arch = .aarch64 , .musl = true },
397
+ }) | t | {
398
+ const resolved = t .resolveTarget (b );
399
+ step .dependOn (
400
+ & b .addInstallFile (getTranslateC (b , resolved , .Debug ), b .fmt ("translated-c-headers/{s}.zig" , .{
401
+ resolved .result .zigTriple (b .allocator ) catch @panic ("OOM" ),
402
+ })).step ,
403
+ );
404
+ }
392
405
}
393
406
394
407
// zig build enum-extractor
@@ -405,23 +418,32 @@ pub fn build(b: *Build) !void {
405
418
}
406
419
}
407
420
408
- pub fn addMultiCheck (
421
+ const TargetDescription = struct {
422
+ os : OperatingSystem ,
423
+ arch : Arch ,
424
+ musl : bool = false ,
425
+
426
+ fn resolveTarget (desc : TargetDescription , b : * Build ) std.Build.ResolvedTarget {
427
+ return b .resolveTargetQuery (.{
428
+ .os_tag = OperatingSystem .stdOSTag (desc .os ),
429
+ .cpu_arch = desc .arch ,
430
+ .cpu_model = getCpuModel (desc .os , desc .arch ) orelse .determined_by_arch_os ,
431
+ .os_version_min = getOSVersionMin (desc .os ),
432
+ .glibc_version = if (desc .musl ) null else getOSGlibCVersion (desc .os ),
433
+ });
434
+ }
435
+ };
436
+
437
+ fn addMultiCheck (
409
438
b : * Build ,
410
439
parent_step : * Step ,
411
440
root_build_options : BunBuildOptions ,
412
- to_check : []const struct { os : OperatingSystem , arch : Arch , musl : bool = false } ,
441
+ to_check : []const TargetDescription ,
413
442
optimize : []const std.builtin.OptimizeMode ,
414
443
) void {
415
444
for (to_check ) | check | {
416
445
for (optimize ) | mode | {
417
- const check_target = b .resolveTargetQuery (.{
418
- .os_tag = OperatingSystem .stdOSTag (check .os ),
419
- .cpu_arch = check .arch ,
420
- .cpu_model = getCpuModel (check .os , check .arch ) orelse .determined_by_arch_os ,
421
- .os_version_min = getOSVersionMin (check .os ),
422
- .glibc_version = if (check .musl ) null else getOSGlibCVersion (check .os ),
423
- });
424
-
446
+ const check_target = check .resolveTarget (b );
425
447
var options : BunBuildOptions = .{
426
448
.target = check_target ,
427
449
.os = check .os ,
@@ -445,7 +467,13 @@ pub fn addMultiCheck(
445
467
}
446
468
}
447
469
448
- fn getTranslateC (b : * Build , target : std.Build.ResolvedTarget , optimize : std.builtin.OptimizeMode ) * Step.TranslateC {
470
+ fn getTranslateC (b : * Build , initial_target : std.Build.ResolvedTarget , optimize : std.builtin.OptimizeMode ) LazyPath {
471
+ const target = b .resolveTargetQuery (q : {
472
+ var query = initial_target .query ;
473
+ if (query .os_tag == .windows )
474
+ query .abi = .gnu ;
475
+ break :q query ;
476
+ });
449
477
const translate_c = b .addTranslateC (.{
450
478
.root_source_file = b .path ("src/c-headers-for-zig.h" ),
451
479
.target = target ,
@@ -461,7 +489,35 @@ fn getTranslateC(b: *Build, target: std.Build.ResolvedTarget, optimize: std.buil
461
489
const str , const value = entry ;
462
490
translate_c .defineCMacroRaw (b .fmt ("{s}={d}" , .{ str , @intFromBool (value ) }));
463
491
}
464
- return translate_c ;
492
+
493
+ if (target .result .os .tag == .windows ) {
494
+ // translate-c is unable to translate the unsuffixed windows functions
495
+ // like `SetCurrentDirectory` since they are defined with an odd macro
496
+ // that translate-c doesn't handle.
497
+ //
498
+ // #define SetCurrentDirectory __MINGW_NAME_AW(SetCurrentDirectory)
499
+ //
500
+ // In these cases, it's better to just reference the underlying function
501
+ // directly: SetCurrentDirectoryW. To make the error better, a post
502
+ // processing step is applied to the translate-c file.
503
+ //
504
+ // Additionally, this step makes it so that decls like NTSTATUS and
505
+ // HANDLE point to the standard library structures.
506
+ const helper_exe = b .addExecutable (.{
507
+ .name = "process_windows_translate_c" ,
508
+ .root_module = b .createModule (.{
509
+ .root_source_file = b .path ("src/codegen/process_windows_translate_c.zig" ),
510
+ .target = b .graph .host ,
511
+ .optimize = .Debug ,
512
+ }),
513
+ });
514
+ const in = translate_c .getOutput ();
515
+ const run = b .addRunArtifact (helper_exe );
516
+ run .addFileArg (in );
517
+ const out = run .addOutputFileArg ("c-headers-for-zig.zig" );
518
+ return out ;
519
+ }
520
+ return translate_c .getOutput ();
465
521
}
466
522
467
523
pub fn addBunObject (b : * Build , opts : * BunBuildOptions ) * Compile {
@@ -580,7 +636,7 @@ fn addInternalImports(b: *Build, mod: *Module, opts: *BunBuildOptions) void {
580
636
mod .addImport ("build_options" , opts .buildOptionsModule (b ));
581
637
582
638
const translate_c = getTranslateC (b , opts .target , opts .optimize );
583
- mod .addImport ("translated-c-headers" , translate_c .createModule ());
639
+ mod .addImport ("translated-c-headers" , b .createModule (.{ . root_source_file = translate_c } ));
584
640
585
641
const zlib_internal_path = switch (os ) {
586
642
.windows = > "src/deps/zlib.win32.zig" ,
0 commit comments