@@ -31,6 +31,11 @@ pub fn build(b: *std.Build) !void {
31
31
const use_zig_libcxx = b .option (bool , "use-zig-libcxx" , "If libc++ is needed, use zig's bundled version, don't try to integrate with the system" ) orelse false ;
32
32
33
33
const test_step = b .step ("test" , "Run all the tests" );
34
+ const deprecated_skip_install_lib_files = b .option (bool , "skip-install-lib-files" , "deprecated. see no-lib" ) orelse false ;
35
+ if (deprecated_skip_install_lib_files ) {
36
+ std .log .warn ("-Dskip-install-lib-files is deprecated in favor of -Dno-lib" , .{});
37
+ }
38
+ const skip_install_lib_files = b .option (bool , "no-lib" , "skip copying of lib/ files and langref to installation prefix. Useful for development" ) orelse deprecated_skip_install_lib_files ;
34
39
35
40
const docgen_exe = b .addExecutable (.{
36
41
.name = "docgen" ,
@@ -40,28 +45,32 @@ pub fn build(b: *std.Build) !void {
40
45
});
41
46
docgen_exe .single_threaded = single_threaded ;
42
47
43
- const langref_out_path = try b .cache_root .join (b .allocator , &.{"langref.html" });
44
- const docgen_cmd = docgen_exe .run ();
45
- docgen_cmd .addArgs (&[_ ][]const u8 {
46
- "--zig" ,
47
- b .zig_exe ,
48
- "doc" ++ fs .path .sep_str ++ "langref.html.in" ,
49
- langref_out_path ,
50
- });
51
- docgen_cmd .step .dependOn (& docgen_exe .step );
48
+ const docgen_cmd = b .addRunArtifact (docgen_exe );
49
+ docgen_cmd .addArgs (&.{ "--zig" , b .zig_exe });
50
+ docgen_cmd .addFileSourceArg (.{ .path = "doc/langref.html.in" });
51
+ const langref_file = docgen_cmd .addOutputFileArg ("langref.html" );
52
+ const install_langref = b .addInstallFileWithDir (langref_file , .prefix , "doc/langref.html" );
53
+ if (! skip_install_lib_files ) {
54
+ b .getInstallStep ().dependOn (& install_langref .step );
55
+ }
52
56
53
57
const docs_step = b .step ("docs" , "Build documentation" );
54
58
docs_step .dependOn (& docgen_cmd .step );
55
59
56
- const test_cases = b .addTest (.{
57
- .root_source_file = .{ .path = "src/test.zig" },
60
+ // This is for legacy reasons, to be removed after our CI scripts are upgraded to use
61
+ // the file from the install prefix instead.
62
+ const legacy_write_to_cache = b .addWriteFiles ();
63
+ legacy_write_to_cache .addCopyFileToSource (langref_file , "zig-cache/langref.html" );
64
+ docs_step .dependOn (& legacy_write_to_cache .step );
65
+
66
+ const check_case_exe = b .addExecutable (.{
67
+ .name = "check-case" ,
68
+ .root_source_file = .{ .path = "test/src/Cases.zig" },
58
69
.optimize = optimize ,
59
70
});
60
- test_cases .main_pkg_path = "." ;
61
- test_cases .stack_size = stack_size ;
62
- test_cases .single_threaded = single_threaded ;
63
-
64
- const fmt_build_zig = b .addFmt (&[_ ][]const u8 {"build.zig" });
71
+ check_case_exe .main_pkg_path = "." ;
72
+ check_case_exe .stack_size = stack_size ;
73
+ check_case_exe .single_threaded = single_threaded ;
65
74
66
75
const skip_debug = b .option (bool , "skip-debug" , "Main test suite skips debug builds" ) orelse false ;
67
76
const skip_release = b .option (bool , "skip-release" , "Main test suite skips release builds" ) orelse false ;
@@ -74,11 +83,6 @@ pub fn build(b: *std.Build) !void {
74
83
const skip_stage1 = b .option (bool , "skip-stage1" , "Main test suite skips stage1 compile error tests" ) orelse false ;
75
84
const skip_run_translated_c = b .option (bool , "skip-run-translated-c" , "Main test suite skips run-translated-c tests" ) orelse false ;
76
85
const skip_stage2_tests = b .option (bool , "skip-stage2-tests" , "Main test suite skips self-hosted compiler tests" ) orelse false ;
77
- const deprecated_skip_install_lib_files = b .option (bool , "skip-install-lib-files" , "deprecated. see no-lib" ) orelse false ;
78
- if (deprecated_skip_install_lib_files ) {
79
- std .log .warn ("-Dskip-install-lib-files is deprecated in favor of -Dno-lib" , .{});
80
- }
81
- const skip_install_lib_files = b .option (bool , "no-lib" , "skip copying of lib/ files to installation prefix. Useful for development" ) orelse deprecated_skip_install_lib_files ;
82
86
83
87
const only_install_lib_files = b .option (bool , "lib-files-only" , "Only install library files" ) orelse false ;
84
88
@@ -175,13 +179,12 @@ pub fn build(b: *std.Build) !void {
175
179
test_step .dependOn (& exe .step );
176
180
}
177
181
178
- b .default_step .dependOn (& exe .step );
179
182
exe .single_threaded = single_threaded ;
180
183
181
184
if (target .isWindows () and target .getAbi () == .gnu ) {
182
185
// LTO is currently broken on mingw, this can be removed when it's fixed.
183
186
exe .want_lto = false ;
184
- test_cases .want_lto = false ;
187
+ check_case_exe .want_lto = false ;
185
188
}
186
189
187
190
const exe_options = b .addOptions ();
@@ -195,11 +198,11 @@ pub fn build(b: *std.Build) !void {
195
198
exe_options .addOption (bool , "llvm_has_arc" , llvm_has_arc );
196
199
exe_options .addOption (bool , "force_gpa" , force_gpa );
197
200
exe_options .addOption (bool , "only_c" , only_c );
198
- exe_options .addOption (bool , "omit_pkg_fetching_code" , false );
201
+ exe_options .addOption (bool , "omit_pkg_fetching_code" , only_c );
199
202
200
203
if (link_libc ) {
201
204
exe .linkLibC ();
202
- test_cases .linkLibC ();
205
+ check_case_exe .linkLibC ();
203
206
}
204
207
205
208
const is_debug = optimize == .Debug ;
@@ -285,14 +288,14 @@ pub fn build(b: *std.Build) !void {
285
288
}
286
289
287
290
try addCmakeCfgOptionsToExe (b , cfg , exe , use_zig_libcxx );
288
- try addCmakeCfgOptionsToExe (b , cfg , test_cases , use_zig_libcxx );
291
+ try addCmakeCfgOptionsToExe (b , cfg , check_case_exe , use_zig_libcxx );
289
292
} else {
290
293
// Here we are -Denable-llvm but no cmake integration.
291
294
try addStaticLlvmOptionsToExe (exe );
292
- try addStaticLlvmOptionsToExe (test_cases );
295
+ try addStaticLlvmOptionsToExe (check_case_exe );
293
296
}
294
297
if (target .isWindows ()) {
295
- inline for (.{ exe , test_cases }) | artifact | {
298
+ inline for (.{ exe , check_case_exe }) | artifact | {
296
299
artifact .linkSystemLibrary ("version" );
297
300
artifact .linkSystemLibrary ("uuid" );
298
301
artifact .linkSystemLibrary ("ole32" );
@@ -337,8 +340,9 @@ pub fn build(b: *std.Build) !void {
337
340
const test_filter = b .option ([]const u8 , "test-filter" , "Skip tests that do not match filter" );
338
341
339
342
const test_cases_options = b .addOptions ();
340
- test_cases .addOptions ("build_options" , test_cases_options );
343
+ check_case_exe .addOptions ("build_options" , test_cases_options );
341
344
345
+ test_cases_options .addOption (bool , "enable_tracy" , false );
342
346
test_cases_options .addOption (bool , "enable_logging" , enable_logging );
343
347
test_cases_options .addOption (bool , "enable_link_snapshots" , enable_link_snapshots );
344
348
test_cases_options .addOption (bool , "skip_non_native" , skip_non_native );
@@ -361,12 +365,6 @@ pub fn build(b: *std.Build) !void {
361
365
test_cases_options .addOption (std .SemanticVersion , "semver" , semver );
362
366
test_cases_options .addOption (? []const u8 , "test_filter" , test_filter );
363
367
364
- const test_cases_step = b .step ("test-cases" , "Run the main compiler test cases" );
365
- test_cases_step .dependOn (& test_cases .step );
366
- if (! skip_stage2_tests ) {
367
- test_step .dependOn (test_cases_step );
368
- }
369
-
370
368
var chosen_opt_modes_buf : [4 ]builtin.Mode = undefined ;
371
369
var chosen_mode_index : usize = 0 ;
372
370
if (! skip_debug ) {
@@ -387,96 +385,101 @@ pub fn build(b: *std.Build) !void {
387
385
}
388
386
const optimization_modes = chosen_opt_modes_buf [0.. chosen_mode_index ];
389
387
390
- // run stage1 `zig fmt` on this build.zig file just to make sure it works
391
- test_step .dependOn (& fmt_build_zig .step );
392
- const fmt_step = b .step ("test-fmt" , "Run zig fmt against build.zig to make sure it works" );
393
- fmt_step .dependOn (& fmt_build_zig .step );
394
-
395
- test_step .dependOn (tests .addPkgTests (
396
- b ,
397
- test_filter ,
398
- "test/behavior.zig" ,
399
- "behavior" ,
400
- "Run the behavior tests" ,
401
- optimization_modes ,
402
- skip_single_threaded ,
403
- skip_non_native ,
404
- skip_libc ,
405
- skip_stage1 ,
406
- skip_stage2_tests ,
407
- ));
388
+ const fmt_include_paths = &.{ "doc" , "lib" , "src" , "test" , "tools" , "build.zig" };
389
+ const fmt_exclude_paths = &.{"test/cases" };
390
+ const do_fmt = b .addFmt (.{
391
+ .paths = fmt_include_paths ,
392
+ .exclude_paths = fmt_exclude_paths ,
393
+ });
408
394
409
- test_step .dependOn (tests .addPkgTests (
410
- b ,
411
- test_filter ,
412
- "lib/compiler_rt.zig" ,
413
- "compiler-rt" ,
414
- "Run the compiler_rt tests" ,
415
- optimization_modes ,
416
- true , // skip_single_threaded
417
- skip_non_native ,
418
- true , // skip_libc
419
- skip_stage1 ,
420
- skip_stage2_tests or true , // TODO get these all passing
421
- ));
395
+ b .step ("test-fmt" , "Check source files having conforming formatting" ).dependOn (& b .addFmt (.{
396
+ .paths = fmt_include_paths ,
397
+ .exclude_paths = fmt_exclude_paths ,
398
+ .check = true ,
399
+ }).step );
422
400
423
- test_step .dependOn (tests .addPkgTests (
424
- b ,
425
- test_filter ,
426
- "lib/c.zig" ,
427
- "universal-libc" ,
428
- "Run the universal libc tests" ,
429
- optimization_modes ,
430
- true , // skip_single_threaded
431
- skip_non_native ,
432
- true , // skip_libc
433
- skip_stage1 ,
434
- skip_stage2_tests or true , // TODO get these all passing
435
- ));
401
+ const test_cases_step = b .step ("test-cases" , "Run the main compiler test cases" );
402
+ try tests .addCases (b , test_cases_step , test_filter , check_case_exe );
403
+ if (! skip_stage2_tests ) test_step .dependOn (test_cases_step );
404
+
405
+ test_step .dependOn (tests .addModuleTests (b , .{
406
+ .test_filter = test_filter ,
407
+ .root_src = "test/behavior.zig" ,
408
+ .name = "behavior" ,
409
+ .desc = "Run the behavior tests" ,
410
+ .optimize_modes = optimization_modes ,
411
+ .skip_single_threaded = skip_single_threaded ,
412
+ .skip_non_native = skip_non_native ,
413
+ .skip_libc = skip_libc ,
414
+ .skip_stage1 = skip_stage1 ,
415
+ .skip_stage2 = skip_stage2_tests ,
416
+ .max_rss = 1 * 1024 * 1024 * 1024 ,
417
+ }));
418
+
419
+ test_step .dependOn (tests .addModuleTests (b , .{
420
+ .test_filter = test_filter ,
421
+ .root_src = "lib/compiler_rt.zig" ,
422
+ .name = "compiler-rt" ,
423
+ .desc = "Run the compiler_rt tests" ,
424
+ .optimize_modes = optimization_modes ,
425
+ .skip_single_threaded = true ,
426
+ .skip_non_native = skip_non_native ,
427
+ .skip_libc = true ,
428
+ .skip_stage1 = skip_stage1 ,
429
+ .skip_stage2 = true , // TODO get all these passing
430
+ }));
431
+
432
+ test_step .dependOn (tests .addModuleTests (b , .{
433
+ .test_filter = test_filter ,
434
+ .root_src = "lib/c.zig" ,
435
+ .name = "universal-libc" ,
436
+ .desc = "Run the universal libc tests" ,
437
+ .optimize_modes = optimization_modes ,
438
+ .skip_single_threaded = true ,
439
+ .skip_non_native = skip_non_native ,
440
+ .skip_libc = true ,
441
+ .skip_stage1 = skip_stage1 ,
442
+ .skip_stage2 = true , // TODO get all these passing
443
+ }));
436
444
437
445
test_step .dependOn (tests .addCompareOutputTests (b , test_filter , optimization_modes ));
438
446
test_step .dependOn (tests .addStandaloneTests (
439
447
b ,
440
- test_filter ,
441
448
optimization_modes ,
442
- skip_non_native ,
443
449
enable_macos_sdk ,
444
- target ,
445
450
skip_stage2_tests ,
446
- b .enable_darling ,
447
- b .enable_qemu ,
448
- b .enable_rosetta ,
449
- b .enable_wasmtime ,
450
- b .enable_wine ,
451
451
enable_symlinks_windows ,
452
452
));
453
453
test_step .dependOn (tests .addCAbiTests (b , skip_non_native , skip_release ));
454
- test_step .dependOn (tests .addLinkTests (b , test_filter , optimization_modes , enable_macos_sdk , skip_stage2_tests , enable_symlinks_windows ));
454
+ test_step .dependOn (tests .addLinkTests (b , enable_macos_sdk , skip_stage2_tests , enable_symlinks_windows ));
455
455
test_step .dependOn (tests .addStackTraceTests (b , test_filter , optimization_modes ));
456
- test_step .dependOn (tests .addCliTests (b , test_filter , optimization_modes ));
456
+ test_step .dependOn (tests .addCliTests (b ));
457
457
test_step .dependOn (tests .addAssembleAndLinkTests (b , test_filter , optimization_modes ));
458
458
test_step .dependOn (tests .addTranslateCTests (b , test_filter ));
459
459
if (! skip_run_translated_c ) {
460
460
test_step .dependOn (tests .addRunTranslatedCTests (b , test_filter , target ));
461
461
}
462
- // tests for this feature are disabled until we have the self-hosted compiler available
463
- // test_step.dependOn(tests.addGenHTests(b, test_filter));
464
462
465
- test_step .dependOn (tests .addPkgTests (
466
- b ,
467
- test_filter ,
468
- "lib/std/std.zig" ,
469
- "std" ,
470
- "Run the standard library tests" ,
471
- optimization_modes ,
472
- skip_single_threaded ,
473
- skip_non_native ,
474
- skip_libc ,
475
- skip_stage1 ,
476
- true , // TODO get these all passing
477
- ));
463
+ test_step .dependOn (tests .addModuleTests (b , .{
464
+ .test_filter = test_filter ,
465
+ .root_src = "lib/std/std.zig" ,
466
+ .name = "std" ,
467
+ .desc = "Run the standard library tests" ,
468
+ .optimize_modes = optimization_modes ,
469
+ .skip_single_threaded = skip_single_threaded ,
470
+ .skip_non_native = skip_non_native ,
471
+ .skip_libc = skip_libc ,
472
+ .skip_stage1 = skip_stage1 ,
473
+ .skip_stage2 = true , // TODO get all these passing
474
+ // I observed a value of 3398275072 on my M1, and multiplied by 1.1 to
475
+ // get this amount:
476
+ .max_rss = 3738102579 ,
477
+ }));
478
478
479
479
try addWasiUpdateStep (b , version );
480
+
481
+ b .step ("fmt" , "Modify source files in place to have conforming formatting" )
482
+ .dependOn (& do_fmt .step );
480
483
}
481
484
482
485
fn addWasiUpdateStep (b : * std.Build , version : [:0 ]const u8 ) ! void {
@@ -505,6 +508,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
505
508
exe_options .addOption (bool , "enable_tracy_callstack" , false );
506
509
exe_options .addOption (bool , "enable_tracy_allocation" , false );
507
510
exe_options .addOption (bool , "value_tracing" , false );
511
+ exe_options .addOption (bool , "omit_pkg_fetching_code" , true );
508
512
509
513
const run_opt = b .addSystemCommand (&.{ "wasm-opt" , "-Oz" , "--enable-bulk-memory" });
510
514
run_opt .addArtifactArg (exe );
@@ -676,10 +680,7 @@ fn addCxxKnownPath(
676
680
) ! void {
677
681
if (! std .process .can_spawn )
678
682
return error .RequiredLibraryNotFound ;
679
- const path_padded = try b .exec (&[_ ][]const u8 {
680
- ctx .cxx_compiler ,
681
- b .fmt ("-print-file-name={s}" , .{objname }),
682
- });
683
+ const path_padded = b .exec (&.{ ctx .cxx_compiler , b .fmt ("-print-file-name={s}" , .{objname }) });
683
684
var tokenizer = mem .tokenize (u8 , path_padded , "\r \n " );
684
685
const path_unpadded = tokenizer .next ().? ;
685
686
if (mem .eql (u8 , path_unpadded , objname )) {
0 commit comments