@@ -33,8 +33,6 @@ comptime {
33
33
}
34
34
}
35
35
36
- const default_reported_nodejs_version = "22.3.0" ;
37
-
38
36
const zero_sha = "0000000000000000000000000000000000000000" ;
39
37
40
38
const BunBuildOptions = struct {
@@ -48,7 +46,7 @@ const BunBuildOptions = struct {
48
46
sha : []const u8 ,
49
47
enable_logs : bool = false ,
50
48
tracy_callstack_depth : u16 ,
51
- reported_nodejs_version : [] const u8 = default_reported_nodejs_version ,
49
+ reported_nodejs_version : Version ,
52
50
53
51
generated_code_dir : []const u8 ,
54
52
@@ -73,14 +71,7 @@ const BunBuildOptions = struct {
73
71
opts .addOption ([:0 ]const u8 , "sha" , b .allocator .dupeZ (u8 , this .sha ) catch @panic ("OOM" ));
74
72
opts .addOption (bool , "baseline" , this .isBaseline ());
75
73
opts .addOption (bool , "enable_logs" , this .enable_logs );
76
- opts .addOption ([:0 ]const u8 , "reported_nodejs_version" , b .allocator .dupeZ (u8 , this .reported_nodejs_version ) catch @panic ("OOM" ));
77
- if (this .reported_nodejs_version .len > 0 and this .reported_nodejs_version [0 ] == 'v' ) {
78
- @panic ("Node.js version should not start with 'v'" );
79
- }
80
-
81
- if (this .reported_nodejs_version .len == 0 ) {
82
- @panic ("Node.js version should not be empty" );
83
- }
74
+ opts .addOption ([]const u8 , "reported_nodejs_version" , b .fmt ("{}" , .{this .reported_nodejs_version }));
84
75
85
76
const mod = opts .createModule ();
86
77
this .cached_options_module = mod ;
@@ -122,6 +113,23 @@ pub fn getOSGlibCVersion(os: OperatingSystem) ?Version {
122
113
};
123
114
}
124
115
116
+ pub fn getCpuModel (os : OperatingSystem , arch : Arch ) ? Target.Query.CpuModel {
117
+ // https://github.com/oven-sh/bun/issues/12076
118
+ if (os == .linux and arch == .aarch64 ) {
119
+ return .{ .explicit = & Target .aarch64 .cpu .cortex_a35 };
120
+ }
121
+
122
+ // Be explicit and ensure we do not accidentally target a newer M-series chip
123
+ if (os == .mac and arch == .aarch64 ) {
124
+ return .{ .explicit = & Target .aarch64 .cpu .apple_m1 };
125
+ }
126
+
127
+ // note: x86_64 is dealt with in the CMake config and passed in.
128
+ // the reason for the explicit handling on aarch64 is due to troubles
129
+ // passing the exact target in via flags.
130
+ return null ;
131
+ }
132
+
125
133
pub fn build (b : * Build ) ! void {
126
134
std .log .info ("zig compiler v{s}" , .{builtin .zig_version_string });
127
135
@@ -147,9 +155,12 @@ pub fn build(b: *Build) !void {
147
155
break :brk .{ os , arch };
148
156
};
149
157
150
- if (os == .linux and arch == .aarch64 ) {
151
- // #12076
152
- target_query .cpu_model = .{ .explicit = & std .Target .aarch64 .cpu .cortex_a35 };
158
+ // target must be refined to support older but very popular devices on
159
+ // aarch64, this means moving the minimum supported CPU to support certain
160
+ // raspberry PIs. there are also a number of cloud hosts that use virtual
161
+ // machines with surprisingly out of date versions of glibc.
162
+ if (getCpuModel (os , arch )) | cpu_model | {
163
+ target_query .cpu_model = cpu_model ;
153
164
}
154
165
155
166
target_query .os_version_min = getOSVersionMin (os );
@@ -168,6 +179,8 @@ pub fn build(b: *Build) !void {
168
179
break :ref_trace if (trace == 0 ) null else trace ;
169
180
};
170
181
182
+ const obj_format = b .option (ObjectFormat , "obj_format" , "Output file for object files" ) orelse .obj ;
183
+
171
184
var build_options = BunBuildOptions {
172
185
.target = target ,
173
186
.optimize = optimize ,
@@ -183,7 +196,10 @@ pub fn build(b: *Build) !void {
183
196
break :canary if (rev == 0 ) null else rev ;
184
197
},
185
198
186
- .reported_nodejs_version = b .option ([]const u8 , "reported_nodejs_version" , "Reported Node.js version" ) orelse default_reported_nodejs_version ,
199
+ .reported_nodejs_version = try Version .parse (
200
+ b .option ([]const u8 , "reported_nodejs_version" , "Reported Node.js version" ) orelse
201
+ "0.0.0-unset" ,
202
+ ),
187
203
188
204
.sha = sha : {
189
205
const sha = b .option ([]const u8 , "sha" , "Force the git sha" ) orelse
@@ -229,7 +245,7 @@ pub fn build(b: *Build) !void {
229
245
var step = b .step ("obj" , "Build Bun's Zig code as a .o file" );
230
246
var bun_obj = addBunObject (b , & build_options );
231
247
step .dependOn (& bun_obj .step );
232
- step .dependOn (& b . addInstallFile ( bun_obj . getEmittedBin () , "bun-zig.o" ). step );
248
+ step .dependOn (addInstallObjectFile ( b , bun_obj , "bun-zig" , obj_format ) );
233
249
}
234
250
235
251
// zig build windows-shim
@@ -257,95 +273,59 @@ pub fn build(b: *Build) !void {
257
273
258
274
// zig build check-all
259
275
{
260
- var step = b .step ("check-all" , "Check for semantic analysis errors on all supported platforms" );
261
- inline for ( .{
276
+ const step = b .step ("check-all" , "Check for semantic analysis errors on all supported platforms" );
277
+ addMultiCheck ( b , step , build_options , & .{
262
278
.{ .os = .windows , .arch = .x86_64 },
263
279
.{ .os = .mac , .arch = .x86_64 },
264
280
.{ .os = .mac , .arch = .aarch64 },
265
281
.{ .os = .linux , .arch = .x86_64 },
266
282
.{ .os = .linux , .arch = .aarch64 },
267
- }) | check | {
268
- inline for (.{ .Debug , .ReleaseFast }) | mode | {
269
- const check_target = b .resolveTargetQuery (.{
270
- .os_tag = OperatingSystem .stdOSTag (check .os ),
271
- .cpu_arch = check .arch ,
272
- .cpu_model = if (check .os == .linux and check .arch == .aarch64 ) .{ .explicit = & std .Target .aarch64 .cpu .cortex_a35 } else .{ .determined_by_cpu_arch = {} },
273
- .os_version_min = getOSVersionMin (check .os ),
274
- .glibc_version = getOSGlibCVersion (check .os ),
275
- });
276
-
277
- var options = BunBuildOptions {
278
- .target = check_target ,
279
- .os = check .os ,
280
- .arch = check_target .result .cpu .arch ,
281
- .optimize = mode ,
282
-
283
- .canary_revision = build_options .canary_revision ,
284
- .sha = build_options .sha ,
285
- .tracy_callstack_depth = build_options .tracy_callstack_depth ,
286
- .version = build_options .version ,
287
- .reported_nodejs_version = build_options .reported_nodejs_version ,
288
- .generated_code_dir = build_options .generated_code_dir ,
289
- };
290
- var obj = addBunObject (b , & options );
291
- obj .generated_bin = null ;
292
- step .dependOn (& obj .step );
293
- }
294
- }
283
+ });
295
284
}
296
285
297
286
// zig build check-windows
298
287
{
299
- var step = b .step ("check-windows" , "Check for semantic analysis errors on Windows x64 " );
300
- inline for ( .{
288
+ const step = b .step ("check-windows" , "Check for semantic analysis errors on Windows" );
289
+ addMultiCheck ( b , step , build_options , & .{
301
290
.{ .os = .windows , .arch = .x86_64 },
302
- }) | check | {
303
- inline for (.{ .Debug , .ReleaseFast }) | mode | {
304
- const check_target = b .resolveTargetQuery (.{
305
- .os_tag = OperatingSystem .stdOSTag (check .os ),
306
- .cpu_arch = check .arch ,
307
- .os_version_min = getOSVersionMin (check .os ),
308
- .glibc_version = getOSGlibCVersion (check .os ),
309
- });
310
-
311
- var options = BunBuildOptions {
312
- .target = check_target ,
313
- .os = check .os ,
314
- .arch = check_target .result .cpu .arch ,
315
- .optimize = mode ,
316
- .canary_revision = build_options .canary_revision ,
317
- .sha = build_options .sha ,
318
- .tracy_callstack_depth = build_options .tracy_callstack_depth ,
319
- .version = build_options .version ,
320
- .reported_nodejs_version = build_options .reported_nodejs_version ,
321
- .generated_code_dir = build_options .generated_code_dir ,
322
- };
323
- var obj = addBunObject (b , & options );
324
- obj .generated_bin = null ;
325
- step .dependOn (& obj .step );
326
- }
327
- }
291
+ });
328
292
}
293
+ }
329
294
330
- // Running `zig build` with no arguments is almost always a mistake.
331
- // TODO: revive this error. cannot right now since ZLS runs zig build without arguments
332
- {
333
- // const mistake_message = b.addSystemCommand(&.{
334
- // "echo",
335
- // \\
336
- // \\To build Bun from source, please use `bun run setup` instead of `zig build`"
337
- // \\For more info, see https://bun.sh/docs/project/contributing
338
- // \\
339
- // \\If you want to build the zig code in isolation, run:
340
- // \\ 'zig build obj -Dgenerated-code=./build/codegen [...opts]'
341
- // \\
342
- // \\If you want to test a compile without emitting an object:
343
- // \\ 'zig build check'
344
- // \\ 'zig build check-all' (run linux+mac+windows)
345
- // \\
346
- // });
347
-
348
- // b.default_step.dependOn(&mistake_message.step);
295
+ pub inline fn addMultiCheck (
296
+ b : * Build ,
297
+ parent_step : * Step ,
298
+ root_build_options : BunBuildOptions ,
299
+ to_check : []const struct { os : OperatingSystem , arch : Arch },
300
+ ) void {
301
+ inline for (to_check ) | check | {
302
+ inline for (.{ .Debug , .ReleaseFast }) | mode | {
303
+ const check_target = b .resolveTargetQuery (.{
304
+ .os_tag = OperatingSystem .stdOSTag (check .os ),
305
+ .cpu_arch = check .arch ,
306
+ .cpu_model = getCpuModel (check .os , check .arch ) orelse .determined_by_cpu_arch ,
307
+ .os_version_min = getOSVersionMin (check .os ),
308
+ .glibc_version = getOSGlibCVersion (check .os ),
309
+ });
310
+
311
+ var options : BunBuildOptions = .{
312
+ .target = check_target ,
313
+ .os = check .os ,
314
+ .arch = check_target .result .cpu .arch ,
315
+ .optimize = mode ,
316
+
317
+ .canary_revision = root_build_options .canary_revision ,
318
+ .sha = root_build_options .sha ,
319
+ .tracy_callstack_depth = root_build_options .tracy_callstack_depth ,
320
+ .version = root_build_options .version ,
321
+ .reported_nodejs_version = root_build_options .reported_nodejs_version ,
322
+ .generated_code_dir = root_build_options .generated_code_dir ,
323
+ };
324
+
325
+ var obj = addBunObject (b , & options );
326
+ obj .generated_bin = null ;
327
+ parent_step .dependOn (& obj .step );
328
+ }
349
329
}
350
330
}
351
331
@@ -392,6 +372,25 @@ pub fn addBunObject(b: *Build, opts: *BunBuildOptions) *Compile {
392
372
return obj ;
393
373
}
394
374
375
+ const ObjectFormat = enum {
376
+ bc ,
377
+ obj ,
378
+ };
379
+
380
+ pub fn addInstallObjectFile (
381
+ b : * Build ,
382
+ compile : * Compile ,
383
+ name : []const u8 ,
384
+ out_mode : ObjectFormat ,
385
+ ) * Step {
386
+ // bin always needed to be computed or else the compilation will do nothing. zig build system bug?
387
+ const bin = compile .getEmittedBin ();
388
+ return & b .addInstallFile (switch (out_mode ) {
389
+ .obj = > bin ,
390
+ .bc = > compile .getEmittedLlvmBc (),
391
+ }, b .fmt ("{s}.o" , .{name })).step ;
392
+ }
393
+
395
394
fn exists (path : []const u8 ) bool {
396
395
const file = std .fs .openFileAbsolute (path , .{ .mode = .read_only }) catch return false ;
397
396
file .close ();
@@ -452,7 +451,11 @@ fn addInternalPackages(b: *Build, obj: *Compile, opts: *BunBuildOptions) void {
452
451
453
452
fn validateGeneratedPath (path : []const u8 ) void {
454
453
if (! exists (path )) {
455
- std .debug .panic ("{s} does not exist in generated code directory!" , .{std .fs .path .basename (path )});
454
+ std .debug .panic (
455
+ \\Generated file '{s}' is missing!
456
+ \\
457
+ \\Make sure to use CMake and Ninja, or pass a manual codegen folder with '-Dgenerated-code=...'
458
+ , .{path });
456
459
}
457
460
}
458
461
0 commit comments