aboutsummaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-06-30 11:27:39 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-07-02 13:27:28 -0700
commit8ce880ca753ce95138bf03d956cf363ea2dfde5a (patch)
treecb9b26f3b186e3ea8da52974ef2cb4c1ac416dc1 /build.zig
parent22b20f20b66a0225fe1d57ab8773ac066c205bdd (diff)
downloadzig-8ce880ca753ce95138bf03d956cf363ea2dfde5a.tar.gz
zig-8ce880ca753ce95138bf03d956cf363ea2dfde5a.zip
avoid calling into stage1 backend when AstGen fails
The motivation for this commit is that there exists source files which produce ast-check errors, but crash stage1 or otherwise trigger stage1 bugs. Previously to this commit, Zig would run AstGen, collect the compile errors, run stage1, report stage1 compile errors and exit if any, and then report AstGen compile errors. The main change in this commit is to report AstGen errors prior to invoking stage1, and in fact if any AstGen errors occur, do not invoke stage1 at all. This caused most of the compile error tests to fail due to things such as unused local variables and mismatched stage1/stage2 error messages. It was taking a long time to update the test cases one-by-one, so I took this opportunity to unify the stage1 and stage2 testing harness, specifically with regards to compile errors. In this way we can start keeping track of which tests pass for 1, 2, or both. `zig build test-compile-errors` no longer works; it is now integrated into `zig build test-stage2`. This is one step closer to executing compile error tests in parallel; in fact the ThreadPool object is already in scope. There are some cases where the stage1 compile errors were actually better; those are left failing in this commit, to be addressed in a follow-up commit. Other changes in this commit: * build.zig: improve support for -Dstage1 used with the test step. * AstGen: minor cosmetic changes to error messages. * stage2: add -fstage1 and -fno-stage1 flags. This now allows one to download a binary of the zig compiler and use the llvm backend of self-hosted. This was also needed for hooking up the test harness. However, I realized that stage1 calls exit() and also has memory leaks, so had to complicate the test harness by not using this flag after all and instead invoking as a child process. - These CLI flags will disappear once we start shipping the self-hosted compiler as the main compiler. Until then, they can be used to try out the work-in-progress stage2. * stage2: select the LLVM backend by default for release modes, as long as the target architecture is supported by LLVM. * test harness: support setting the optimize mode
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig32
1 files changed, 20 insertions, 12 deletions
diff --git a/build.zig b/build.zig
index dcc60e6622..40e1b36e71 100644
--- a/build.zig
+++ b/build.zig
@@ -40,7 +40,7 @@ pub fn build(b: *Builder) !void {
var test_stage2 = b.addTest("src/test.zig");
test_stage2.setBuildMode(mode);
- test_stage2.addPackagePath("stage2_tests", "test/stage2/test.zig");
+ test_stage2.addPackagePath("test_cases", "test/cases.zig");
const fmt_build_zig = b.addFmt(&[_][]const u8{"build.zig"});
@@ -113,11 +113,15 @@ pub fn build(b: *Builder) !void {
if (is_stage1) {
exe.addIncludeDir("src");
exe.addIncludeDir("deps/SoftFloat-3e/source/include");
+
+ test_stage2.addIncludeDir("src");
+ test_stage2.addIncludeDir("deps/SoftFloat-3e/source/include");
// This is intentionally a dummy path. stage1.zig tries to @import("compiler_rt") in case
// of being built by cmake. But when built by zig it's gonna get a compiler_rt so that
// is pointless.
exe.addPackagePath("compiler_rt", "src/empty.zig");
exe.defineCMacro("ZIG_LINK_MODE", "Static");
+ test_stage2.defineCMacro("ZIG_LINK_MODE", "Static");
const softfloat = b.addStaticLibrary("softfloat", null);
softfloat.setBuildMode(.ReleaseFast);
@@ -126,10 +130,15 @@ pub fn build(b: *Builder) !void {
softfloat.addIncludeDir("deps/SoftFloat-3e/source/8086");
softfloat.addIncludeDir("deps/SoftFloat-3e/source/include");
softfloat.addCSourceFiles(&softfloat_sources, &[_][]const u8{ "-std=c99", "-O3" });
+
exe.linkLibrary(softfloat);
+ test_stage2.linkLibrary(softfloat);
exe.addCSourceFiles(&stage1_sources, &exe_cflags);
exe.addCSourceFiles(&optimized_c_sources, &[_][]const u8{ "-std=c99", "-O3" });
+
+ test_stage2.addCSourceFiles(&stage1_sources, &exe_cflags);
+ test_stage2.addCSourceFiles(&optimized_c_sources, &[_][]const u8{ "-std=c99", "-O3" });
}
if (cmake_cfg) |cfg| {
// Inside this code path, we have to coordinate with system packaged LLVM, Clang, and LLD.
@@ -139,8 +148,8 @@ pub fn build(b: *Builder) !void {
b.addSearchPrefix(cfg.cmake_prefix_path);
}
- try addCmakeCfgOptionsToExe(b, cfg, tracy, exe);
- try addCmakeCfgOptionsToExe(b, cfg, tracy, test_stage2);
+ try addCmakeCfgOptionsToExe(b, cfg, exe);
+ try addCmakeCfgOptionsToExe(b, cfg, test_stage2);
} else {
// Here we are -Denable-llvm but no cmake integration.
try addStaticLlvmOptionsToExe(exe);
@@ -233,7 +242,9 @@ pub fn build(b: *Builder) !void {
const is_darling_enabled = b.option(bool, "enable-darling", "[Experimental] Use Darling to run cross compiled macOS tests") orelse false;
const glibc_multi_dir = b.option([]const u8, "enable-foreign-glibc", "Provide directory with glibc installations to run cross compiled tests that link glibc");
+ test_stage2.addBuildOption(bool, "enable_logging", enable_logging);
test_stage2.addBuildOption(bool, "skip_non_native", skip_non_native);
+ test_stage2.addBuildOption(bool, "skip_compile_errors", skip_compile_errors);
test_stage2.addBuildOption(bool, "is_stage1", is_stage1);
test_stage2.addBuildOption(bool, "omit_stage2", omit_stage2);
test_stage2.addBuildOption(bool, "have_llvm", enable_llvm);
@@ -243,7 +254,8 @@ pub fn build(b: *Builder) !void {
test_stage2.addBuildOption(u32, "mem_leak_frames", mem_leak_frames * 2);
test_stage2.addBuildOption(bool, "enable_darling", is_darling_enabled);
test_stage2.addBuildOption(?[]const u8, "glibc_multi_install_dir", glibc_multi_dir);
- test_stage2.addBuildOption([]const u8, "version", version);
+ test_stage2.addBuildOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version));
+ test_stage2.addBuildOption(std.SemanticVersion, "semver", semver);
const test_stage2_step = b.step("test-stage2", "Run the stage2 compiler tests");
test_stage2_step.dependOn(&test_stage2.step);
@@ -339,9 +351,6 @@ pub fn build(b: *Builder) !void {
}
// tests for this feature are disabled until we have the self-hosted compiler available
// toolchain_step.dependOn(tests.addGenHTests(b, test_filter));
- if (!skip_compile_errors) {
- toolchain_step.dependOn(tests.addCompileErrorTests(b, test_filter, modes));
- }
const std_step = tests.addPkgTests(
b,
@@ -383,7 +392,6 @@ const exe_cflags = [_][]const u8{
fn addCmakeCfgOptionsToExe(
b: *Builder,
cfg: CMakeConfig,
- tracy: ?[]const u8,
exe: *std.build.LibExeObjStep,
) !void {
exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
@@ -397,7 +405,7 @@ fn addCmakeCfgOptionsToExe(
addCMakeLibraryList(exe, cfg.lld_libraries);
addCMakeLibraryList(exe, cfg.llvm_libraries);
- const need_cpp_includes = tracy != null;
+ const need_cpp_includes = true;
// System -lc++ must be used because in this code path we are attempting to link
// against system-provided LLVM, Clang, LLD.
@@ -486,9 +494,9 @@ fn addCxxKnownPath(
if (need_cpp_includes) {
// I used these temporarily for testing something but we obviously need a
// more general purpose solution here.
- //exe.addIncludeDir("/nix/store/b3zsk4ihlpiimv3vff86bb5bxghgdzb9-gcc-9.2.0/lib/gcc/x86_64-unknown-linux-gnu/9.2.0/../../../../include/c++/9.2.0");
- //exe.addIncludeDir("/nix/store/b3zsk4ihlpiimv3vff86bb5bxghgdzb9-gcc-9.2.0/lib/gcc/x86_64-unknown-linux-gnu/9.2.0/../../../../include/c++/9.2.0/x86_64-unknown-linux-gnu");
- //exe.addIncludeDir("/nix/store/b3zsk4ihlpiimv3vff86bb5bxghgdzb9-gcc-9.2.0/lib/gcc/x86_64-unknown-linux-gnu/9.2.0/../../../../include/c++/9.2.0/backward");
+ //exe.addIncludeDir("/nix/store/fvf3qjqa5qpcjjkq37pb6ypnk1mzhf5h-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-gnu/9.3.0/../../../../include/c++/9.3.0");
+ //exe.addIncludeDir("/nix/store/fvf3qjqa5qpcjjkq37pb6ypnk1mzhf5h-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-gnu/9.3.0/../../../../include/c++/9.3.0/x86_64-unknown-linux-gnu");
+ //exe.addIncludeDir("/nix/store/fvf3qjqa5qpcjjkq37pb6ypnk1mzhf5h-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-gnu/9.3.0/../../../../include/c++/9.3.0/backward");
}
}