Skip to content

Commit bd242ce

Browse files
authored
Merge pull request #14647 from ziglang/build-parallel
zig build: run steps in parallel
2 parents a2c6ecd + 7177b39 commit bd242ce

File tree

229 files changed

+10315
-7520
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+10315
-7520
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,9 @@ set(ZIG_STAGE2_SOURCES
506506
"${CMAKE_SOURCE_DIR}/lib/std/Thread.zig"
507507
"${CMAKE_SOURCE_DIR}/lib/std/Thread/Futex.zig"
508508
"${CMAKE_SOURCE_DIR}/lib/std/Thread/Mutex.zig"
509+
"${CMAKE_SOURCE_DIR}/lib/std/Thread/Pool.zig"
509510
"${CMAKE_SOURCE_DIR}/lib/std/Thread/ResetEvent.zig"
511+
"${CMAKE_SOURCE_DIR}/lib/std/Thread/WaitGroup.zig"
510512
"${CMAKE_SOURCE_DIR}/lib/std/time.zig"
511513
"${CMAKE_SOURCE_DIR}/lib/std/treap.zig"
512514
"${CMAKE_SOURCE_DIR}/lib/std/unicode.zig"
@@ -516,6 +518,7 @@ set(ZIG_STAGE2_SOURCES
516518
"${CMAKE_SOURCE_DIR}/lib/std/zig/c_builtins.zig"
517519
"${CMAKE_SOURCE_DIR}/lib/std/zig/Parse.zig"
518520
"${CMAKE_SOURCE_DIR}/lib/std/zig/render.zig"
521+
"${CMAKE_SOURCE_DIR}/lib/std/zig/Server.zig"
519522
"${CMAKE_SOURCE_DIR}/lib/std/zig/string_literal.zig"
520523
"${CMAKE_SOURCE_DIR}/lib/std/zig/system.zig"
521524
"${CMAKE_SOURCE_DIR}/lib/std/zig/system/NativePaths.zig"
@@ -530,9 +533,7 @@ set(ZIG_STAGE2_SOURCES
530533
"${CMAKE_SOURCE_DIR}/src/Package.zig"
531534
"${CMAKE_SOURCE_DIR}/src/RangeSet.zig"
532535
"${CMAKE_SOURCE_DIR}/src/Sema.zig"
533-
"${CMAKE_SOURCE_DIR}/src/ThreadPool.zig"
534536
"${CMAKE_SOURCE_DIR}/src/TypedValue.zig"
535-
"${CMAKE_SOURCE_DIR}/src/WaitGroup.zig"
536537
"${CMAKE_SOURCE_DIR}/src/Zir.zig"
537538
"${CMAKE_SOURCE_DIR}/src/arch/aarch64/CodeGen.zig"
538539
"${CMAKE_SOURCE_DIR}/src/arch/aarch64/Emit.zig"

build.zig

Lines changed: 109 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ pub fn build(b: *std.Build) !void {
3131
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;
3232

3333
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;
3439

3540
const docgen_exe = b.addExecutable(.{
3641
.name = "docgen",
@@ -40,28 +45,32 @@ pub fn build(b: *std.Build) !void {
4045
});
4146
docgen_exe.single_threaded = single_threaded;
4247

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+
}
5256

5357
const docs_step = b.step("docs", "Build documentation");
5458
docs_step.dependOn(&docgen_cmd.step);
5559

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" },
5869
.optimize = optimize,
5970
});
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;
6574

6675
const skip_debug = b.option(bool, "skip-debug", "Main test suite skips debug builds") orelse false;
6776
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 {
7483
const skip_stage1 = b.option(bool, "skip-stage1", "Main test suite skips stage1 compile error tests") orelse false;
7584
const skip_run_translated_c = b.option(bool, "skip-run-translated-c", "Main test suite skips run-translated-c tests") orelse false;
7685
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;
8286

8387
const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
8488

@@ -175,13 +179,12 @@ pub fn build(b: *std.Build) !void {
175179
test_step.dependOn(&exe.step);
176180
}
177181

178-
b.default_step.dependOn(&exe.step);
179182
exe.single_threaded = single_threaded;
180183

181184
if (target.isWindows() and target.getAbi() == .gnu) {
182185
// LTO is currently broken on mingw, this can be removed when it's fixed.
183186
exe.want_lto = false;
184-
test_cases.want_lto = false;
187+
check_case_exe.want_lto = false;
185188
}
186189

187190
const exe_options = b.addOptions();
@@ -195,11 +198,11 @@ pub fn build(b: *std.Build) !void {
195198
exe_options.addOption(bool, "llvm_has_arc", llvm_has_arc);
196199
exe_options.addOption(bool, "force_gpa", force_gpa);
197200
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);
199202

200203
if (link_libc) {
201204
exe.linkLibC();
202-
test_cases.linkLibC();
205+
check_case_exe.linkLibC();
203206
}
204207

205208
const is_debug = optimize == .Debug;
@@ -285,14 +288,14 @@ pub fn build(b: *std.Build) !void {
285288
}
286289

287290
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);
289292
} else {
290293
// Here we are -Denable-llvm but no cmake integration.
291294
try addStaticLlvmOptionsToExe(exe);
292-
try addStaticLlvmOptionsToExe(test_cases);
295+
try addStaticLlvmOptionsToExe(check_case_exe);
293296
}
294297
if (target.isWindows()) {
295-
inline for (.{ exe, test_cases }) |artifact| {
298+
inline for (.{ exe, check_case_exe }) |artifact| {
296299
artifact.linkSystemLibrary("version");
297300
artifact.linkSystemLibrary("uuid");
298301
artifact.linkSystemLibrary("ole32");
@@ -337,8 +340,9 @@ pub fn build(b: *std.Build) !void {
337340
const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");
338341

339342
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);
341344

345+
test_cases_options.addOption(bool, "enable_tracy", false);
342346
test_cases_options.addOption(bool, "enable_logging", enable_logging);
343347
test_cases_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots);
344348
test_cases_options.addOption(bool, "skip_non_native", skip_non_native);
@@ -361,12 +365,6 @@ pub fn build(b: *std.Build) !void {
361365
test_cases_options.addOption(std.SemanticVersion, "semver", semver);
362366
test_cases_options.addOption(?[]const u8, "test_filter", test_filter);
363367

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-
370368
var chosen_opt_modes_buf: [4]builtin.Mode = undefined;
371369
var chosen_mode_index: usize = 0;
372370
if (!skip_debug) {
@@ -387,96 +385,101 @@ pub fn build(b: *std.Build) !void {
387385
}
388386
const optimization_modes = chosen_opt_modes_buf[0..chosen_mode_index];
389387

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+
});
408394

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);
422400

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+
}));
436444

