Skip to content

zig build: run steps in parallel #14647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 156 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
156 commits
Select commit Hold shift + click to select a range
c6a895f
extract some logic from std.Build to build_runner.zig
andrewrk Feb 13, 2023
0b744d7
build runner: untangle dependency loop checking from making
andrewrk Feb 13, 2023
5b90fa0
extract ThreadPool and WaitGroup from compiler to std lib
andrewrk Feb 13, 2023
658de75
add std.heap.ThreadSafeAllocator
andrewrk Feb 13, 2023
cff86cf
build_runner now executes the step graph in parallel
andrewrk Feb 13, 2023
1fa1484
build runner: proper threaded dependency management
andrewrk Feb 14, 2023
9580fbc
build system: capture stderr and report it later
andrewrk Feb 14, 2023
02381c0
std.Build: improve debugging of misconfigured steps
andrewrk Feb 14, 2023
8d38472
std.Build: further enhance debug message for bad getPath()
andrewrk Feb 14, 2023
7ebaa05
std.Progress: add lock_stderr and unlock_stderr
andrewrk Feb 16, 2023
c5edd8b
std.Build: better handling of stderr of child processes
andrewrk Feb 16, 2023
26486c7
build runner: show stderr even on successful steps run
andrewrk Feb 16, 2023
96d798d
update to new for loop syntax
andrewrk Feb 19, 2023
cb09470
zig build: add a -j<N> option for limiting concurrency
andrewrk Feb 19, 2023
c641af3
CI: use -j1 like a coward
andrewrk Feb 19, 2023
ee693bf
std.os.linux: add ptrace
andrewrk Jan 15, 2022
ae8e7c8
stage2: hot code swapping PoC
andrewrk Jan 15, 2022
50a2bb5
link: PTRACE_ATTACH/PTRACE_DETACH
andrewrk Jan 15, 2022
4f4ddf5
hot code swapping PoC working
andrewrk Jan 22, 2022
c911de8
link.Elf: keep the logic for updates but condition on hcs
andrewrk Feb 21, 2023
4db5bc7
std.mem.copy: update to new for loop syntax
andrewrk Feb 23, 2023
572cb24
progress towards semantic error serialization
andrewrk Feb 23, 2023
6f717b1
std.zig.ErrorBundle: rework binary encoding
andrewrk Feb 24, 2023
6d88c3e
add builtin.zig_version_string
andrewrk Feb 28, 2023
a42888e
std.zig.ErrorBundle: add special representation for empty
andrewrk Feb 28, 2023
c583d14
std.fifo: add toOwnedSlice method
andrewrk Feb 28, 2023
986a30e
integrate the build runner and the compiler server
andrewrk Feb 28, 2023
7a3dabd
build runner: account for debug builds in cleanExit
andrewrk Feb 28, 2023
79440d2
std.Build.CompileStep: obtain the build output dir from protocol
andrewrk Mar 1, 2023
27f136e
build.zig: remove redundant dependency of install step on zig exe
andrewrk Mar 1, 2023
7da34bd
build runner: print a fancy tree with build results on failure
andrewrk Mar 1, 2023
7efeedc
std.Build.CompileStep: better default step name
andrewrk Mar 1, 2023
85b4b6e
std.Build.InstallArtifactStep: better default step name
andrewrk Mar 1, 2023
8acbfaf
compiler: update function accepts a std.Progress.Node
andrewrk Mar 1, 2023
81376e7
fix UAF in build runner
andrewrk Mar 1, 2023
0e07879
multiplex compiler progress messages into the build runner
andrewrk Mar 1, 2023
8b2d872
fix std.Build.TranslateCStep
andrewrk Mar 1, 2023
0129986
build runner: fix unicode tree printing
andrewrk Mar 1, 2023
e895d58
build system: give RunStep a better default step name
andrewrk Mar 1, 2023
a7754d2
build system: better default name for ConfigHeaderStep
andrewrk Mar 1, 2023
b5baa41
fix zig fmt crash
andrewrk Mar 1, 2023
1bcf674
build runner: make step_stack a map to remove redundant steps
andrewrk Mar 1, 2023
8c25082
std.Build.Step: avoid redundancy in default error message
andrewrk Mar 1, 2023
b4997d0
std.Build.RunStep: better default step name
andrewrk Mar 1, 2023
533c7b5
build runner: hide repeated steps in the build summary
andrewrk Mar 1, 2023
b465dc1
build runner: slight rewording in build summary
andrewrk Mar 1, 2023
d0f6758
link: only write manifest if we have the exclusive lock
andrewrk Mar 2, 2023
58edefc
zig build: many enhancements related to parallel building
andrewrk Mar 2, 2023
a2dc49a
fix Step.evalZigProcess to handle more than 1 message per poll
andrewrk Mar 2, 2023
e0561ad
std.Build.Cache.Directory: add a format() method
andrewrk Mar 2, 2023
7ffdbb3
std.debug.TTY.Config: add yellow
andrewrk Mar 3, 2023
9bf63b0
stage2: avoid linux-only APIs on other operating systems
andrewrk Mar 3, 2023
dcec4d5
eliminate stderr usage in std.Build make() functions
andrewrk Mar 3, 2023
d6f7766
stage2: avoid networking when generating zig2.c
andrewrk Mar 3, 2023
d0cf34a
stage2: fix compilation on 32-bit targets
andrewrk Mar 3, 2023
677a0e2
stage2: avoid bloat when using -Donly-c
andrewrk Mar 3, 2023
8b054e1
std.Build.RunStep: work around a miscompilation
andrewrk Mar 3, 2023
41a5ad2
std: child process API supports rusage data
andrewrk Mar 3, 2023
d695f36
build runner supports reporting cached status and duration
andrewrk Mar 3, 2023
2b23625
std.Build.RunStep: report duration and cached status
andrewrk Mar 3, 2023
0322e29
update test/standalone/sigpipe build.zig script to latest API
andrewrk Mar 3, 2023
80d1976
build runner: add microseconds to elapsed in build summary
andrewrk Mar 3, 2023
2996eb5
std.Build.RunStep: add maxrss, duration, and cached status
andrewrk Mar 3, 2023
2cc33f5
std.Build.Step.cacheHit marks step as cached on hit
andrewrk Mar 4, 2023
405bf1b
std.Build.ConfigHeaderStep: integrate with the cache system
andrewrk Mar 4, 2023
bb1960c
std.Build.InstallDirStep: avoid std.log
andrewrk Mar 4, 2023
1e63573
std.build.CompileStep: eliminate std.log usage
andrewrk Mar 4, 2023
a4c35a6
std.Build: audit use of updateFile
andrewrk Mar 5, 2023
d3cbbe0
std.Build.Step: no-op steps report cached if all deps cached
andrewrk Mar 5, 2023
6377aad
build runner: fix typo in max rss display
andrewrk Mar 6, 2023
3b29d00
add std.process.totalSystemMemory
andrewrk Mar 6, 2023
f51413d
zig build: add an OOM-prevention system
andrewrk Mar 6, 2023
7bad695
build.zig: annotate std lib tests maxrss
andrewrk Mar 6, 2023
a24af8e
re-integrate stack trace tests with the new std.Build API
andrewrk Mar 7, 2023
e897637
re-enable compare-output test cases
andrewrk Mar 7, 2023
0b8736f
re-enable CLI tests
andrewrk Mar 7, 2023
8b871ae
re-enable C ABI tests
andrewrk Mar 7, 2023
263aaf0
re-enable asm-and-link tests
andrewrk Mar 7, 2023
8510f9e
std.Build: add addAnonymousDependency
andrewrk Mar 7, 2023
3b06990
std.Build.CompileStep: tweak the default step name
andrewrk Mar 7, 2023
e122cd6
new linker test harness
andrewrk Mar 7, 2023
4efeeaa
delete link test "static_lib_as_system_lib"
andrewrk Mar 7, 2023
f558c83
std.Build.CheckObjectStep: better error message
andrewrk Mar 7, 2023
cdf0a2a
re-enable wasm linker tests
andrewrk Mar 8, 2023
9a9b008
std.Build.CompileStep: add FileSource support to some paths
andrewrk Mar 8, 2023
1142e05
re-enable macho linker tests
andrewrk Mar 8, 2023
15c4fae
re-enable the simple standalone tests
andrewrk Mar 8, 2023
030742f
re-enable standalone tests based on build.zig
andrewrk Mar 8, 2023
8d4067e
CI: take advantage of zig build concurrency
andrewrk Mar 8, 2023
974a6fe
std.Build.RunStep: support -fqemu solving bad dynamic linker
andrewrk Mar 8, 2023
23295f6
fix ZIR decoding of error notes
andrewrk Mar 9, 2023
7106a91
CLI: fix ast-check printing ZIR errors twice
andrewrk Mar 9, 2023
7db7400
std.Progress.Node: add a setName method
andrewrk Mar 10, 2023
25c3878
std.fs.File.readvAll: fix behavior for 0-length vectors
andrewrk Mar 10, 2023
3b00e34
AstGen: skip walking the AST when there are parse errors
andrewrk Mar 10, 2023
3186658
std.Build.CheckFileStep: add a way to expect exact
andrewrk Mar 10, 2023
7cc4a69
build runner enhancements in preparation for test-cases
andrewrk Mar 10, 2023
29cfd47
re-enable test-cases and get them all passing
andrewrk Mar 10, 2023
59f5df3
std.Build: use Cache hash helper for package prefix dirs
andrewrk Mar 10, 2023
a333bb9
zig objcopy: support the compiler protocol
andrewrk Mar 10, 2023
f31aeb0
std.Build.WriteFileStep: add missing step dependencies
andrewrk Mar 10, 2023
2c491d7
docgen: don't print progress in dumb terminals
andrewrk Mar 10, 2023
f829f84
std.Build.InstallFileStep: add missing step dependencies
andrewrk Mar 10, 2023
857296a
build.zig: update docgen to modern build system API
andrewrk Mar 10, 2023
28bda2e
make -Dno-lib also skip docgen
andrewrk Mar 10, 2023
bf73620
build runner: communicate TTY conf to child procs via env vars
andrewrk Mar 10, 2023
097bcca
build.zig: fix how test-cases marked is_test=1 are handled
andrewrk Mar 10, 2023
7d5bce5
build runner: print to stderr in dumb terminals
andrewrk Mar 10, 2023
20b3533
build.zig: bump maxrss upper bound for std lib tests
andrewrk Mar 10, 2023
ba77959
Revert "build runner: print to stderr in dumb terminals"
andrewrk Mar 10, 2023
f4428e5
fix wasm bootstrapping compilation errors
andrewrk Mar 10, 2023
2c326c8
build.zig: install the langref to $prefix/doc/langref.html
andrewrk Mar 10, 2023
2956232
standalone tests: avoid running on strange target
andrewrk Mar 10, 2023
1a3c1fe
test-link: add names to headerpad test
andrewrk Mar 10, 2023
fbce6a7
disable failing aarch64 backend behavior tests
andrewrk Mar 12, 2023
53fb59e
std.fifo: make toOwnedSlice support head != 0
andrewrk Mar 12, 2023
98299e7
add std.process.cleanExit
andrewrk Mar 12, 2023
ef5f8bd
getExternalExecutor: fix aarch64 windows
andrewrk Mar 12, 2023
ede5dcf
make the build runner and test runner talk to each other
andrewrk Mar 12, 2023
8a8f148
test-stack-trace: set env to disable color
andrewrk Mar 13, 2023
61d7e31
remove bad unit test from std lib
andrewrk Mar 13, 2023
a0dd291
std.build.RunStep: clean up some leftover mess
andrewrk Mar 13, 2023
8e6d46b
test runner: remove one superfluous stack frame
andrewrk Mar 13, 2023
bc79328
fix endianness when using test-runner in qemu
andrewrk Mar 13, 2023
149aa9a
add a workaround for miscompilation regarding alignment
andrewrk Mar 13, 2023
c5cdc02
add the new extern test to standalone tests
andrewrk Mar 13, 2023
66eb910
remove redundant link test
andrewrk Mar 14, 2023
fa9108c
add skip_foreign_checks=true on a standalone test
andrewrk Mar 14, 2023
a26a2e1
build runner: fix compilation errors on windows
andrewrk Mar 14, 2023
b1299d5
build runner: tweak progress bar display
andrewrk Mar 14, 2023
e098b28
std.fs.File.writevAll: fix behavior for 0-length vectors
andrewrk Mar 14, 2023
1dbb616
Module: handle incremental update from ZIR with AST errors
andrewrk Mar 14, 2023
171977d
test-cases: fix incorrectly linking libc when backend is llvm
andrewrk Mar 14, 2023
0f88ad8
std.Build.CompileStep: proper step dependency on headers
andrewrk Mar 14, 2023
bde1293
CLI: remove the experimental --watch flag
andrewrk Mar 14, 2023
2b09299
std.Build.Cache: handle ENOENT on createFile race
andrewrk Mar 14, 2023
22d94ea
disable std lib unit tests that hard code port numbers
andrewrk Mar 14, 2023
941cae4
revert a change to C ABI tests
andrewrk Mar 14, 2023
3e328c8
std.Build.CompileStep: remove setNamePrefix and add setName
andrewrk Mar 14, 2023
63bd0fe
use DEC graphics instead of Unicode for box drawing
andrewrk Mar 14, 2023
11de55d
std.Build.Cache: handle ENOENT on createFile race
andrewrk Mar 14, 2023
37a7d2c
std.Build.RunStep: fix handling spawn failure
andrewrk Mar 14, 2023
ed33901
test-cli: fix expected stderr on windows
andrewrk Mar 14, 2023
363d4a1
add compile log output to build runner
andrewrk Mar 14, 2023
717e2c8
std.Build.Cache: make unit tests not depend on cwd
andrewrk Mar 14, 2023
6d6f6a4
std.os.windows.OpenFile: handle DELETE_PENDING
andrewrk Mar 15, 2023
6664d24
test-cases: add missing compile log output
andrewrk Mar 15, 2023
4f1382e
add std.LinearFifo.readableSliceOfLen
andrewrk Mar 15, 2023
4aa5895
std.Build: fix invalid assumption about fifos
andrewrk Mar 15, 2023
a1058dd
fix std.fs unit test to not be racey
andrewrk Mar 15, 2023
1a70ea0
windows_spawn standalone test: test on native OS
andrewrk Mar 15, 2023
21b544a
fix compile log test case expected output
andrewrk Mar 15, 2023
5c6adbe
test-c-abi: disable LTO on more targets
andrewrk Mar 15, 2023
cdda395
std lib tests: avoid cwd races by using std.testing.tmpDir
andrewrk Mar 15, 2023
1f59994
C ABI tests: don't test aarch64-windows yet
andrewrk Mar 15, 2023
7177b39
fix test-case copy-paste typo from earlier commit
andrewrk Mar 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/Thread.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/Futex.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/Mutex.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/Pool.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/ResetEvent.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/WaitGroup.zig"
"${CMAKE_SOURCE_DIR}/lib/std/time.zig"
"${CMAKE_SOURCE_DIR}/lib/std/treap.zig"
"${CMAKE_SOURCE_DIR}/lib/std/unicode.zig"
Expand All @@ -516,6 +518,7 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/zig/c_builtins.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/Parse.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/render.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/Server.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/string_literal.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/system.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/system/NativePaths.zig"
Expand All @@ -530,9 +533,7 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/src/Package.zig"
"${CMAKE_SOURCE_DIR}/src/RangeSet.zig"
"${CMAKE_SOURCE_DIR}/src/Sema.zig"
"${CMAKE_SOURCE_DIR}/src/ThreadPool.zig"
"${CMAKE_SOURCE_DIR}/src/TypedValue.zig"
"${CMAKE_SOURCE_DIR}/src/WaitGroup.zig"
"${CMAKE_SOURCE_DIR}/src/Zir.zig"
"${CMAKE_SOURCE_DIR}/src/arch/aarch64/CodeGen.zig"
"${CMAKE_SOURCE_DIR}/src/arch/aarch64/Emit.zig"
Expand Down
217 changes: 109 additions & 108 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ pub fn build(b: *std.Build) !void {
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;

const test_step = b.step("test", "Run all the tests");
const deprecated_skip_install_lib_files = b.option(bool, "skip-install-lib-files", "deprecated. see no-lib") orelse false;
if (deprecated_skip_install_lib_files) {
std.log.warn("-Dskip-install-lib-files is deprecated in favor of -Dno-lib", .{});
}
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;

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

const langref_out_path = try b.cache_root.join(b.allocator, &.{"langref.html"});
const docgen_cmd = docgen_exe.run();
docgen_cmd.addArgs(&[_][]const u8{
"--zig",
b.zig_exe,
"doc" ++ fs.path.sep_str ++ "langref.html.in",
langref_out_path,
});
docgen_cmd.step.dependOn(&docgen_exe.step);
const docgen_cmd = b.addRunArtifact(docgen_exe);
docgen_cmd.addArgs(&.{ "--zig", b.zig_exe });
docgen_cmd.addFileSourceArg(.{ .path = "doc/langref.html.in" });
const langref_file = docgen_cmd.addOutputFileArg("langref.html");
const install_langref = b.addInstallFileWithDir(langref_file, .prefix, "doc/langref.html");
if (!skip_install_lib_files) {
b.getInstallStep().dependOn(&install_langref.step);
}

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

const test_cases = b.addTest(.{
.root_source_file = .{ .path = "src/test.zig" },
// This is for legacy reasons, to be removed after our CI scripts are upgraded to use
// the file from the install prefix instead.
const legacy_write_to_cache = b.addWriteFiles();
legacy_write_to_cache.addCopyFileToSource(langref_file, "zig-cache/langref.html");
docs_step.dependOn(&legacy_write_to_cache.step);

const check_case_exe = b.addExecutable(.{
.name = "check-case",
.root_source_file = .{ .path = "test/src/Cases.zig" },
.optimize = optimize,
});
test_cases.main_pkg_path = ".";
test_cases.stack_size = stack_size;
test_cases.single_threaded = single_threaded;

const fmt_build_zig = b.addFmt(&[_][]const u8{"build.zig"});
check_case_exe.main_pkg_path = ".";
check_case_exe.stack_size = stack_size;
check_case_exe.single_threaded = single_threaded;

const skip_debug = b.option(bool, "skip-debug", "Main test suite skips debug builds") orelse false;
const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse false;
Expand All @@ -74,11 +83,6 @@ pub fn build(b: *std.Build) !void {
const skip_stage1 = b.option(bool, "skip-stage1", "Main test suite skips stage1 compile error tests") orelse false;
const skip_run_translated_c = b.option(bool, "skip-run-translated-c", "Main test suite skips run-translated-c tests") orelse false;
const skip_stage2_tests = b.option(bool, "skip-stage2-tests", "Main test suite skips self-hosted compiler tests") orelse false;
const deprecated_skip_install_lib_files = b.option(bool, "skip-install-lib-files", "deprecated. see no-lib") orelse false;
if (deprecated_skip_install_lib_files) {
std.log.warn("-Dskip-install-lib-files is deprecated in favor of -Dno-lib", .{});
}
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;

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

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

b.default_step.dependOn(&exe.step);
exe.single_threaded = single_threaded;

if (target.isWindows() and target.getAbi() == .gnu) {
// LTO is currently broken on mingw, this can be removed when it's fixed.
exe.want_lto = false;
test_cases.want_lto = false;
check_case_exe.want_lto = false;
}

const exe_options = b.addOptions();
Expand All @@ -195,11 +198,11 @@ pub fn build(b: *std.Build) !void {
exe_options.addOption(bool, "llvm_has_arc", llvm_has_arc);
exe_options.addOption(bool, "force_gpa", force_gpa);
exe_options.addOption(bool, "only_c", only_c);
exe_options.addOption(bool, "omit_pkg_fetching_code", false);
exe_options.addOption(bool, "omit_pkg_fetching_code", only_c);

if (link_libc) {
exe.linkLibC();
test_cases.linkLibC();
check_case_exe.linkLibC();
}

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

try addCmakeCfgOptionsToExe(b, cfg, exe, use_zig_libcxx);
try addCmakeCfgOptionsToExe(b, cfg, test_cases, use_zig_libcxx);
try addCmakeCfgOptionsToExe(b, cfg, check_case_exe, use_zig_libcxx);
} else {
// Here we are -Denable-llvm but no cmake integration.
try addStaticLlvmOptionsToExe(exe);
try addStaticLlvmOptionsToExe(test_cases);
try addStaticLlvmOptionsToExe(check_case_exe);
}
if (target.isWindows()) {
inline for (.{ exe, test_cases }) |artifact| {
inline for (.{ exe, check_case_exe }) |artifact| {
artifact.linkSystemLibrary("version");
artifact.linkSystemLibrary("uuid");
artifact.linkSystemLibrary("ole32");
Expand Down Expand Up @@ -337,8 +340,9 @@ pub fn build(b: *std.Build) !void {
const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");

const test_cases_options = b.addOptions();
test_cases.addOptions("build_options", test_cases_options);
check_case_exe.addOptions("build_options", test_cases_options);

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

const test_cases_step = b.step("test-cases", "Run the main compiler test cases");
test_cases_step.dependOn(&test_cases.step);
if (!skip_stage2_tests) {
test_step.dependOn(test_cases_step);
}

var chosen_opt_modes_buf: [4]builtin.Mode = undefined;
var chosen_mode_index: usize = 0;
if (!skip_debug) {
Expand All @@ -387,96 +385,101 @@ pub fn build(b: *std.Build) !void {
}
const optimization_modes = chosen_opt_modes_buf[0..chosen_mode_index];

// run stage1 `zig fmt` on this build.zig file just to make sure it works
test_step.dependOn(&fmt_build_zig.step);
const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works");
fmt_step.dependOn(&fmt_build_zig.step);

test_step.dependOn(tests.addPkgTests(
b,
test_filter,
"test/behavior.zig",
"behavior",
"Run the behavior tests",
optimization_modes,
skip_single_threaded,
skip_non_native,
skip_libc,
skip_stage1,
skip_stage2_tests,
));
const fmt_include_paths = &.{ "doc", "lib", "src", "test", "tools", "build.zig" };
const fmt_exclude_paths = &.{"test/cases"};
const do_fmt = b.addFmt(.{
.paths = fmt_include_paths,
.exclude_paths = fmt_exclude_paths,
});

test_step.dependOn(tests.addPkgTests(
b,
test_filter,
"lib/compiler_rt.zig",
"compiler-rt",
"Run the compiler_rt tests",
optimization_modes,
true, // skip_single_threaded
skip_non_native,
true, // skip_libc
skip_stage1,
skip_stage2_tests or true, // TODO get these all passing
));
b.step("test-fmt", "Check source files having conforming formatting").dependOn(&b.addFmt(.{
.paths = fmt_include_paths,
.exclude_paths = fmt_exclude_paths,
.check = true,
}).step);

test_step.dependOn(tests.addPkgTests(
b,
test_filter,
"lib/c.zig",
"universal-libc",
"Run the universal libc tests",
optimization_modes,
true, // skip_single_threaded
skip_non_native,
true, // skip_libc
skip_stage1,
skip_stage2_tests or true, // TODO get these all passing
));
const test_cases_step = b.step("test-cases", "Run the main compiler test cases");
try tests.addCases(b, test_cases_step, test_filter, check_case_exe);
if (!skip_stage2_tests) test_step.dependOn(test_cases_step);

test_step.dependOn(tests.addModuleTests(b, .{
.test_filter = test_filter,
.root_src = "test/behavior.zig",
.name = "behavior",
.desc = "Run the behavior tests",
.optimize_modes = optimization_modes,
.skip_single_threaded = skip_single_threaded,
.skip_non_native = skip_non_native,
.skip_libc = skip_libc,
.skip_stage1 = skip_stage1,
.skip_stage2 = skip_stage2_tests,
.max_rss = 1 * 1024 * 1024 * 1024,
}));

test_step.dependOn(tests.addModuleTests(b, .{
.test_filter = test_filter,
.root_src = "lib/compiler_rt.zig",
.name = "compiler-rt",
.desc = "Run the compiler_rt tests",
.optimize_modes = optimization_modes,
.skip_single_threaded = true,
.skip_non_native = skip_non_native,
.skip_libc = true,
.skip_stage1 = skip_stage1,
.skip_stage2 = true, // TODO get all these passing
}));

test_step.dependOn(tests.addModuleTests(b, .{
.test_filter = test_filter,
.root_src = "lib/c.zig",
.name = "universal-libc",
.desc = "Run the universal libc tests",
.optimize_modes = optimization_modes,
.skip_single_threaded = true,
.skip_non_native = skip_non_native,
.skip_libc = true,
.skip_stage1 = skip_stage1,
.skip_stage2 = true, // TODO get all these passing
}));

test_step.dependOn(tests.addCompareOutputTests(b, test_filter, optimization_modes));
test_step.dependOn(tests.addStandaloneTests(
b,
test_filter,
optimization_modes,
skip_non_native,
enable_macos_sdk,
target,
skip_stage2_tests,
b.enable_darling,
b.enable_qemu,
b.enable_rosetta,
b.enable_wasmtime,
b.enable_wine,
enable_symlinks_windows,
));
test_step.dependOn(tests.addCAbiTests(b, skip_non_native, skip_release));
test_step.dependOn(tests.addLinkTests(b, test_filter, optimization_modes, enable_macos_sdk, skip_stage2_tests, enable_symlinks_windows));
test_step.dependOn(tests.addLinkTests(b, enable_macos_sdk, skip_stage2_tests, enable_symlinks_windows));
test_step.dependOn(tests.addStackTraceTests(b, test_filter, optimization_modes));
test_step.dependOn(tests.addCliTests(b, test_filter, optimization_modes));
test_step.dependOn(tests.addCliTests(b));
test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, optimization_modes));
test_step.dependOn(tests.addTranslateCTests(b, test_filter));
if (!skip_run_translated_c) {
test_step.dependOn(tests.addRunTranslatedCTests(b, test_filter, target));
}
// tests for this feature are disabled until we have the self-hosted compiler available
// test_step.dependOn(tests.addGenHTests(b, test_filter));

test_step.dependOn(tests.addPkgTests(
b,
test_filter,
"lib/std/std.zig",
"std",
"Run the standard library tests",
optimization_modes,
skip_single_threaded,
skip_non_native,
skip_libc,
skip_stage1,
true, // TODO get these all passing
));
test_step.dependOn(tests.addModuleTests(b, .{
.test_filter = test_filter,
.root_src = "lib/std/std.zig",
.name = "std",
.desc = "Run the standard library tests",
.optimize_modes = optimization_modes,
.skip_single_threaded = skip_single_threaded,
.skip_non_native = skip_non_native,
.skip_libc = skip_libc,
.skip_stage1 = skip_stage1,
.skip_stage2 = true, // TODO get all these passing
// I observed a value of 3398275072 on my M1, and multiplied by 1.1 to
// get this amount:
.max_rss = 3738102579,
}));

try addWasiUpdateStep(b, version);

b.step("fmt", "Modify source files in place to have conforming formatting")
.dependOn(&do_fmt.step);
}

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

const run_opt = b.addSystemCommand(&.{ "wasm-opt", "-Oz", "--enable-bulk-memory" });
run_opt.addArtifactArg(exe);
Expand Down Expand Up @@ -676,10 +680,7 @@ fn addCxxKnownPath(
) !void {
if (!std.process.can_spawn)
return error.RequiredLibraryNotFound;
const path_padded = try b.exec(&[_][]const u8{
ctx.cxx_compiler,
b.fmt("-print-file-name={s}", .{objname}),
});
const path_padded = b.exec(&.{ ctx.cxx_compiler, b.fmt("-print-file-name={s}", .{objname}) });
var tokenizer = mem.tokenize(u8, path_padded, "\r\n");
const path_unpadded = tokenizer.next().?;
if (mem.eql(u8, path_unpadded, objname)) {
Expand Down
2 changes: 1 addition & 1 deletion ci/aarch64-linux-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ stage3-debug/bin/zig build test docs \
--zig-lib-dir "$(pwd)/../lib"

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

# Produce the experimental std lib documentation.
stage3-debug/bin/zig test ../lib/std/std.zig -femit-docs -fno-emit-bin --zig-lib-dir ../lib
Expand Down
2 changes: 1 addition & 1 deletion ci/aarch64-linux-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ stage3-release/bin/zig build test docs \
--zig-lib-dir "$(pwd)/../lib"

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

# Produce the experimental std lib documentation.
stage3-release/bin/zig test ../lib/std/std.zig -femit-docs -fno-emit-bin --zig-lib-dir ../lib
Expand Down
2 changes: 1 addition & 1 deletion ci/x86_64-linux-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ stage3-debug/bin/zig build test docs \
--zig-lib-dir "$(pwd)/../lib"

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

# Produce the experimental std lib documentation.
stage3-debug/bin/zig test ../lib/std/std.zig -femit-docs -fno-emit-bin --zig-lib-dir ../lib
Expand Down
2 changes: 1 addition & 1 deletion ci/x86_64-linux-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ stage3-release/bin/zig build test docs \
--zig-lib-dir "$(pwd)/../lib"

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

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