@@ -12,10 +12,59 @@ fn addDepotToolsToPath(step: *std.Build.Step.Run, depot_tools_dir: []const u8) v
1212 step .addPathDir (depot_tools_dir );
1313}
1414
15+ const GnArgs = struct {
16+ is_asan : bool ,
17+ is_tsan : bool ,
18+ is_debug : bool ,
19+ symbol_level : u8 ,
20+ v8_enable_sandbox : bool ,
21+
22+ fn asString (self : GnArgs , b : * std.Build , target : std.Build.ResolvedTarget ) ! []const u8 {
23+ const tag = target .result .os .tag ;
24+ const arch = target .result .cpu .arch ;
25+
26+ var args : std .ArrayList (u8 ) = .empty ;
27+ const gpa = b .allocator ;
28+
29+ // official builds depend on pgo
30+ try args .appendSlice (gpa , "is_official_build=false\n " );
31+ try args .appendSlice (gpa , b .fmt ("is_debug={}\n " , .{self .is_debug }));
32+ try args .appendSlice (gpa , b .fmt ("symbol_level={d}\n " , .{self .symbol_level }));
33+ try args .appendSlice (gpa , b .fmt ("is_asan={}\n " , .{self .is_asan }));
34+ try args .appendSlice (gpa , b .fmt ("is_tsan={}\n " , .{self .is_tsan }));
35+ try args .appendSlice (gpa , b .fmt ("v8_enable_sandbox={}\n " , .{self .v8_enable_sandbox }));
36+
37+ switch (tag ) {
38+ .ios = > {
39+ try args .appendSlice (gpa , "v8_enable_pointer_compression=false\n " );
40+ try args .appendSlice (gpa , "v8_enable_webassembly=false\n " );
41+ },
42+ .linux = > {
43+ if (arch == .aarch64 ) {
44+ try args .appendSlice (gpa , "clang_base_path=\" /usr/lib/llvm-21\" \n " );
45+ try args .appendSlice (gpa , "clang_use_chrome_plugins=false\n " );
46+ try args .appendSlice (gpa , "treat_warnings_as_errors=false\n " );
47+ }
48+ },
49+ else = > {},
50+ }
51+
52+ return gpa .dupe (u8 , args .items );
53+ }
54+ };
55+
1556pub fn build (b : * std.Build ) ! void {
1657 const target = b .standardTargetOptions (.{});
1758 const optimize = b .standardOptimizeOption (.{});
1859
60+ const gn_args = GnArgs {
61+ .is_debug = optimize == .Debug ,
62+ .symbol_level = b .option (u8 , "symbol_level" , "Symbol level" ) orelse if (optimize == .Debug ) 1 else 0 ,
63+ .is_asan = b .option (bool , "is_asan" , "Address sanitizer" ) orelse false ,
64+ .is_tsan = b .option (bool , "is_tsan" , "Thread sanitizer" ) orelse false ,
65+ .v8_enable_sandbox = b .option (bool , "v8_enable_sandbox" , "V8 lightable sandbox" ) orelse false ,
66+ };
67+
1968 var build_opts = b .addOptions ();
2069 build_opts .addOption (
2170 bool ,
@@ -46,7 +95,7 @@ pub fn build(b: *std.Build) !void {
4695 prepare_step .dependOn (& bootstrapped_v8 .step );
4796
4897 // Otherwise, go through build process.
49- break :blk try buildV8 (b , v8_dir , depot_tools_dir , bootstrapped_v8 , target , optimize );
98+ break :blk try buildV8 (b , v8_dir , depot_tools_dir , bootstrapped_v8 , target , gn_args );
5099 };
51100
52101 const build_step = b .step ("build-v8" , "Build v8" );
@@ -328,47 +377,12 @@ fn buildV8(
328377 depot_tools_dir : []const u8 ,
329378 bootstrapped_v8 : * std.Build.Step.Run ,
330379 target : std.Build.ResolvedTarget ,
331- optimize : std.builtin.OptimizeMode ,
380+ gn_args : GnArgs ,
332381) ! * std.Build.Step.WriteFile {
333382 const v8_dir_lazy_path : LazyPath = .{ .cwd_relative = v8_dir };
334383
335- const allocator = b .allocator ;
336-
337- const tag = target .result .os .tag ;
338- const arch = target .result .cpu .arch ;
339- const is_debug = optimize == .Debug ;
340-
341- var gn_args : std .ArrayList (u8 ) = .empty ;
342- defer gn_args .deinit (allocator );
343-
344- // official builds depend on pgo
345- try gn_args .appendSlice (allocator , "is_official_build=false\n " );
346-
347- if (is_debug ) {
348- try gn_args .appendSlice (allocator , "is_debug=true\n " );
349- try gn_args .appendSlice (allocator , "symbol_level=1\n " );
350- } else {
351- try gn_args .appendSlice (allocator , "is_debug=false\n " );
352- try gn_args .appendSlice (allocator , "symbol_level=0\n " );
353- }
354-
355- switch (tag ) {
356- .ios = > {
357- try gn_args .appendSlice (allocator , "v8_enable_pointer_compression=false\n " );
358- try gn_args .appendSlice (allocator , "v8_enable_webassembly=false\n " );
359- // TODO: target_environment for this target.
360- },
361- .linux = > {
362- if (arch == .aarch64 ) {
363- try gn_args .appendSlice (allocator , "clang_base_path=\" /usr/lib/llvm-21\" \n " );
364- try gn_args .appendSlice (allocator , "clang_use_chrome_plugins=false\n " );
365- try gn_args .appendSlice (allocator , "treat_warnings_as_errors=false\n " );
366- }
367- },
368- else = > {},
369- }
370-
371- const out_dir = b .fmt ("out/{s}/{s}" , .{ @tagName (tag ), if (is_debug ) "debug" else "release" });
384+ const args_string = try gn_args .asString (b , target );
385+ const out_dir = b .fmt ("out/{s}/{s}" , .{ @tagName (target .result .os .tag ), if (gn_args .is_debug ) "debug" else "release" });
372386
373387 const gn_run = b .addSystemCommand (&.{
374388 getDepotToolExePath (b , depot_tools_dir , "gn" ),
@@ -377,7 +391,7 @@ fn buildV8(
377391 "--dotfile=zig/.gn" ,
378392 "gen" ,
379393 out_dir ,
380- b .fmt ("--args={s}" , .{gn_args . items }),
394+ b .fmt ("--args={s}" , .{args_string }),
381395 });
382396 gn_run .setCwd (v8_dir_lazy_path );
383397 addDepotToolsToPath (gn_run , depot_tools_dir );
0 commit comments