437445
test_step.dependOn(tests.addCompareOutputTests(b, test_filter, optimization_modes));
438446
test_step.dependOn(tests.addStandaloneTests(
439447
b,
440-
test_filter,
441448
optimization_modes,
442-
skip_non_native,
443449
enable_macos_sdk,
444-
target,
445450
skip_stage2_tests,
446-
b.enable_darling,
447-
b.enable_qemu,
448-
b.enable_rosetta,
449-
b.enable_wasmtime,
450-
b.enable_wine,
451451
enable_symlinks_windows,
452452
));
453453
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));
455455
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));
457457
test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, optimization_modes));
458458
test_step.dependOn(tests.addTranslateCTests(b, test_filter));
459459
if (!skip_run_translated_c) {
460460
test_step.dependOn(tests.addRunTranslatedCTests(b, test_filter, target));
461461
}
462-
// tests for this feature are disabled until we have the self-hosted compiler available
463-
// test_step.dependOn(tests.addGenHTests(b, test_filter));
464462

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+
}));
478478

479479
try addWasiUpdateStep(b, version);
480+
481+
b.step("fmt", "Modify source files in place to have conforming formatting")
482+
.dependOn(&do_fmt.step);
480483
}
481484

482485
fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
@@ -505,6 +508,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
505508
exe_options.addOption(bool, "enable_tracy_callstack", false);
506509
exe_options.addOption(bool, "enable_tracy_allocation", false);
507510
exe_options.addOption(bool, "value_tracing", false);
511+
exe_options.addOption(bool, "omit_pkg_fetching_code", true);
508512

509513
const run_opt = b.addSystemCommand(&.{ "wasm-opt", "-Oz", "--enable-bulk-memory" });
510514
run_opt.addArtifactArg(exe);
@@ -676,10 +680,7 @@ fn addCxxKnownPath(
676680
) !void {
677681
if (!std.process.can_spawn)
678682
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}) });
683684
var tokenizer = mem.tokenize(u8, path_padded, "\r\n");
684685
const path_unpadded = tokenizer.next().?;
685686
if (mem.eql(u8, path_unpadded, objname)) {

ci/aarch64-linux-debug.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ stage3-debug/bin/zig build test docs \
6767
--zig-lib-dir "$(pwd)/../lib"
6868

6969
# Look for HTML errors.
70-
tidy --drop-empty-elements no -qe "$ZIG_LOCAL_CACHE_DIR/langref.html"
70+
tidy --drop-empty-elements no -qe "stage3-debug/doc/langref.html"
7171

7272
# Produce the experimental std lib documentation.
7373
stage3-debug/bin/zig test ../lib/std/std.zig -femit-docs -fno-emit-bin --zig-lib-dir ../lib

ci/aarch64-linux-release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ stage3-release/bin/zig build test docs \
6767
--zig-lib-dir "$(pwd)/../lib"
6868

6969
# Look for HTML errors.
70-
tidy --drop-empty-elements no -qe "$ZIG_LOCAL_CACHE_DIR/langref.html"
70+
tidy --drop-empty-elements no -qe "stage3-release/doc/langref.html"
7171

7272
# Produce the experimental std lib documentation.
7373
stage3-release/bin/zig test ../lib/std/std.zig -femit-docs -fno-emit-bin --zig-lib-dir ../lib

ci/x86_64-linux-debug.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ stage3-debug/bin/zig build test docs \
6666
--zig-lib-dir "$(pwd)/../lib"
6767

6868
# Look for HTML errors.
69-
tidy --drop-empty-elements no -qe "$ZIG_LOCAL_CACHE_DIR/langref.html"
69+
tidy --drop-empty-elements no -qe "stage3-debug/doc/langref.html"
7070

7171
# Produce the experimental std lib documentation.
7272
stage3-debug/bin/zig test ../lib/std/std.zig -femit-docs -fno-emit-bin --zig-lib-dir ../lib

ci/x86_64-linux-release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ stage3-release/bin/zig build test docs \
6767
--zig-lib-dir "$(pwd)/../lib"
6868

6969
# Look for HTML errors.
70-
tidy --drop-empty-elements no -qe "$ZIG_LOCAL_CACHE_DIR/langref.html"
70+
tidy --drop-empty-elements no -qe "stage3-release/doc/langref.html"
7171

7272
# Produce the experimental std lib documentation.
7373
stage3-release/bin/zig test ../lib/std/std.zig -femit-docs -fno-emit-bin --zig-lib-dir ../lib

0 commit comments

Comments
 (0)