From 73bbd1069a993a0e663033ea3b8cd4ed1a123566 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Sun, 7 Aug 2022 18:17:31 -0700
Subject: [PATCH 01/24] build: remove the option to omit stage2
---
build.zig | 14 +++++---------
ci/azure/build.zig | 2 --
src/Compilation.zig | 29 ++---------------------------
src/Sema.zig | 7 -------
src/config.zig.in | 1 -
test/tests.zig | 6 ------
6 files changed, 7 insertions(+), 52 deletions(-)
diff --git a/build.zig b/build.zig
index 0ff528520180..1c2212c1a4c7 100644
--- a/build.zig
+++ b/build.zig
@@ -65,7 +65,6 @@ pub fn build(b: *Builder) !void {
const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
const is_stage1 = b.option(bool, "stage1", "Build the stage1 compiler, put stage2 behind a feature flag") orelse false;
- const omit_stage2 = b.option(bool, "omit-stage2", "Do not include stage2 behind a feature flag inside stage1") orelse false;
const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false;
const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (is_stage1 or static_llvm);
const llvm_has_m68k = b.option(
@@ -361,7 +360,6 @@ pub fn build(b: *Builder) !void {
exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
exe_options.addOption(bool, "value_tracing", value_tracing);
exe_options.addOption(bool, "is_stage1", is_stage1);
- exe_options.addOption(bool, "omit_stage2", omit_stage2);
if (tracy) |tracy_path| {
const client_cpp = fs.path.join(
b.allocator,
@@ -397,7 +395,6 @@ pub fn build(b: *Builder) !void {
test_cases_options.addOption(bool, "skip_non_native", skip_non_native);
test_cases_options.addOption(bool, "skip_stage1", skip_stage1);
test_cases_options.addOption(bool, "is_stage1", is_stage1);
- test_cases_options.addOption(bool, "omit_stage2", omit_stage2);
test_cases_options.addOption(bool, "have_llvm", enable_llvm);
test_cases_options.addOption(bool, "llvm_has_m68k", llvm_has_m68k);
test_cases_options.addOption(bool, "llvm_has_csky", llvm_has_csky);
@@ -457,7 +454,7 @@ pub fn build(b: *Builder) !void {
skip_non_native,
skip_libc,
skip_stage1,
- omit_stage2,
+ false,
is_stage1,
));
@@ -472,7 +469,7 @@ pub fn build(b: *Builder) !void {
skip_non_native,
true, // skip_libc
skip_stage1,
- omit_stage2 or true, // TODO get these all passing
+ true, // TODO get these all passing
is_stage1,
));
@@ -487,7 +484,7 @@ pub fn build(b: *Builder) !void {
skip_non_native,
true, // skip_libc
skip_stage1,
- omit_stage2 or true, // TODO get these all passing
+ true, // TODO get these all passing
is_stage1,
));
@@ -499,14 +496,13 @@ pub fn build(b: *Builder) !void {
skip_non_native,
enable_macos_sdk,
target,
- omit_stage2,
b.enable_darling,
b.enable_qemu,
b.enable_rosetta,
b.enable_wasmtime,
b.enable_wine,
));
- toolchain_step.dependOn(tests.addLinkTests(b, test_filter, modes, enable_macos_sdk, omit_stage2));
+ toolchain_step.dependOn(tests.addLinkTests(b, test_filter, modes, enable_macos_sdk));
toolchain_step.dependOn(tests.addStackTraceTests(b, test_filter, modes));
toolchain_step.dependOn(tests.addCliTests(b, test_filter, modes));
toolchain_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes));
@@ -528,7 +524,7 @@ pub fn build(b: *Builder) !void {
skip_non_native,
skip_libc,
skip_stage1,
- omit_stage2 or true, // TODO get these all passing
+ true, // TODO get these all passing
is_stage1,
);
diff --git a/ci/azure/build.zig b/ci/azure/build.zig
index 3fec5553215f..053065b6997b 100644
--- a/ci/azure/build.zig
+++ b/ci/azure/build.zig
@@ -38,7 +38,6 @@ pub fn build(b: *Builder) !void {
docs_step.dependOn(&docgen_cmd.step);
const is_stage1 = b.option(bool, "stage1", "Build the stage1 compiler, put stage2 behind a feature flag") orelse false;
- const omit_stage2 = b.option(bool, "omit-stage2", "Do not include stage2 behind a feature flag inside stage1") orelse false;
const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false;
const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (is_stage1 or static_llvm);
const llvm_has_m68k = b.option(
@@ -300,7 +299,6 @@ pub fn build(b: *Builder) !void {
exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
exe_options.addOption(bool, "value_tracing", value_tracing);
exe_options.addOption(bool, "is_stage1", is_stage1);
- exe_options.addOption(bool, "omit_stage2", omit_stage2);
if (tracy) |tracy_path| {
const client_cpp = fs.path.join(
b.allocator,
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 060afba6948b..6d778b955a01 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -1044,8 +1044,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
// Even though we may have no Zig code to compile (depending on `options.main_pkg`),
// we may need to use stage1 for building compiler-rt and other dependencies.
- if (build_options.omit_stage2)
- break :blk true;
if (options.use_llvm) |use_llvm| {
if (!use_llvm) {
break :blk false;
@@ -2213,8 +2211,7 @@ pub fn update(comp: *Compilation) !void {
comp.c_object_work_queue.writeItemAssumeCapacity(key);
}
- const use_stage1 = build_options.omit_stage2 or
- (build_options.is_stage1 and comp.bin_file.options.use_stage1);
+ const use_stage1 = build_options.is_stage1 and comp.bin_file.options.use_stage1;
if (comp.bin_file.options.module) |module| {
module.compile_log_text.shrinkAndFree(module.gpa, 0);
module.generation += 1;
@@ -2390,8 +2387,7 @@ fn flush(comp: *Compilation, prog_node: *std.Progress.Node) !void {
};
comp.link_error_flags = comp.bin_file.errorFlags();
- const use_stage1 = build_options.omit_stage2 or
- (build_options.is_stage1 and comp.bin_file.options.use_stage1);
+ const use_stage1 = build_options.is_stage1 and comp.bin_file.options.use_stage1;
if (!use_stage1) {
if (comp.bin_file.options.module) |module| {
try link.File.C.flushEmitH(module);
@@ -2952,9 +2948,6 @@ pub fn performAllTheWork(
fn processOneJob(comp: *Compilation, job: Job) !void {
switch (job) {
.codegen_decl => |decl_index| {
- if (build_options.omit_stage2)
- @panic("sadly stage2 is omitted from this build to save memory on the CI server");
-
const module = comp.bin_file.options.module.?;
const decl = module.declPtr(decl_index);
@@ -2989,9 +2982,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
}
},
.codegen_func => |func| {
- if (build_options.omit_stage2)
- @panic("sadly stage2 is omitted from this build to save memory on the CI server");
-
const named_frame = tracy.namedFrame("codegen_func");
defer named_frame.end();
@@ -3002,9 +2992,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
};
},
.emit_h_decl => |decl_index| {
- if (build_options.omit_stage2)
- @panic("sadly stage2 is omitted from this build to save memory on the CI server");
-
const module = comp.bin_file.options.module.?;
const decl = module.declPtr(decl_index);
@@ -3063,9 +3050,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
}
},
.analyze_decl => |decl_index| {
- if (build_options.omit_stage2)
- @panic("sadly stage2 is omitted from this build to save memory on the CI server");
-
const module = comp.bin_file.options.module.?;
module.ensureDeclAnalyzed(decl_index) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
@@ -3073,9 +3057,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
};
},
.update_embed_file => |embed_file| {
- if (build_options.omit_stage2)
- @panic("sadly stage2 is omitted from this build to save memory on the CI server");
-
const named_frame = tracy.namedFrame("update_embed_file");
defer named_frame.end();
@@ -3086,9 +3067,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
};
},
.update_line_number => |decl_index| {
- if (build_options.omit_stage2)
- @panic("sadly stage2 is omitted from this build to save memory on the CI server");
-
const named_frame = tracy.namedFrame("update_line_number");
defer named_frame.end();
@@ -3107,9 +3085,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
};
},
.analyze_pkg => |pkg| {
- if (build_options.omit_stage2)
- @panic("sadly stage2 is omitted from this build to save memory on the CI server");
-
const named_frame = tracy.namedFrame("analyze_pkg");
defer named_frame.end();
diff --git a/src/Sema.zig b/src/Sema.zig
index 091b88e7190f..aa02288df774 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -27358,9 +27358,6 @@ pub fn resolveTypeLayout(
src: LazySrcLoc,
ty: Type,
) CompileError!void {
- if (build_options.omit_stage2)
- @panic("sadly stage2 is omitted from this build to save memory on the CI server");
-
switch (ty.zigTypeTag()) {
.Struct => return sema.resolveStructLayout(block, src, ty),
.Union => return sema.resolveUnionLayout(block, src, ty),
@@ -27699,8 +27696,6 @@ fn resolveUnionFully(
}
pub fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!Type {
- if (build_options.omit_stage2)
- @panic("sadly stage2 is omitted from this build to save memory on the CI server");
switch (ty.tag()) {
.@"struct" => {
const struct_obj = ty.castTag(.@"struct").?.data;
@@ -29323,8 +29318,6 @@ fn typePtrOrOptionalPtrTy(
/// TODO merge these implementations together with the "advanced"/sema_kit pattern seen
/// elsewhere in value.zig
pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {
- if (build_options.omit_stage2)
- @panic("sadly stage2 is omitted from this build to save memory on the CI server");
return switch (ty.tag()) {
.u1,
.u8,
diff --git a/src/config.zig.in b/src/config.zig.in
index a886b2d28efa..336a6c45edae 100644
--- a/src/config.zig.in
+++ b/src/config.zig.in
@@ -10,4 +10,3 @@ pub const enable_tracy = false;
pub const value_tracing = false;
pub const is_stage1 = true;
pub const skip_non_native = false;
-pub const omit_stage2: bool = @ZIG_OMIT_STAGE2_BOOL@;
diff --git a/test/tests.zig b/test/tests.zig
index 0bca9a9d1603..e1836dc1e010 100644
--- a/test/tests.zig
+++ b/test/tests.zig
@@ -462,7 +462,6 @@ pub fn addStandaloneTests(
skip_non_native: bool,
enable_macos_sdk: bool,
target: std.zig.CrossTarget,
- omit_stage2: bool,
enable_darling: bool,
enable_qemu: bool,
enable_rosetta: bool,
@@ -479,7 +478,6 @@ pub fn addStandaloneTests(
.skip_non_native = skip_non_native,
.enable_macos_sdk = enable_macos_sdk,
.target = target,
- .omit_stage2 = omit_stage2,
.enable_darling = enable_darling,
.enable_qemu = enable_qemu,
.enable_rosetta = enable_rosetta,
@@ -497,7 +495,6 @@ pub fn addLinkTests(
test_filter: ?[]const u8,
modes: []const Mode,
enable_macos_sdk: bool,
- omit_stage2: bool,
) *build.Step {
const cases = b.allocator.create(StandaloneContext) catch unreachable;
cases.* = StandaloneContext{
@@ -509,7 +506,6 @@ pub fn addLinkTests(
.skip_non_native = true,
.enable_macos_sdk = enable_macos_sdk,
.target = .{},
- .omit_stage2 = omit_stage2,
};
link.addCases(cases);
return cases.step;
@@ -978,7 +974,6 @@ pub const StandaloneContext = struct {
skip_non_native: bool,
enable_macos_sdk: bool,
target: std.zig.CrossTarget,
- omit_stage2: bool,
enable_darling: bool = false,
enable_qemu: bool = false,
enable_rosetta: bool = false,
@@ -1003,7 +998,6 @@ pub const StandaloneContext = struct {
const b = self.b;
if (features.requires_macos_sdk and !self.enable_macos_sdk) return;
- if (features.requires_stage2 and self.omit_stage2) return;
const annotated_case_name = b.fmt("build {s}", .{build_file});
if (self.test_filter) |filter| {
From 507aae4a1a3db498ece2a3a89d74e9e24d952923 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Sun, 7 Aug 2022 23:10:57 -0700
Subject: [PATCH 02/24] make self-hosted the default compiler
stage1 is available behind the -fstage1 flag.
closes #89
---
CMakeLists.txt | 2 +-
build.zig | 16 +-
ci/azure/build.zig | 10 +-
ci/azure/macos_script | 17 +-
ci/azure/pipelines.yml | 4 +-
ci/srht/freebsd_script | 9 +-
ci/zinc/linux_test.sh | 48 +++--
doc/docgen.zig | 31 +++
doc/langref.html.in | 178 +++++++-----------
lib/std/builtin.zig | 2 +-
src/Compilation.zig | 29 +--
src/config.zig.in | 2 +-
src/link.zig | 4 +-
src/link/Coff.zig | 4 +-
src/link/Elf.zig | 2 +-
src/link/MachO.zig | 4 +-
src/link/Wasm.zig | 6 +-
src/main.zig | 2 +-
src/stage1.zig | 2 +-
src/test.zig | 2 +-
...mpty slice with sentinel out of bounds.zig | 2 +-
.../safety/out of bounds slice access.zig | 6 +-
...h sentinel out of bounds - runtime len.zig | 2 +-
.../slice with sentinel out of bounds.zig | 2 +-
test/tests.zig | 3 +-
25 files changed, 176 insertions(+), 213 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 96d10f1e8354..d9784090cd08 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,7 +12,7 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
if(NOT CMAKE_INSTALL_PREFIX)
- set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/stage1" CACHE STRING
+ set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/stage2" CACHE STRING
"Directory to install zig to" FORCE)
endif()
diff --git a/build.zig b/build.zig
index 1c2212c1a4c7..6823248431da 100644
--- a/build.zig
+++ b/build.zig
@@ -64,9 +64,9 @@ pub fn build(b: *Builder) !void {
const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
- const is_stage1 = b.option(bool, "stage1", "Build the stage1 compiler, put stage2 behind a feature flag") orelse false;
+ const have_stage1 = b.option(bool, "enable-stage1", "Include the stage1 compiler behind a feature flag") orelse false;
const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false;
- const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (is_stage1 or static_llvm);
+ const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (have_stage1 or static_llvm);
const llvm_has_m68k = b.option(
bool,
"llvm-has-m68k",
@@ -136,7 +136,7 @@ pub fn build(b: *Builder) !void {
};
const main_file: ?[]const u8 = mf: {
- if (!is_stage1) break :mf "src/main.zig";
+ if (!have_stage1) break :mf "src/main.zig";
if (use_zig0) break :mf null;
break :mf "src/stage1.zig";
};
@@ -247,7 +247,7 @@ pub fn build(b: *Builder) !void {
}
};
- if (is_stage1) {
+ if (have_stage1) {
const softfloat = b.addStaticLibrary("softfloat", null);
softfloat.setBuildMode(.ReleaseFast);
softfloat.setTarget(target);
@@ -359,7 +359,7 @@ pub fn build(b: *Builder) !void {
exe_options.addOption(bool, "enable_tracy_callstack", tracy_callstack);
exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
exe_options.addOption(bool, "value_tracing", value_tracing);
- exe_options.addOption(bool, "is_stage1", is_stage1);
+ exe_options.addOption(bool, "have_stage1", have_stage1);
if (tracy) |tracy_path| {
const client_cpp = fs.path.join(
b.allocator,
@@ -394,7 +394,7 @@ pub fn build(b: *Builder) !void {
test_cases_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots);
test_cases_options.addOption(bool, "skip_non_native", skip_non_native);
test_cases_options.addOption(bool, "skip_stage1", skip_stage1);
- test_cases_options.addOption(bool, "is_stage1", is_stage1);
+ test_cases_options.addOption(bool, "have_stage1", have_stage1);
test_cases_options.addOption(bool, "have_llvm", enable_llvm);
test_cases_options.addOption(bool, "llvm_has_m68k", llvm_has_m68k);
test_cases_options.addOption(bool, "llvm_has_csky", llvm_has_csky);
@@ -455,7 +455,6 @@ pub fn build(b: *Builder) !void {
skip_libc,
skip_stage1,
false,
- is_stage1,
));
toolchain_step.dependOn(tests.addPkgTests(
@@ -470,7 +469,6 @@ pub fn build(b: *Builder) !void {
true, // skip_libc
skip_stage1,
true, // TODO get these all passing
- is_stage1,
));
toolchain_step.dependOn(tests.addPkgTests(
@@ -485,7 +483,6 @@ pub fn build(b: *Builder) !void {
true, // skip_libc
skip_stage1,
true, // TODO get these all passing
- is_stage1,
));
toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
@@ -525,7 +522,6 @@ pub fn build(b: *Builder) !void {
skip_libc,
skip_stage1,
true, // TODO get these all passing
- is_stage1,
);
const test_step = b.step("test", "Run all the tests");
diff --git a/ci/azure/build.zig b/ci/azure/build.zig
index 053065b6997b..00f1cce2bd95 100644
--- a/ci/azure/build.zig
+++ b/ci/azure/build.zig
@@ -37,9 +37,9 @@ pub fn build(b: *Builder) !void {
const docs_step = b.step("docs", "Build documentation");
docs_step.dependOn(&docgen_cmd.step);
- const is_stage1 = b.option(bool, "stage1", "Build the stage1 compiler, put stage2 behind a feature flag") orelse false;
+ const have_stage1 = b.option(bool, "enable-stage1", "Include the stage1 compiler behind a feature flag") orelse false;
const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false;
- const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (is_stage1 or static_llvm);
+ const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (have_stage1 or static_llvm);
const llvm_has_m68k = b.option(
bool,
"llvm-has-m68k",
@@ -101,7 +101,7 @@ pub fn build(b: *Builder) !void {
break :blk 4;
};
- const main_file: ?[]const u8 = if (is_stage1) null else "src/main.zig";
+ const main_file: ?[]const u8 = if (have_stage1) null else "src/main.zig";
const exe = b.addExecutable("zig", main_file);
exe.strip = strip;
@@ -190,7 +190,7 @@ pub fn build(b: *Builder) !void {
if (enable_llvm) {
const cmake_cfg = if (static_llvm) null else findAndParseConfigH(b, config_h_path_option);
- if (is_stage1) {
+ if (have_stage1) {
const softfloat = b.addStaticLibrary("softfloat", null);
softfloat.setBuildMode(.ReleaseFast);
softfloat.setTarget(target);
@@ -298,7 +298,7 @@ pub fn build(b: *Builder) !void {
exe_options.addOption(bool, "enable_tracy_callstack", tracy_callstack);
exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
exe_options.addOption(bool, "value_tracing", value_tracing);
- exe_options.addOption(bool, "is_stage1", is_stage1);
+ exe_options.addOption(bool, "have_stage1", have_stage1);
if (tracy) |tracy_path| {
const client_cpp = fs.path.join(
b.allocator,
diff --git a/ci/azure/macos_script b/ci/azure/macos_script
index b244a7386947..d0ad9171ee8e 100755
--- a/ci/azure/macos_script
+++ b/ci/azure/macos_script
@@ -34,7 +34,7 @@ git fetch --tags
mkdir build
cd build
cmake .. \
- -DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
+ -DCMAKE_INSTALL_PREFIX="$(pwd)/stage2" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
@@ -52,23 +52,18 @@ make $JOBS install
# Here we rebuild zig but this time using the Zig binary we just now produced to
# build zig1.o rather than relying on the one built with stage0. See
# https://github.com/ziglang/zig/issues/6830 for more details.
-cmake .. -DZIG_EXECUTABLE="$(pwd)/release/bin/zig"
+cmake .. -DZIG_EXECUTABLE="$(pwd)/stage2/bin/zig"
make $JOBS install
-# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.
-release/bin/zig build -p stage2 -Denable-llvm
+stage2/bin/zig build -p release -Denable-llvm -Denable-stage1
-stage2/bin/zig build test-behavior
-
-# TODO: upgrade these to test stage2 instead of stage1
-# TODO: upgrade these to test stage3 instead of stage2
-release/bin/zig build test-behavior -Denable-macos-sdk -Domit-stage2
release/bin/zig build test-compiler-rt -Denable-macos-sdk
+release/bin/zig build test-behavior -Denable-macos-sdk
release/bin/zig build test-std -Denable-macos-sdk
release/bin/zig build test-universal-libc -Denable-macos-sdk
release/bin/zig build test-compare-output -Denable-macos-sdk
release/bin/zig build test-standalone -Denable-macos-sdk
-release/bin/zig build test-stack-traces -Denable-macos-sdk
+release/bin/zig build test-stack-traces -Denable-macos-sdk -fstage1
release/bin/zig build test-cli -Denable-macos-sdk
release/bin/zig build test-asm-link -Denable-macos-sdk
release/bin/zig build test-translate-c -Denable-macos-sdk
@@ -76,7 +71,7 @@ release/bin/zig build test-run-translated-c -Denable-macos-sdk
release/bin/zig build docs -Denable-macos-sdk
release/bin/zig build test-fmt -Denable-macos-sdk
release/bin/zig build test-cases -Denable-macos-sdk -Dsingle-threaded
-release/bin/zig build test-link -Denable-macos-sdk -Domit-stage2
+release/bin/zig build test-link -Denable-macos-sdk
if [ "${BUILD_REASON}" != "PullRequest" ]; then
mv ../LICENSE release/
diff --git a/ci/azure/pipelines.yml b/ci/azure/pipelines.yml
index 5d208b31a2f7..16804a0a2b6e 100644
--- a/ci/azure/pipelines.yml
+++ b/ci/azure/pipelines.yml
@@ -68,9 +68,7 @@ jobs:
& "${ZIGPREFIXPATH}/bin/zig.exe" build `
--prefix "$ZIGINSTALLDIR" `
--search-prefix "$ZIGPREFIXPATH" `
- -Dstage1 `
- <# stage2 is omitted until we resolve https://github.com/ziglang/zig/issues/6485 #> `
- -Domit-stage2 `
+ -Denable-stage1 `
-Dstatic-llvm `
-Drelease `
-Dstrip `
diff --git a/ci/srht/freebsd_script b/ci/srht/freebsd_script
index 9fd7c0be6505..9c77c7d120c4 100755
--- a/ci/srht/freebsd_script
+++ b/ci/srht/freebsd_script
@@ -38,10 +38,11 @@ cmake .. \
-GNinja
samu install
-# TODO ld.lld: error: undefined symbol: main
-# >>> referenced by crt1_c.c:75 (/usr/src/lib/csu/amd64/crt1_c.c:75)
-# >>> /usr/lib/crt1.o:(_start)
-#release/bin/zig test ../test/behavior.zig -fno-stage1 -fLLVM -I ../test
+# Here we rebuild zig but this time using the Zig binary we just now produced to
+# build zig1.o rather than relying on the one built with stage0. This makes it
+# a stage3 build rather than a stage2 build.
+cmake .. -DZIG_EXECUTABLE="$PREFIX/bin/zig"
+samu install
# Here we skip some tests to save time.
release/bin/zig build test -Dskip-stage1 -Dskip-non-native
diff --git a/ci/zinc/linux_test.sh b/ci/zinc/linux_test.sh
index 3a54e82c38a5..1b280fbae5fd 100755
--- a/ci/zinc/linux_test.sh
+++ b/ci/zinc/linux_test.sh
@@ -33,41 +33,39 @@ unset CXX
ninja install
-STAGE1_ZIG="$DEBUG_STAGING/bin/zig"
-
# Here we rebuild zig but this time using the Zig binary we just now produced to
# build zig1.o rather than relying on the one built with stage0. See
# https://github.com/ziglang/zig/issues/6830 for more details.
-cmake .. -DZIG_EXECUTABLE="$STAGE1_ZIG"
+cmake .. -DZIG_EXECUTABLE="$DEBUG_STAGING/bin/zig"
ninja install
cd $WORKSPACE
+"$DEBUG_STAGING/bin/zig" build -p stage3 -Denable-stage1 -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
+
+# simultaneously test building self-hosted without LLVM and with 32-bit arm
+stage3/bin/zig build -Dtarget=arm-linux-musleabihf
+
echo "Looking for non-conforming code formatting..."
echo "Formatting errors can be fixed by running 'zig fmt' on the files printed here."
-$STAGE1_ZIG fmt --check . --exclude test/cases/
-
-$STAGE1_ZIG build -p stage2 -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage2/bin/zig build -p stage3 -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage3/bin/zig build # test building self-hosted without LLVM
-stage3/bin/zig build -Dtarget=arm-linux-musleabihf # test building self-hosted for 32-bit arm
-
-stage3/bin/zig build test-compiler-rt -fqemu -fwasmtime -Denable-llvm
-stage3/bin/zig build test-behavior -fqemu -fwasmtime -Denable-llvm
-stage3/bin/zig build test-std -fqemu -fwasmtime -Denable-llvm
-stage3/bin/zig build test-universal-libc -fqemu -fwasmtime -Denable-llvm
-stage3/bin/zig build test-compare-output -fqemu -fwasmtime -Denable-llvm
-stage3/bin/zig build test-asm-link -fqemu -fwasmtime -Denable-llvm
-stage3/bin/zig build test-fmt -fqemu -fwasmtime -Denable-llvm
-stage3/bin/zig build test-translate-c -fqemu -fwasmtime -Denable-llvm
-stage3/bin/zig build test-run-translated-c -fqemu -fwasmtime -Denable-llvm
-stage3/bin/zig build test-standalone -fqemu -fwasmtime -Denable-llvm
-stage3/bin/zig build test-cli -fqemu -fwasmtime -Denable-llvm
+stage3/bin/zig fmt --check . --exclude test/cases/
+
+stage3/bin/zig build test-compiler-rt -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
+stage3/bin/zig build test-behavior -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
+stage3/bin/zig build test-std -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
+stage3/bin/zig build test-universal-libc -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
+stage3/bin/zig build test-compare-output -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
+stage3/bin/zig build test-asm-link -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
+stage3/bin/zig build test-fmt -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
+stage3/bin/zig build test-translate-c -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
+stage3/bin/zig build test-run-translated-c -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
+stage3/bin/zig build test-standalone -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
+stage3/bin/zig build test-cli -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
stage3/bin/zig build test-cases -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage3/bin/zig build test-link -fqemu -fwasmtime -Denable-llvm
+stage3/bin/zig build test-link -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
+stage3/bin/zig build docs -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-$STAGE1_ZIG build test-stack-traces -fqemu -fwasmtime
-$STAGE1_ZIG build docs -fqemu -fwasmtime
+stage3/bin/zig build test-stack-traces -fqemu -fwasmtime -fstage1
# Produce the experimental std lib documentation.
mkdir -p "$RELEASE_STAGING/docs/std"
@@ -87,7 +85,7 @@ stage3/bin/zig build \
-Drelease \
-Dstrip \
-Dtarget="$TARGET" \
- -Dstage1
+ -Denable-stage1
# Explicit exit helps show last command duration.
exit
diff --git a/doc/docgen.zig b/doc/docgen.zig
index a101b96be72d..0f0e212e3c24 100644
--- a/doc/docgen.zig
+++ b/doc/docgen.zig
@@ -285,6 +285,7 @@ const Code = struct {
link_objects: []const []const u8,
target_str: ?[]const u8,
link_libc: bool,
+ backend_stage1: bool,
link_mode: ?std.builtin.LinkMode,
disable_cache: bool,
verbose_cimport: bool,
@@ -554,6 +555,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
var link_mode: ?std.builtin.LinkMode = null;
var disable_cache = false;
var verbose_cimport = false;
+ var backend_stage1 = false;
const source_token = while (true) {
const content_tok = try eatToken(tokenizer, Token.Id.Content);
@@ -586,6 +588,8 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
link_libc = true;
} else if (mem.eql(u8, end_tag_name, "link_mode_dynamic")) {
link_mode = .Dynamic;
+ } else if (mem.eql(u8, end_tag_name, "backend_stage1")) {
+ backend_stage1 = true;
} else if (mem.eql(u8, end_tag_name, "code_end")) {
_ = try eatToken(tokenizer, Token.Id.BracketClose);
break content_tok;
@@ -609,6 +613,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
.link_objects = link_objects.toOwnedSlice(),
.target_str = target_str,
.link_libc = link_libc,
+ .backend_stage1 = backend_stage1,
.link_mode = link_mode,
.disable_cache = disable_cache,
.verbose_cimport = verbose_cimport,
@@ -1187,6 +1192,9 @@ fn printShell(out: anytype, shell_content: []const u8) !void {
try out.writeAll("");
}
+// Override this to skip to later tests
+const debug_start_line = 0;
+
fn genHtml(
allocator: Allocator,
tokenizer: *Tokenizer,
@@ -1266,6 +1274,13 @@ fn genHtml(
continue;
}
+ if (debug_start_line > 0) {
+ const loc = tokenizer.getTokenLocation(code.source_token);
+ if (debug_start_line > loc.line) {
+ continue;
+ }
+ }
+
const raw_source = tokenizer.buffer[code.source_token.start..code.source_token.end];
const trimmed_raw_source = mem.trim(u8, raw_source, " \n");
const tmp_source_file_name = try fs.path.join(
@@ -1311,6 +1326,10 @@ fn genHtml(
try build_args.append("-lc");
try shell_out.print("-lc ", .{});
}
+ if (code.backend_stage1) {
+ try build_args.append("-fstage1");
+ try shell_out.print("-fstage1", .{});
+ }
const target = try std.zig.CrossTarget.parse(.{
.arch_os_abi = code.target_str orelse "native",
});
@@ -1443,6 +1462,10 @@ fn genHtml(
try test_args.append("-lc");
try shell_out.print("-lc ", .{});
}
+ if (code.backend_stage1) {
+ try test_args.append("-fstage1");
+ try shell_out.print("-fstage1", .{});
+ }
if (code.target_str) |triple| {
try test_args.appendSlice(&[_][]const u8{ "-target", triple });
try shell_out.print("-target {s} ", .{triple});
@@ -1490,6 +1513,14 @@ fn genHtml(
try shell_out.print("-O {s} ", .{@tagName(code.mode)});
},
}
+ if (code.link_libc) {
+ try test_args.append("-lc");
+ try shell_out.print("-lc ", .{});
+ }
+ if (code.backend_stage1) {
+ try test_args.append("-fstage1");
+ try shell_out.print("-fstage1", .{});
+ }
const result = try ChildProcess.exec(.{
.allocator = allocator,
.argv = test_args.items,
diff --git a/doc/langref.html.in b/doc/langref.html.in
index c61f2d0790fe..ba817f0a4d10 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -1188,6 +1188,7 @@ test "this will be skipped" {
(The evented IO mode is enabled using the --test-evented-io command line parameter.)
{#code_begin|test|async_skip#}
+ {#backend_stage1#}
const std = @import("std");
test "async skip test" {
@@ -2768,7 +2769,7 @@ test "comptime @intToPtr" {
}
}
{#code_end#}
- {#see_also|Optional Pointers|@intToPtr|@ptrToInt|C Pointers|Pointers to Zero Bit Types#}
+ {#see_also|Optional Pointers|@intToPtr|@ptrToInt|C Pointers#}
{#header_open|volatile#}
Loads and stores are assumed to not have side effects. If a given load or store
should have side effects, such as Memory Mapped Input/Output (MMIO), use {#syntax#}volatile{#endsyntax#}.
@@ -2862,19 +2863,22 @@ var foo: u8 align(4) = 100;
test "global variable alignment" {
try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
try expect(@TypeOf(&foo) == *align(4) u8);
- const as_pointer_to_array: *[1]u8 = &foo;
- const as_slice: []u8 = as_pointer_to_array;
- try expect(@TypeOf(as_slice) == []align(4) u8);
+ const as_pointer_to_array: *align(4) [1]u8 = &foo;
+ const as_slice: []align(4) u8 = as_pointer_to_array;
+ const as_unaligned_slice: []u8 = as_slice;
+ try expect(as_unaligned_slice[0] == 100);
}
-fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; }
+fn derp() align(@sizeOf(usize) * 2) i32 {
+ return 1234;
+}
fn noop1() align(1) void {}
fn noop4() align(4) void {}
test "function alignment" {
try expect(derp() == 1234);
- try expect(@TypeOf(noop1) == fn() align(1) void);
- try expect(@TypeOf(noop4) == fn() align(4) void);
+ try expect(@TypeOf(noop1) == fn () align(1) void);
+ try expect(@TypeOf(noop4) == fn () align(4) void);
noop1();
noop4();
}
@@ -3336,6 +3340,7 @@ fn doTheTest() !void {
Zig allows the address to be taken of a non-byte-aligned field:
{#code_begin|test|pointer_to_non-byte_aligned_field#}
+ {#backend_stage1#}
const std = @import("std");
const expect = std.testing.expect;
@@ -3391,7 +3396,8 @@ fn bar(x: *const u3) u3 {
Pointers to non-ABI-aligned fields share the same address as the other fields within their host integer:
- {#code_begin|test|pointer_to_non-bit_aligned_field#}
+ {#code_begin|test|packed_struct_field_addrs#}
+ {#backend_stage1#}
const std = @import("std");
const expect = std.testing.expect;
@@ -3407,7 +3413,7 @@ var bit_field = BitField{
.c = 3,
};
-test "pointer to non-bit-aligned field" {
+test "pointers of sub-byte-aligned fields share addresses" {
try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.b));
try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.c));
}
@@ -3438,20 +3444,22 @@ test "pointer to non-bit-aligned field" {
}
{#code_end#}
- Packed structs have 1-byte alignment. However if you have an overaligned pointer to a packed struct,
- Zig should correctly understand the alignment of fields. However there is
- a bug:
+ Packed structs have the same alignment as their backing integer, however, overaligned
+ pointers to packed structs can override this:
- {#code_begin|test_err|expected type '*u32', found '*align(1) u32'#}
+ {#code_begin|test|overaligned_packed_struct#}
+const std = @import("std");
+const expect = std.testing.expect;
+
const S = packed struct {
a: u32,
b: u32,
};
test "overaligned pointer to packed struct" {
- var foo: S align(4) = undefined;
+ var foo: S align(4) = .{ .a = 1, .b = 2 };
const ptr: *align(4) S = &foo;
const ptr_to_b: *u32 = &ptr.b;
- _ = ptr_to_b;
+ try expect(ptr_to_b.* == 2);
}
{#code_end#}
When this bug is fixed, the above test in the documentation will unexpectedly pass, which will
@@ -3698,7 +3706,7 @@ test "@tagName" {
By default, enums are not guaranteed to be compatible with the C ABI:
- {#code_begin|obj_err|parameter of type 'Foo' not allowed in function with calling convention 'C'#}
+ {#code_begin|obj_err|parameter of type 'test.Foo' not allowed in function with calling convention 'C'#}
const Foo = enum { a, b, c };
export fn entry(foo: Foo) void { _ = foo; }
{#code_end#}
@@ -4004,7 +4012,7 @@ fn makeNumber() Number {
This is typically used for type safety when interacting with C code that does not expose struct details.
Example:
- {#code_begin|test_err|expected type '*Derp', found '*Wat'#}
+ {#code_begin|test_err|expected type '*test.Derp', found '*test.Wat'#}
const Derp = opaque {};
const Wat = opaque {};
@@ -4203,7 +4211,7 @@ test "switch on tagged union" {
When a {#syntax#}switch{#endsyntax#} expression does not have an {#syntax#}else{#endsyntax#} clause,
it must exhaustively list all the possible values. Failure to do so is a compile error:
- {#code_begin|test_err|not handled in switch#}
+ {#code_begin|test_err|unhandled enumeration value#}
const Color = enum {
auto,
off,
@@ -5026,17 +5034,9 @@ test "function" {
try expect(do_op(sub2, 5, 6) == -1);
}
{#code_end#}
- Function values are like pointers:
- {#code_begin|obj#}
-const assert = @import("std").debug.assert;
-
-comptime {
- assert(@TypeOf(foo) == fn()void);
- assert(@sizeOf(fn()void) == @sizeOf(?fn()void));
-}
-
-fn foo() void { }
- {#code_end#}
+ There is a difference between a function body and a function pointer.
+ Function bodies are {#link|comptime#}-only types while function {#link|Pointers#} may be
+ runtime-known.
{#header_open|Pass-by-value Parameters#}
Primitive types such as {#link|Integers#} and {#link|Floats#} passed as parameters
@@ -6123,10 +6123,11 @@ test "float widening" {
two choices about the coercion.
- - Cast {#syntax#}54.0{#endsyntax#} to {#syntax#}comptime_int{#endsyntax#} resulting in {#syntax#}@as(comptime_int, 10){#endsyntax#}, which is casted to {#syntax#}@as(f32, 10){#endsyntax#}
- - Cast {#syntax#}5{#endsyntax#} to {#syntax#}comptime_float{#endsyntax#} resulting in {#syntax#}@as(comptime_float, 10.8){#endsyntax#}, which is casted to {#syntax#}@as(f32, 10.8){#endsyntax#}
+ - Cast {#syntax#}54.0{#endsyntax#} to {#syntax#}comptime_int{#endsyntax#} resulting in {#syntax#}@as(comptime_int, 10){#endsyntax#}, which is casted to {#syntax#}@as(f32, 10){#endsyntax#}
+ - Cast {#syntax#}5{#endsyntax#} to {#syntax#}comptime_float{#endsyntax#} resulting in {#syntax#}@as(comptime_float, 10.8){#endsyntax#}, which is casted to {#syntax#}@as(f32, 10.8){#endsyntax#}
{#code_begin|test_err#}
+ {#backend_stage1#}
// Compile time coercion of float to int
test "implicit cast to comptime_int" {
var f: f32 = 54.0 / 5;
@@ -6302,19 +6303,6 @@ test "coercion between unions and enums" {
{#code_end#}
{#see_also|union|enum#}
{#header_close#}
- {#header_open|Type Coercion: Zero Bit Types#}
- {#link|Zero Bit Types#} may be coerced to single-item {#link|Pointers#},
- regardless of const.
- TODO document the reasoning for this
- TODO document whether vice versa should work and why
- {#code_begin|test|coerce_zero_bit_types#}
-test "coercion of zero bit types" {
- var x: void = {};
- var y: *void = x;
- _ = y;
-}
- {#code_end#}
- {#header_close#}
{#header_open|Type Coercion: undefined#}
{#link|undefined#} can be cast to any type.
{#header_close#}
@@ -6467,7 +6455,6 @@ test "peer type resolution: *const T and ?*T" {
An {#link|enum#} with only 1 tag.
A {#link|struct#} with all fields being zero bit types.
A {#link|union#} with only 1 field which is a zero bit type.
- {#link|Pointers to Zero Bit Types#} are themselves zero bit types.
These types can only ever have one possible value, and thus
@@ -6527,7 +6514,7 @@ test "turn HashMap into a set with void" {
Expressions of type {#syntax#}void{#endsyntax#} are the only ones whose value can be ignored. For example:
- {#code_begin|test_err|expression value is ignored#}
+ {#code_begin|test_err|ignored#}
test "ignoring expression value" {
foo();
}
@@ -6553,37 +6540,6 @@ fn foo() i32 {
}
{#code_end#}
{#header_close#}
-
- {#header_open|Pointers to Zero Bit Types#}
- Pointers to zero bit types also have zero bits. They always compare equal to each other:
- {#code_begin|test|pointers_to_zero_bits#}
-const std = @import("std");
-const expect = std.testing.expect;
-
-test "pointer to empty struct" {
- const Empty = struct {};
- var a = Empty{};
- var b = Empty{};
- var ptr_a = &a;
- var ptr_b = &b;
- comptime try expect(ptr_a == ptr_b);
-}
- {#code_end#}
- The type being pointed to can only ever be one value; therefore loads and stores are
- never generated. {#link|ptrToInt#} and {#link|intToPtr#} are not allowed:
- {#code_begin|test_err#}
-const Empty = struct {};
-
-test "@ptrToInt for pointer to zero bit type" {
- var a = Empty{};
- _ = @ptrToInt(&a);
-}
-
-test "@intToPtr for pointer to zero bit type" {
- _ = @intToPtr(*Empty, 0x1);
-}
- {#code_end#}
- {#header_close#}
{#header_close#}
{#header_open|Result Location Semantics#}
@@ -6666,7 +6622,7 @@ fn gimmeTheBiggerInteger(a: u64, b: u64) u64 {
For example, if we were to introduce another function to the above snippet:
- {#code_begin|test_err|values of type 'type' must be comptime known#}
+ {#code_begin|test_err|value with comptime only type 'type' depends on runtime control flow#}
fn max(comptime T: type, a: T, b: T) T {
return if (a > b) a else b;
}
@@ -6692,7 +6648,7 @@ fn foo(condition: bool) void {
For example:
- {#code_begin|test_err|operator not allowed for type 'bool'#}
+ {#code_begin|test_err|operator > not allowed for type 'bool'#}
fn max(comptime T: type, a: T, b: T) T {
return if (a > b) a else b;
}
@@ -6837,7 +6793,7 @@ fn performFn(start_value: i32) i32 {
use a {#syntax#}comptime{#endsyntax#} expression to guarantee that the expression will be evaluated at compile-time.
If this cannot be accomplished, the compiler will emit an error. For example:
- {#code_begin|test_err|unable to evaluate constant expression#}
+ {#code_begin|test_err|comptime call of extern function#}
extern fn exit() noreturn;
test "foo" {
@@ -6889,7 +6845,7 @@ test "fibonacci" {
Imagine if we had forgotten the base case of the recursive function and tried to run the tests:
- {#code_begin|test_err|operation caused overflow#}
+ {#code_begin|test_err|overflow of integer type#}
const expect = @import("std").testing.expect;
fn fibonacci(index: u32) u32 {
@@ -6913,7 +6869,8 @@ test "fibonacci" {
But what would have happened if we used a signed integer?
{#code_begin|test_err|evaluation exceeded 1000 backwards branches#}
-const expect = @import("std").testing.expect;
+ {#backend_stage1#}
+const assert = @import("std").debug.assert;
fn fibonacci(index: i32) i32 {
//if (index < 2) return index;
@@ -6922,7 +6879,7 @@ fn fibonacci(index: i32) i32 {
test "fibonacci" {
comptime {
- try expect(fibonacci(7) == 13);
+ try assert(fibonacci(7) == 13);
}
}
{#code_end#}
@@ -6935,8 +6892,8 @@ test "fibonacci" {
What if we fix the base case, but put the wrong value in the {#syntax#}expect{#endsyntax#} line?
- {#code_begin|test_err|test "fibonacci"... FAIL (TestUnexpectedResult)#}
-const expect = @import("std").testing.expect;
+ {#code_begin|test_err|reached unreachable#}
+const assert = @import("std").debug.assert;
fn fibonacci(index: i32) i32 {
if (index < 2) return index;
@@ -6945,16 +6902,10 @@ fn fibonacci(index: i32) i32 {
test "fibonacci" {
comptime {
- try expect(fibonacci(7) == 99999);
+ try assert(fibonacci(7) == 99999);
}
}
{#code_end#}
-
- What happened is Zig started interpreting the {#syntax#}expect{#endsyntax#} function with the
- parameter {#syntax#}ok{#endsyntax#} set to {#syntax#}false{#endsyntax#}. When the interpreter hit
- {#syntax#}@panic{#endsyntax#} it emitted a compile error because a panic during compile
- causes a compile error if it is detected at compile-time.
-
At container level (outside of any function), all expressions are implicitly
@@ -7280,6 +7231,7 @@ pub fn main() void {
{#code_begin|exe#}
{#target_linux_x86_64#}
+ {#backend_stage1#}
pub fn main() noreturn {
const msg = "hello world\n";
_ = syscall3(SYS_write, STDOUT_FILENO, @ptrToInt(msg), msg.len);
@@ -7497,6 +7449,7 @@ test "global assembly" {
or resumer (in the case of subsequent suspensions).
{#code_begin|test|suspend_no_resume#}
+ {#backend_stage1#}
const std = @import("std");
const expect = std.testing.expect;
@@ -7524,6 +7477,7 @@ fn func() void {
{#link|@frame#} provides access to the async function frame pointer.
{#code_begin|test|async_suspend_block#}
+ {#backend_stage1#}
const std = @import("std");
const expect = std.testing.expect;
@@ -7562,6 +7516,7 @@ fn testSuspendBlock() void {
never returns to its resumer and continues executing.
{#code_begin|test|resume_from_suspend#}
+ {#backend_stage1#}
const std = @import("std");
const expect = std.testing.expect;
@@ -7598,6 +7553,7 @@ fn testResumeFromSuspend(my_result: *i32) void {
and the return value of the async function would be lost.
{#code_begin|test|async_await#}
+ {#backend_stage1#}
const std = @import("std");
const expect = std.testing.expect;
@@ -7642,6 +7598,7 @@ fn func() void {
return value directly from the target function's frame.
{#code_begin|test|async_await_sequence#}
+ {#backend_stage1#}
const std = @import("std");
const expect = std.testing.expect;
@@ -7695,6 +7652,7 @@ fn seq(c: u8) void {
{#syntax#}async{#endsyntax#}/{#syntax#}await{#endsyntax#} usage:
{#code_begin|exe|async#}
+ {#backend_stage1#}
const std = @import("std");
const Allocator = std.mem.Allocator;
@@ -7773,6 +7731,7 @@ fn readFile(allocator: Allocator, filename: []const u8) ![]u8 {
observe the same behavior, with one tiny difference:
{#code_begin|exe|blocking#}
+ {#backend_stage1#}
const std = @import("std");
const Allocator = std.mem.Allocator;
@@ -7910,6 +7869,7 @@ comptime {
{#syntax#}await{#endsyntax#} will copy the result from {#syntax#}result_ptr{#endsyntax#}.
{#code_begin|test|async_struct_field_fn_pointer#}
+ {#backend_stage1#}
const std = @import("std");
const expect = std.testing.expect;
@@ -8677,6 +8637,7 @@ test "decl access by string" {
allows one to, for example, heap-allocate an async function frame:
{#code_begin|test|heap_allocated_frame#}
+ {#backend_stage1#}
const std = @import("std");
test "heap allocated frame" {
@@ -9423,12 +9384,6 @@ const std = @import("std");
const expect = std.testing.expect;
test "vector @reduce" {
- // This test regressed with LLVM 14:
- // https://github.com/llvm/llvm-project/issues/55522
- // We'll skip this test unless the self-hosted compiler is being used.
- // After LLVM 15 is released we can delete this line.
- if (@import("builtin").zig_backend == .stage1) return;
-
const value = @Vector(4, i32){ 1, -1, 1, -1 };
const result = value > @splat(4, @as(i32, 0));
// result is { true, false, true, false };
@@ -9938,7 +9893,7 @@ pub fn main() void {
{#header_close#}
{#header_open|Index out of Bounds#}
At compile-time:
- {#code_begin|test_err|index 5 outside array of size 5#}
+ {#code_begin|test_err|index 5 outside array of length 5#}
comptime {
const array: [5]u8 = "hello".*;
const garbage = array[5];
@@ -9959,9 +9914,9 @@ fn foo(x: []const u8) u8 {
{#header_close#}
{#header_open|Cast Negative Number to Unsigned Integer#}
At compile-time:
- {#code_begin|test_err|attempt to cast negative value to unsigned integer#}
+ {#code_begin|test_err|type 'u32' cannot represent integer value '-1'#}
comptime {
- const value: i32 = -1;
+ var value: i32 = -1;
const unsigned = @intCast(u32, value);
_ = unsigned;
}
@@ -9982,7 +9937,7 @@ pub fn main() void {
{#header_close#}
{#header_open|Cast Truncates Data#}
At compile-time:
- {#code_begin|test_err|cast from 'u16' to 'u8' truncates bits#}
+ {#code_begin|test_err|type 'u8' cannot represent integer value '300'#}
comptime {
const spartan_count: u16 = 300;
const byte = @intCast(u8, spartan_count);
@@ -10017,7 +9972,7 @@ pub fn main() void {
{#link|@divExact#} (division)
Example with addition at compile-time:
- {#code_begin|test_err|operation caused overflow#}
+ {#code_begin|test_err|overflow of integer type 'u8' with value '256'#}
comptime {
var byte: u8 = 255;
byte += 1;
@@ -10118,6 +10073,7 @@ test "wraparound addition and subtraction" {
{#header_open|Exact Left Shift Overflow#}
At compile-time:
{#code_begin|test_err|operation caused overflow#}
+ {#backend_stage1#}
comptime {
const x = @shlExact(@as(u8, 0b01010101), 2);
_ = x;
@@ -10137,6 +10093,7 @@ pub fn main() void {
{#header_open|Exact Right Shift Overflow#}
At compile-time:
{#code_begin|test_err|exact shift shifted out 1 bits#}
+ {#backend_stage1#}
comptime {
const x = @shrExact(@as(u8, 0b10101010), 2);
_ = x;
@@ -10200,6 +10157,7 @@ pub fn main() void {
{#header_open|Exact Division Remainder#}
At compile-time:
{#code_begin|test_err|exact division had a remainder#}
+ {#backend_stage1#}
comptime {
const a: u32 = 10;
const b: u32 = 3;
@@ -10302,7 +10260,7 @@ fn getNumberOrFail() !i32 {
{#header_close#}
{#header_open|Invalid Error Code#}
At compile-time:
- {#code_begin|test_err|integer value 11 represents no error#}
+ {#code_begin|test_err|integer value '11' represents no error#}
comptime {
const err = error.AnError;
const number = @errorToInt(err) + 10;
@@ -10324,7 +10282,7 @@ pub fn main() void {
{#header_close#}
{#header_open|Invalid Enum Cast#}
At compile-time:
- {#code_begin|test_err|has no tag matching integer value 3#}
+ {#code_begin|test_err|enum 'test.Foo' has no tag with value '3'#}
const Foo = enum {
a,
b,
@@ -10356,7 +10314,7 @@ pub fn main() void {
{#header_open|Invalid Error Set Cast#}
At compile-time:
- {#code_begin|test_err|error.B not a member of error set 'Set2'#}
+ {#code_begin|test_err|'error.B' not a member of error set 'error{A,C}'#}
const Set1 = error{
A,
B,
@@ -10417,7 +10375,7 @@ fn foo(bytes: []u8) u32 {
{#header_close#}
{#header_open|Wrong Union Field Access#}
At compile-time:
- {#code_begin|test_err|accessing union field 'float' while field 'int' is set#}
+ {#code_begin|test_err|access of union field 'float' while field 'int' is active#}
comptime {
var f = Foo{ .int = 42 };
f.float = 12.34;
@@ -10509,6 +10467,7 @@ fn bar(f: *Foo) void {
At compile-time:
{#code_begin|test_err|null pointer casted to type#}
+ {#backend_stage1#}
comptime {
const opt_ptr: ?*i32 = null;
const ptr = @ptrCast(*i32, opt_ptr);
@@ -10551,7 +10510,8 @@ const expect = std.testing.expect;
test "using an allocator" {
var buffer: [100]u8 = undefined;
- const allocator = std.heap.FixedBufferAllocator.init(&buffer).allocator();
+ var fba = std.heap.FixedBufferAllocator.init(&buffer);
+ const allocator = fba.allocator();
const result = try concat(allocator, "foo", "bar");
try expect(std.mem.eql(u8, "foobar", result));
}
@@ -10647,7 +10607,7 @@ pub fn main() !void {
String literals such as {#syntax#}"foo"{#endsyntax#} are in the global constant data section.
This is why it is an error to pass a string literal to a mutable slice, like this:
- {#code_begin|test_err|cannot cast pointer to array literal to slice type '[]u8'#}
+ {#code_begin|test_err|expected type '[]u8', found '*const [5:0]u8'#}
fn foo(s: []u8) void {
_ = s;
}
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig
index 2c2bc92c9602..69312df83853 100644
--- a/lib/std/builtin.zig
+++ b/lib/std/builtin.zig
@@ -866,7 +866,7 @@ pub fn panicUnwrapError(st: ?*StackTrace, err: anyerror) noreturn {
pub fn panicOutOfBounds(index: usize, len: usize) noreturn {
@setCold(true);
- std.debug.panic("attempt to index out of bound: index {d}, len {d}", .{ index, len });
+ std.debug.panic("index out of bounds: index {d}, len {d}", .{ index, len });
}
pub noinline fn returnError(st: *StackTrace) void {
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 6d778b955a01..84dd2739470a 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -1040,22 +1040,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
const comp = try arena.create(Compilation);
const root_name = try arena.dupeZ(u8, options.root_name);
- const use_stage1 = options.use_stage1 orelse blk: {
- // Even though we may have no Zig code to compile (depending on `options.main_pkg`),
- // we may need to use stage1 for building compiler-rt and other dependencies.
-
- if (options.use_llvm) |use_llvm| {
- if (!use_llvm) {
- break :blk false;
- }
- }
-
- // If LLVM does not support the target, then we can't use it.
- if (!target_util.hasLlvmSupport(options.target, options.target.ofmt))
- break :blk false;
-
- break :blk build_options.is_stage1;
- };
+ const use_stage1 = options.use_stage1 orelse false;
const cache_mode = if (use_stage1 and !options.disable_lld_caching)
CacheMode.whole
@@ -2211,7 +2196,7 @@ pub fn update(comp: *Compilation) !void {
comp.c_object_work_queue.writeItemAssumeCapacity(key);
}
- const use_stage1 = build_options.is_stage1 and comp.bin_file.options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
if (comp.bin_file.options.module) |module| {
module.compile_log_text.shrinkAndFree(module.gpa, 0);
module.generation += 1;
@@ -2387,7 +2372,7 @@ fn flush(comp: *Compilation, prog_node: *std.Progress.Node) !void {
};
comp.link_error_flags = comp.bin_file.errorFlags();
- const use_stage1 = build_options.is_stage1 and comp.bin_file.options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
if (!use_stage1) {
if (comp.bin_file.options.module) |module| {
try link.File.C.flushEmitH(module);
@@ -2845,7 +2830,7 @@ pub fn performAllTheWork(
comp.work_queue_wait_group.reset();
defer comp.work_queue_wait_group.wait();
- const use_stage1 = build_options.is_stage1 and comp.bin_file.options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
{
const astgen_frame = tracy.namedFrame("astgen");
@@ -3430,7 +3415,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
var man = comp.obtainCObjectCacheManifest();
defer man.deinit();
- const use_stage1 = build_options.is_stage1 and comp.bin_file.options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects
man.hash.add(use_stage1);
@@ -4745,7 +4730,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca
const target = comp.getTarget();
const generic_arch_name = target.cpu.arch.genericName();
- const use_stage1 = build_options.is_stage1 and comp.bin_file.options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
const zig_backend: std.builtin.CompilerBackend = blk: {
if (use_stage1) break :blk .stage1;
@@ -5032,7 +5017,7 @@ fn buildOutputFromZig(
.link_mode = .Static,
.function_sections = true,
.no_builtin = true,
- .use_stage1 = build_options.is_stage1 and comp.bin_file.options.use_stage1,
+ .use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1,
.want_sanitize_c = false,
.want_stack_check = false,
.want_stack_protector = 0,
diff --git a/src/config.zig.in b/src/config.zig.in
index 336a6c45edae..12e13815f84c 100644
--- a/src/config.zig.in
+++ b/src/config.zig.in
@@ -8,5 +8,5 @@ pub const enable_logging: bool = @ZIG_ENABLE_LOGGING_BOOL@;
pub const enable_link_snapshots: bool = false;
pub const enable_tracy = false;
pub const value_tracing = false;
-pub const is_stage1 = true;
+pub const have_stage1 = true;
pub const skip_non_native = false;
diff --git a/src/link.zig b/src/link.zig
index a0c0c5c369ee..a85969d61eb7 100644
--- a/src/link.zig
+++ b/src/link.zig
@@ -279,7 +279,7 @@ pub const File = struct {
return &(try MachO.openPath(allocator, options)).base;
}
- const use_stage1 = build_options.is_stage1 and options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and options.use_stage1;
if (use_stage1 or options.emit == null) {
return switch (options.target.ofmt) {
.coff => &(try Coff.createEmpty(allocator, options)).base,
@@ -817,7 +817,7 @@ pub const File = struct {
// If there is no Zig code to compile, then we should skip flushing the output file
// because it will not be part of the linker line anyway.
const module_obj_path: ?[]const u8 = if (base.options.module) |module| blk: {
- const use_stage1 = build_options.is_stage1 and base.options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and base.options.use_stage1;
if (use_stage1) {
const obj_basename = try std.zig.binNameAlloc(arena, .{
.root_name = base.options.root_name,
diff --git a/src/link/Coff.zig b/src/link/Coff.zig
index 92e9dce3ad28..a01b9cf7c3ac 100644
--- a/src/link/Coff.zig
+++ b/src/link/Coff.zig
@@ -411,7 +411,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Coff {
};
const use_llvm = build_options.have_llvm and options.use_llvm;
- const use_stage1 = build_options.is_stage1 and options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and options.use_stage1;
if (use_llvm and !use_stage1) {
self.llvm_object = try LlvmObject.create(gpa, options);
}
@@ -949,7 +949,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) !
// If there is no Zig code to compile, then we should skip flushing the output file because it
// will not be part of the linker line anyway.
const module_obj_path: ?[]const u8 = if (self.base.options.module) |module| blk: {
- const use_stage1 = build_options.is_stage1 and self.base.options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and self.base.options.use_stage1;
if (use_stage1) {
const obj_basename = try std.zig.binNameAlloc(arena, .{
.root_name = self.base.options.root_name,
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
index 9902886baca5..ade4f62f91e2 100644
--- a/src/link/Elf.zig
+++ b/src/link/Elf.zig
@@ -328,7 +328,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf {
.page_size = page_size,
};
const use_llvm = build_options.have_llvm and options.use_llvm;
- const use_stage1 = build_options.is_stage1 and options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and options.use_stage1;
if (use_llvm and !use_stage1) {
self.llvm_object = try LlvmObject.create(gpa, options);
}
diff --git a/src/link/MachO.zig b/src/link/MachO.zig
index 7a5084302363..020388cee871 100644
--- a/src/link/MachO.zig
+++ b/src/link/MachO.zig
@@ -272,7 +272,7 @@ pub const Export = struct {
pub fn openPath(allocator: Allocator, options: link.Options) !*MachO {
assert(options.target.ofmt == .macho);
- const use_stage1 = build_options.is_stage1 and options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and options.use_stage1;
if (use_stage1 or options.emit == null) {
return createEmpty(allocator, options);
}
@@ -363,7 +363,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {
const cpu_arch = options.target.cpu.arch;
const page_size: u16 = if (cpu_arch == .aarch64) 0x4000 else 0x1000;
const use_llvm = build_options.have_llvm and options.use_llvm;
- const use_stage1 = build_options.is_stage1 and options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and options.use_stage1;
const self = try gpa.create(MachO);
errdefer gpa.destroy(self);
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig
index 626786588873..626f17665215 100644
--- a/src/link/Wasm.zig
+++ b/src/link/Wasm.zig
@@ -356,7 +356,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Wasm {
}
const use_llvm = build_options.have_llvm and options.use_llvm;
- const use_stage1 = build_options.is_stage1 and options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and options.use_stage1;
if (use_llvm and !use_stage1) {
self.llvm_object = try LlvmObject.create(gpa, options);
}
@@ -2593,7 +2593,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
// If there is no Zig code to compile, then we should skip flushing the output file because it
// will not be part of the linker line anyway.
const module_obj_path: ?[]const u8 = if (self.base.options.module) |mod| blk: {
- const use_stage1 = build_options.is_stage1 and self.base.options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and self.base.options.use_stage1;
if (use_stage1) {
const obj_basename = try std.zig.binNameAlloc(arena, .{
.root_name = self.base.options.root_name,
@@ -2803,7 +2803,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
if (self.base.options.module) |mod| {
// when we use stage1, we use the exports that stage1 provided us.
// For stage2, we can directly retrieve them from the module.
- const use_stage1 = build_options.is_stage1 and self.base.options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and self.base.options.use_stage1;
if (use_stage1) {
for (comp.export_symbol_names.items) |symbol_name| {
try argv.append(try std.fmt.allocPrint(arena, "--export={s}", .{symbol_name}));
diff --git a/src/main.zig b/src/main.zig
index 91d171d23764..dd3a7e797bdb 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -2989,7 +2989,7 @@ fn buildOutputType(
return std.io.getStdOut().writeAll(try comp.generateBuiltinZigSource(arena));
}
if (arg_mode == .translate_c) {
- const stage1_mode = use_stage1 orelse build_options.is_stage1;
+ const stage1_mode = use_stage1 orelse false;
return cmdTranslateC(comp, arena, have_enable_cache, stage1_mode);
}
diff --git a/src/stage1.zig b/src/stage1.zig
index 826fdd0f6bb9..e3f0daaa4450 100644
--- a/src/stage1.zig
+++ b/src/stage1.zig
@@ -18,7 +18,7 @@ const target_util = @import("target.zig");
comptime {
assert(builtin.link_libc);
- assert(build_options.is_stage1);
+ assert(build_options.have_stage1);
assert(build_options.have_llvm);
if (!builtin.is_test) {
@export(main, .{ .name = "main" });
diff --git a/src/test.zig b/src/test.zig
index a8567f24928b..babded13f9d7 100644
--- a/src/test.zig
+++ b/src/test.zig
@@ -25,7 +25,7 @@ const skip_stage1 = builtin.zig_backend != .stage1 or build_options.skip_stage1;
const hr = "=" ** 80;
test {
- if (build_options.is_stage1) {
+ if (build_options.have_stage1) {
@import("stage1.zig").os_init();
}
diff --git a/test/cases/safety/empty slice with sentinel out of bounds.zig b/test/cases/safety/empty slice with sentinel out of bounds.zig
index 835b084740c5..d989a33541c1 100644
--- a/test/cases/safety/empty slice with sentinel out of bounds.zig
+++ b/test/cases/safety/empty slice with sentinel out of bounds.zig
@@ -2,7 +2,7 @@ const std = @import("std");
pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
_ = stack_trace;
- if (std.mem.eql(u8, message, "attempt to index out of bound: index 1, len 0")) {
+ if (std.mem.eql(u8, message, "index out of bounds: index 1, len 0")) {
std.process.exit(0);
}
std.process.exit(1);
diff --git a/test/cases/safety/out of bounds slice access.zig b/test/cases/safety/out of bounds slice access.zig
index a30532aee78c..ddd9e74cf285 100644
--- a/test/cases/safety/out of bounds slice access.zig
+++ b/test/cases/safety/out of bounds slice access.zig
@@ -2,20 +2,20 @@ const std = @import("std");
pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
_ = stack_trace;
- if (std.mem.eql(u8, message, "attempt to index out of bound: index 4, len 4")) {
+ if (std.mem.eql(u8, message, "index out of bounds: index 4, len 4")) {
std.process.exit(0);
}
std.process.exit(1);
}
pub fn main() !void {
- const a = [_]i32{1, 2, 3, 4};
+ const a = [_]i32{ 1, 2, 3, 4 };
baz(bar(&a));
return error.TestFailed;
}
fn bar(a: []const i32) i32 {
return a[4];
}
-fn baz(_: i32) void { }
+fn baz(_: i32) void {}
// run
// backend=llvm
// target=native
diff --git a/test/cases/safety/slice with sentinel out of bounds - runtime len.zig b/test/cases/safety/slice with sentinel out of bounds - runtime len.zig
index fa2e127107c8..524c69d7b7dd 100644
--- a/test/cases/safety/slice with sentinel out of bounds - runtime len.zig
+++ b/test/cases/safety/slice with sentinel out of bounds - runtime len.zig
@@ -2,7 +2,7 @@ const std = @import("std");
pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
_ = stack_trace;
- if (std.mem.eql(u8, message, "attempt to index out of bound: index 5, len 4")) {
+ if (std.mem.eql(u8, message, "index out of bounds: index 5, len 4")) {
std.process.exit(0);
}
std.process.exit(1);
diff --git a/test/cases/safety/slice with sentinel out of bounds.zig b/test/cases/safety/slice with sentinel out of bounds.zig
index 3cc8bfb355a4..636235a5b34c 100644
--- a/test/cases/safety/slice with sentinel out of bounds.zig
+++ b/test/cases/safety/slice with sentinel out of bounds.zig
@@ -2,7 +2,7 @@ const std = @import("std");
pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
_ = stack_trace;
- if (std.mem.eql(u8, message, "attempt to index out of bound: index 5, len 4")) {
+ if (std.mem.eql(u8, message, "index out of bounds: index 5, len 4")) {
std.process.exit(0);
}
std.process.exit(1);
diff --git a/test/tests.zig b/test/tests.zig
index e1836dc1e010..bd3c1c5dec39 100644
--- a/test/tests.zig
+++ b/test/tests.zig
@@ -601,7 +601,6 @@ pub fn addPkgTests(
skip_libc: bool,
skip_stage1: bool,
skip_stage2: bool,
- is_stage1: bool,
) *build.Step {
const step = b.step(b.fmt("test-{s}", .{name}), desc);
@@ -630,7 +629,7 @@ pub fn addPkgTests(
if (test_target.backend) |backend| switch (backend) {
.stage1 => if (skip_stage1) continue,
else => if (skip_stage2) continue,
- } else if (is_stage1 and skip_stage1) continue;
+ } else if (skip_stage2) continue;
const want_this_mode = for (modes) |m| {
if (m == test_target.mode) break true;
From 06c42a0c68b5e3ce54135738704cc7c6c5b92565 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Mon, 8 Aug 2022 16:59:38 -0700
Subject: [PATCH 03/24] CI: test both stage3-debug and stage3-release on
x86-linux
---
ci/zinc/drone.yml | 12 ++-
...nux_test.sh => linux_test_stage3_debug.sh} | 29 +-----
ci/zinc/linux_test_stage3_release.sh | 91 +++++++++++++++++++
3 files changed, 104 insertions(+), 28 deletions(-)
rename ci/zinc/{linux_test.sh => linux_test_stage3_debug.sh} (84%)
create mode 100755 ci/zinc/linux_test_stage3_release.sh
diff --git a/ci/zinc/drone.yml b/ci/zinc/drone.yml
index 6bb7d73b41c1..38185df7e7d7 100644
--- a/ci/zinc/drone.yml
+++ b/ci/zinc/drone.yml
@@ -9,14 +9,20 @@ workspace:
path: /workspace
steps:
-- name: test
+- name: test_stage3_debug
image: ci/debian-amd64:11.1-6
commands:
- - ./ci/zinc/linux_test.sh
+ - ./ci/zinc/linux_test_stage3_debug.sh
+
+- name: test_stage3_release
+ image: ci/debian-amd64:11.1-6
+ commands:
+ - ./ci/zinc/linux_test_stage3_release.sh
- name: package
depends_on:
- - test
+ - test_stage3_debug
+ - test_stage3_release
when:
branch:
- master
diff --git a/ci/zinc/linux_test.sh b/ci/zinc/linux_test_stage3_debug.sh
similarity index 84%
rename from ci/zinc/linux_test.sh
rename to ci/zinc/linux_test_stage3_debug.sh
index 1b280fbae5fd..85cfb57b2ef4 100755
--- a/ci/zinc/linux_test.sh
+++ b/ci/zinc/linux_test_stage3_debug.sh
@@ -10,13 +10,13 @@ MCPU="baseline"
# This will affect the cmake command below.
git config core.abbrev 9
-echo "building debug zig with zig version $($OLD_ZIG version)"
+echo "building stage3-debug with zig version $($OLD_ZIG version)"
export CC="$OLD_ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$OLD_ZIG c++ -target $TARGET -mcpu=$MCPU"
-mkdir _debug
-cd _debug
+mkdir build-debug
+cd build-debug
cmake .. \
-DCMAKE_INSTALL_PREFIX="$DEBUG_STAGING" \
-DCMAKE_PREFIX_PATH="$DEPS_LOCAL" \
@@ -63,29 +63,8 @@ stage3/bin/zig build test-standalone -fqemu -fwasmtime -Dstatic-llvm -Dtar
stage3/bin/zig build test-cli -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
stage3/bin/zig build test-cases -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
stage3/bin/zig build test-link -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
+stage3/bin/zig build test-stack-traces -fqemu -fwasmtime -fstage1
stage3/bin/zig build docs -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage3/bin/zig build test-stack-traces -fqemu -fwasmtime -fstage1
-
-# Produce the experimental std lib documentation.
-mkdir -p "$RELEASE_STAGING/docs/std"
-stage3/bin/zig test lib/std/std.zig \
- --zig-lib-dir lib \
- -femit-docs=$RELEASE_STAGING/docs/std \
- -fno-emit-bin
-
-# Look for HTML errors.
-tidy --drop-empty-elements no -qe zig-cache/langref.html
-
-# Build release zig.
-stage3/bin/zig build \
- --prefix "$RELEASE_STAGING" \
- --search-prefix "$DEPS_LOCAL" \
- -Dstatic-llvm \
- -Drelease \
- -Dstrip \
- -Dtarget="$TARGET" \
- -Denable-stage1
-
# Explicit exit helps show last command duration.
exit
diff --git a/ci/zinc/linux_test_stage3_release.sh b/ci/zinc/linux_test_stage3_release.sh
new file mode 100755
index 000000000000..764c89db8fb7
--- /dev/null
+++ b/ci/zinc/linux_test_stage3_release.sh
@@ -0,0 +1,91 @@
+#!/bin/sh
+
+. ./ci/zinc/linux_base.sh
+
+OLD_ZIG="$DEPS_LOCAL/bin/zig"
+TARGET="${ARCH}-linux-musl"
+MCPU="baseline"
+
+# Make the `zig version` number consistent.
+# This will affect the cmake command below.
+git config core.abbrev 9
+
+echo "building stage3-release with zig version $($OLD_ZIG version)"
+
+export CC="$OLD_ZIG cc -target $TARGET -mcpu=$MCPU"
+export CXX="$OLD_ZIG c++ -target $TARGET -mcpu=$MCPU"
+
+mkdir build-release
+cd build-release
+STAGE2_PREFIX="$(pwd)/stage2"
+cmake .. \
+ -DCMAKE_INSTALL_PREFIX="$STAGE2_PREFIX" \
+ -DCMAKE_PREFIX_PATH="$DEPS_LOCAL" \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DZIG_TARGET_TRIPLE="$TARGET" \
+ -DZIG_TARGET_MCPU="$MCPU" \
+ -DZIG_STATIC=ON \
+ -GNinja
+
+# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
+# so that installation and testing do not get affected by them.
+unset CC
+unset CXX
+
+ninja install
+
+# Here we rebuild zig but this time using the Zig binary we just now produced to
+# build zig1.o rather than relying on the one built with stage0. See
+# https://github.com/ziglang/zig/issues/6830 for more details.
+cmake .. -DZIG_EXECUTABLE="$STAGE2_PREFIX/bin/zig"
+ninja install
+
+# This is the binary we will distribute. We intentionally test this one in this
+# script. If any test failures occur, hopefully they also occur in the debug
+# version of this script for easier troubleshooting. This prevents distribution
+# of a Zig binary that passes tests in debug mode but has a miscompilation in
+# release mode.
+"$STAGE2_PREFIX/bin/zig" build \
+ --prefix "$RELEASE_STAGING" \
+ --search-prefix "$DEPS_LOCAL" \
+ -Dstatic-llvm \
+ -Drelease \
+ -Dstrip \
+ -Dtarget="$TARGET" \
+ -Denable-stage1
+
+cd $WORKSPACE
+
+ZIG="$RELEASE_STAGING/bin/zig"
+
+$ZIG build \
+ test-compiler-rt \
+ test-behavior \
+ test-std \
+ test-universal-libc \
+ test-compare-output \
+ test-asm-link \
+ test-translate-c \
+ test-run-translated-c \
+ test-standalone \
+ test-cli \
+ test-cases \
+ test-link \
+ -fqemu \
+ -fwasmtime \
+ -Dstatic-llvm \
+ -Dtarget=native-native-musl \
+ --search-prefix "$DEPS_LOCAL"
+
+# Produce the experimental std lib documentation.
+mkdir -p "$RELEASE_STAGING/docs/std"
+$ZIG test lib/std/std.zig \
+ --zig-lib-dir lib \
+ -femit-docs=$RELEASE_STAGING/docs/std \
+ -fno-emit-bin
+
+# Look for HTML errors.
+tidy --drop-empty-elements no -qe zig-cache/langref.html
+
+# Explicit exit helps show last command duration.
+exit
From a73b3a0d70a094514a53aa028ee1321f63d950ab Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Tue, 9 Aug 2022 02:58:39 -0700
Subject: [PATCH 04/24] CI: simplify x86 linux test instructions
---
ci/zinc/linux_package.sh | 3 ---
ci/zinc/linux_test_stage3_debug.sh | 21 ++++++---------------
ci/zinc/linux_test_stage3_release.sh | 19 +++++--------------
3 files changed, 11 insertions(+), 32 deletions(-)
diff --git a/ci/zinc/linux_package.sh b/ci/zinc/linux_package.sh
index 547a2d76b8e0..b89e2d851169 100755
--- a/ci/zinc/linux_package.sh
+++ b/ci/zinc/linux_package.sh
@@ -2,9 +2,6 @@
. ./ci/zinc/linux_base.sh
-cp LICENSE $RELEASE_STAGING/
-cp zig-cache/langref.html $RELEASE_STAGING/docs/
-
# Remove the unnecessary bin dir in $prefix/bin/zig
mv $RELEASE_STAGING/bin/zig $RELEASE_STAGING/
rmdir $RELEASE_STAGING/bin
diff --git a/ci/zinc/linux_test_stage3_debug.sh b/ci/zinc/linux_test_stage3_debug.sh
index 85cfb57b2ef4..d40ad9da1192 100755
--- a/ci/zinc/linux_test_stage3_debug.sh
+++ b/ci/zinc/linux_test_stage3_debug.sh
@@ -50,21 +50,12 @@ echo "Looking for non-conforming code formatting..."
echo "Formatting errors can be fixed by running 'zig fmt' on the files printed here."
stage3/bin/zig fmt --check . --exclude test/cases/
-stage3/bin/zig build test-compiler-rt -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage3/bin/zig build test-behavior -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage3/bin/zig build test-std -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage3/bin/zig build test-universal-libc -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage3/bin/zig build test-compare-output -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage3/bin/zig build test-asm-link -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage3/bin/zig build test-fmt -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage3/bin/zig build test-translate-c -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage3/bin/zig build test-run-translated-c -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage3/bin/zig build test-standalone -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage3/bin/zig build test-cli -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage3/bin/zig build test-cases -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage3/bin/zig build test-link -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
-stage3/bin/zig build test-stack-traces -fqemu -fwasmtime -fstage1
-stage3/bin/zig build docs -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
+stage3/bin/zig build test \
+ -fqemu \
+ -fwasmtime \
+ -Dstatic-llvm \
+ -Dtarget=native-native-musl \
+ --search-prefix "$DEPS_LOCAL"
# Explicit exit helps show last command duration.
exit
diff --git a/ci/zinc/linux_test_stage3_release.sh b/ci/zinc/linux_test_stage3_release.sh
index 764c89db8fb7..dd906f70fbce 100755
--- a/ci/zinc/linux_test_stage3_release.sh
+++ b/ci/zinc/linux_test_stage3_release.sh
@@ -58,19 +58,7 @@ cd $WORKSPACE
ZIG="$RELEASE_STAGING/bin/zig"
-$ZIG build \
- test-compiler-rt \
- test-behavior \
- test-std \
- test-universal-libc \
- test-compare-output \
- test-asm-link \
- test-translate-c \
- test-run-translated-c \
- test-standalone \
- test-cli \
- test-cases \
- test-link \
+$ZIG build test \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
@@ -84,8 +72,11 @@ $ZIG test lib/std/std.zig \
-femit-docs=$RELEASE_STAGING/docs/std \
-fno-emit-bin
+cp LICENSE $RELEASE_STAGING/
+cp zig-cache/langref.html $RELEASE_STAGING/docs/
+
# Look for HTML errors.
-tidy --drop-empty-elements no -qe zig-cache/langref.html
+tidy --drop-empty-elements no -qe $RELEASE_STAGING/docs/langref.html
# Explicit exit helps show last command duration.
exit
From 09ec9b03154d909cca0d1719d804a67a11d85f5f Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Wed, 10 Aug 2022 14:49:42 -0700
Subject: [PATCH 05/24] langref: update to new error message
---
doc/langref.html.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/doc/langref.html.in b/doc/langref.html.in
index ba817f0a4d10..9247d3bc4394 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -6622,7 +6622,7 @@ fn gimmeTheBiggerInteger(a: u64, b: u64) u64 {
For example, if we were to introduce another function to the above snippet:
- {#code_begin|test_err|value with comptime only type 'type' depends on runtime control flow#}
+ {#code_begin|test_err|unable to resolve comptime value#}
fn max(comptime T: type, a: T, b: T) T {
return if (a > b) a else b;
}
From e3ccea70dd13ce94f5d2c96c7824fb743282447c Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Wed, 10 Aug 2022 14:49:56 -0700
Subject: [PATCH 06/24] CI: isolate zig-cache for parallel debug/release builds
---
ci/zinc/linux_test_stage3_debug.sh | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/ci/zinc/linux_test_stage3_debug.sh b/ci/zinc/linux_test_stage3_debug.sh
index d40ad9da1192..2ca2f7bad727 100755
--- a/ci/zinc/linux_test_stage3_debug.sh
+++ b/ci/zinc/linux_test_stage3_debug.sh
@@ -12,6 +12,12 @@ git config core.abbrev 9
echo "building stage3-debug with zig version $($OLD_ZIG version)"
+# Override the cache directories so that we don't clobber with the release
+# testing script which is running concurrently and in the same directory.
+# Normally we want processes to cooperate, but in this case we want them isolated.
+export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-cache-local-debug"
+export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-cache-global-debug"
+
export CC="$OLD_ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$OLD_ZIG c++ -target $TARGET -mcpu=$MCPU"
From 7346600517f5902316e5b8c179d8120b7854a5e1 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Wed, 10 Aug 2022 16:33:48 -0700
Subject: [PATCH 07/24] CI: avoid concurrent jobs tripping over each other
---
ci/zinc/linux_base.sh | 4 ++++
ci/zinc/linux_test_stage3_debug.sh | 12 ++++++------
ci/zinc/linux_test_stage3_release.sh | 4 ----
3 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/ci/zinc/linux_base.sh b/ci/zinc/linux_base.sh
index f1e992425832..9a757c8197f9 100755
--- a/ci/zinc/linux_base.sh
+++ b/ci/zinc/linux_base.sh
@@ -25,3 +25,7 @@ DEBUG_STAGING="$WORKSPACE/_debug/staging"
RELEASE_STAGING="$WORKSPACE/_release/staging"
export PATH=$DEPS_LOCAL/bin:$PATH
+
+# Make the `zig version` number consistent.
+# This will affect the cmake commands that follow.
+git config core.abbrev 9
diff --git a/ci/zinc/linux_test_stage3_debug.sh b/ci/zinc/linux_test_stage3_debug.sh
index 2ca2f7bad727..2bacf6d838e3 100755
--- a/ci/zinc/linux_test_stage3_debug.sh
+++ b/ci/zinc/linux_test_stage3_debug.sh
@@ -6,10 +6,6 @@ OLD_ZIG="$DEPS_LOCAL/bin/zig"
TARGET="${ARCH}-linux-musl"
MCPU="baseline"
-# Make the `zig version` number consistent.
-# This will affect the cmake command below.
-git config core.abbrev 9
-
echo "building stage3-debug with zig version $($OLD_ZIG version)"
# Override the cache directories so that we don't clobber with the release
@@ -53,8 +49,12 @@ cd $WORKSPACE
stage3/bin/zig build -Dtarget=arm-linux-musleabihf
echo "Looking for non-conforming code formatting..."
-echo "Formatting errors can be fixed by running 'zig fmt' on the files printed here."
-stage3/bin/zig fmt --check . --exclude test/cases/
+stage3/bin/zig fmt --check . \
+ --exclude test/cases/ \
+ --exclude build-debug \
+ --exclude build-release \
+ --exclude "$ZIG_LOCAL_CACHE_DIR" \
+ --exclude "$ZIG_GLOBAL_CACHE_DIR"
stage3/bin/zig build test \
-fqemu \
diff --git a/ci/zinc/linux_test_stage3_release.sh b/ci/zinc/linux_test_stage3_release.sh
index dd906f70fbce..d3532e0976dc 100755
--- a/ci/zinc/linux_test_stage3_release.sh
+++ b/ci/zinc/linux_test_stage3_release.sh
@@ -6,10 +6,6 @@ OLD_ZIG="$DEPS_LOCAL/bin/zig"
TARGET="${ARCH}-linux-musl"
MCPU="baseline"
-# Make the `zig version` number consistent.
-# This will affect the cmake command below.
-git config core.abbrev 9
-
echo "building stage3-release with zig version $($OLD_ZIG version)"
export CC="$OLD_ZIG cc -target $TARGET -mcpu=$MCPU"
From d75d40dfdfeb82dc9b1b2b5cdcd3fdb8105ac97d Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Wed, 10 Aug 2022 18:00:24 -0700
Subject: [PATCH 08/24] build: make docs a separate step than test
---
build.zig | 1 -
ci/srht/freebsd_script | 2 +-
ci/zinc/linux_test_stage3_release.sh | 2 +-
3 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/build.zig b/build.zig
index 6823248431da..bb3db637d63c 100644
--- a/build.zig
+++ b/build.zig
@@ -527,7 +527,6 @@ pub fn build(b: *Builder) !void {
const test_step = b.step("test", "Run all the tests");
test_step.dependOn(toolchain_step);
test_step.dependOn(std_step);
- test_step.dependOn(docs_step);
}
const exe_cflags = [_][]const u8{
diff --git a/ci/srht/freebsd_script b/ci/srht/freebsd_script
index 9c77c7d120c4..45002fda154a 100755
--- a/ci/srht/freebsd_script
+++ b/ci/srht/freebsd_script
@@ -45,7 +45,7 @@ cmake .. -DZIG_EXECUTABLE="$PREFIX/bin/zig"
samu install
# Here we skip some tests to save time.
-release/bin/zig build test -Dskip-stage1 -Dskip-non-native
+release/bin/zig build test docs -Dskip-stage1 -Dskip-non-native
if [ -f ~/.s3cfg ]; then
mv ../LICENSE release/
diff --git a/ci/zinc/linux_test_stage3_release.sh b/ci/zinc/linux_test_stage3_release.sh
index d3532e0976dc..3f330cf548f5 100755
--- a/ci/zinc/linux_test_stage3_release.sh
+++ b/ci/zinc/linux_test_stage3_release.sh
@@ -54,7 +54,7 @@ cd $WORKSPACE
ZIG="$RELEASE_STAGING/bin/zig"
-$ZIG build test \
+$ZIG build test docs \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
From 9f43ebd6ef753e2e6a8ab8266724720329ea5846 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Wed, 10 Aug 2022 18:53:09 -0700
Subject: [PATCH 09/24] CI: windows: build stage3 directly from dev kit
---
ci/azure/pipelines.yml | 28 +++++++---------------------
1 file changed, 7 insertions(+), 21 deletions(-)
diff --git a/ci/azure/pipelines.yml b/ci/azure/pipelines.yml
index 16804a0a2b6e..730ecbda23d5 100644
--- a/ci/azure/pipelines.yml
+++ b/ci/azure/pipelines.yml
@@ -56,12 +56,6 @@ jobs:
git fetch --unshallow # `git describe` won't work on a shallow repo
}
- # The dev kit zip file that we have here is old, and may be incompatible with
- # the build.zig script of master branch. So we keep an old version of build.zig
- # here in the CI directory.
- mv build.zig build.zig.master
- mv ci/azure/build.zig build.zig
-
mkdir $ZIGBUILDDIR
cd $ZIGBUILDDIR
@@ -73,16 +67,11 @@ jobs:
-Drelease `
-Dstrip `
-Duse-zig-libcxx `
- -Dtarget=$(TARGET)
+ -Dtarget=$(TARGET) `
+ -fno-stage1
CheckLastExitCode
cd -
-
- # Now that we have built an up-to-date zig.exe, we restore the original
- # build script from master branch.
- rm build.zig
- mv build.zig.master build.zig
-
name: build
displayName: 'Build'
@@ -96,15 +85,12 @@ jobs:
return 0
}
- # Sadly, stage2 is omitted from this build to save memory on the CI server. Once self-hosted is
- # built with itself and does not gobble as much memory, we can enable these tests.
- #& "$ZIGINSTALLDIR\bin\zig.exe" test "..\test\behavior.zig" -fno-stage1 -fLLVM -I "..\test" 2>&1
- #CheckLastExitCode
-
- & "$ZIGINSTALLDIR\bin\zig.exe" build test-toolchain -Dskip-non-native -Dskip-stage2-tests -Domit-stage2 2>&1
- CheckLastExitCode
- & "$ZIGINSTALLDIR\bin\zig.exe" build test-std -Dskip-non-native 2>&1
+ & "$ZIGINSTALLDIR\bin\zig.exe" build test `
+ --search-prefix "$ZIGPREFIXPATH" `
+ -Dstatic-llvm `
+ -Dskip-non-native
CheckLastExitCode
+
name: test
displayName: 'Test'
From 7cf6930e249d578512213dd83d7ff5d97c3fcac5 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Wed, 10 Aug 2022 21:46:01 -0700
Subject: [PATCH 10/24] CI: macos: set release mode for zig and simplify
---
ci/azure/macos_script | 29 ++++++++++++-----------------
1 file changed, 12 insertions(+), 17 deletions(-)
diff --git a/ci/azure/macos_script b/ci/azure/macos_script
index d0ad9171ee8e..bf55dda51017 100755
--- a/ci/azure/macos_script
+++ b/ci/azure/macos_script
@@ -55,23 +55,18 @@ make $JOBS install
cmake .. -DZIG_EXECUTABLE="$(pwd)/stage2/bin/zig"
make $JOBS install
-stage2/bin/zig build -p release -Denable-llvm -Denable-stage1
-
-release/bin/zig build test-compiler-rt -Denable-macos-sdk
-release/bin/zig build test-behavior -Denable-macos-sdk
-release/bin/zig build test-std -Denable-macos-sdk
-release/bin/zig build test-universal-libc -Denable-macos-sdk
-release/bin/zig build test-compare-output -Denable-macos-sdk
-release/bin/zig build test-standalone -Denable-macos-sdk
-release/bin/zig build test-stack-traces -Denable-macos-sdk -fstage1
-release/bin/zig build test-cli -Denable-macos-sdk
-release/bin/zig build test-asm-link -Denable-macos-sdk
-release/bin/zig build test-translate-c -Denable-macos-sdk
-release/bin/zig build test-run-translated-c -Denable-macos-sdk
-release/bin/zig build docs -Denable-macos-sdk
-release/bin/zig build test-fmt -Denable-macos-sdk
-release/bin/zig build test-cases -Denable-macos-sdk -Dsingle-threaded
-release/bin/zig build test-link -Denable-macos-sdk
+stage2/bin/zig build -p release \
+ --search-prefix "$PREFIX" \
+ -Dstatic-llvm \
+ -Drelease \
+ -Dstrip \
+ -Dtarget="$TARGET" \
+ -Denable-stage1
+
+release/bin/zig build test docs \
+ -Denable-macos-sdk \
+ -Dstatic-llvm \
+ --search-prefix "$PREFIX"
if [ "${BUILD_REASON}" != "PullRequest" ]; then
mv ../LICENSE release/
From a8f86291d2c108fbc70de175660742a737b78823 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Wed, 10 Aug 2022 22:51:00 -0700
Subject: [PATCH 11/24] CI: update freebsd tarball
This updates to a stage3 freebsd tarball.
---
ci/srht/freebsd_script | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/ci/srht/freebsd_script b/ci/srht/freebsd_script
index 45002fda154a..02ab218756e5 100755
--- a/ci/srht/freebsd_script
+++ b/ci/srht/freebsd_script
@@ -7,7 +7,7 @@ sudo pkg update -fq
sudo pkg install -y cmake py39-s3cmd wget curl jq samurai
ZIGDIR="$(pwd)"
-CACHE_BASENAME="zig+llvm+lld+clang-x86_64-freebsd-gnu-0.10.0-dev.2931+bdf3fa12f"
+CACHE_BASENAME="zig+llvm+lld+clang-x86_64-freebsd-gnu-0.10.0-dev.3524+74673b7f6"
PREFIX="$HOME/$CACHE_BASENAME"
cd $HOME
@@ -45,7 +45,11 @@ cmake .. -DZIG_EXECUTABLE="$PREFIX/bin/zig"
samu install
# Here we skip some tests to save time.
-release/bin/zig build test docs -Dskip-stage1 -Dskip-non-native
+release/bin/zig build test docs \
+ --search-prefix "$PREFIX" \
+ -Dstatic-llvm \
+ -Dskip-stage1 \
+ -Dskip-non-native
if [ -f ~/.s3cfg ]; then
mv ../LICENSE release/
From 5b486b1851ce3ee930236653fc0f8b0ec3eef5e6 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Thu, 11 Aug 2022 00:29:40 -0700
Subject: [PATCH 12/24] CI: use zig build to produce release artifact
For both macOS and FreeBSD.
---
ci/azure/macos_script | 27 +++++++++--------------
ci/srht/freebsd_script | 50 +++++++++++++++++++++++++-----------------
2 files changed, 40 insertions(+), 37 deletions(-)
diff --git a/ci/azure/macos_script b/ci/azure/macos_script
index bf55dda51017..4f3c5697b086 100755
--- a/ci/azure/macos_script
+++ b/ci/azure/macos_script
@@ -34,13 +34,11 @@ git fetch --tags
mkdir build
cd build
cmake .. \
- -DCMAKE_INSTALL_PREFIX="$(pwd)/stage2" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
- -DZIG_STATIC=ON \
- -DZIG_OMIT_STAGE2=ON
+ -DZIG_STATIC=ON
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
@@ -49,13 +47,8 @@ unset CXX
make $JOBS install
-# Here we rebuild zig but this time using the Zig binary we just now produced to
-# build zig1.o rather than relying on the one built with stage0. See
-# https://github.com/ziglang/zig/issues/6830 for more details.
-cmake .. -DZIG_EXECUTABLE="$(pwd)/stage2/bin/zig"
-make $JOBS install
-
-stage2/bin/zig build -p release \
+stage2/bin/zig build \
+ --prefix stage3-release \
--search-prefix "$PREFIX" \
-Dstatic-llvm \
-Drelease \
@@ -63,21 +56,21 @@ stage2/bin/zig build -p release \
-Dtarget="$TARGET" \
-Denable-stage1
-release/bin/zig build test docs \
+stage3-release/bin/zig build test docs \
-Denable-macos-sdk \
-Dstatic-llvm \
--search-prefix "$PREFIX"
if [ "${BUILD_REASON}" != "PullRequest" ]; then
- mv ../LICENSE release/
- mv ../zig-cache/langref.html release/
- mv release/bin/zig release/
- rmdir release/bin
+ mv ../LICENSE stage3-release/
+ mv ../zig-cache/langref.html stage3-release/
+ mv stage3-release/bin/zig stage3-release/
+ rmdir stage3-release/bin
- VERSION=$(release/zig version)
+ VERSION=$(stage3-release/zig version)
DIRNAME="zig-macos-$ARCH-$VERSION"
TARBALL="$DIRNAME.tar.xz"
- mv release "$DIRNAME"
+ mv stage3-release "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
diff --git a/ci/srht/freebsd_script b/ci/srht/freebsd_script
index 02ab218756e5..dc22a02ed590 100755
--- a/ci/srht/freebsd_script
+++ b/ci/srht/freebsd_script
@@ -7,7 +7,9 @@ sudo pkg update -fq
sudo pkg install -y cmake py39-s3cmd wget curl jq samurai
ZIGDIR="$(pwd)"
-CACHE_BASENAME="zig+llvm+lld+clang-x86_64-freebsd-gnu-0.10.0-dev.3524+74673b7f6"
+TARGET="x86_64-freebsd-gnu"
+MCPU="baseline"
+CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.10.0-dev.3524+74673b7f6"
PREFIX="$HOME/$CACHE_BASENAME"
cd $HOME
@@ -30,38 +32,46 @@ export TERM=dumb
mkdir build
cd build
cmake .. \
- -DCMAKE_BUILD_TYPE=Release \
- -DCMAKE_PREFIX_PATH=$PREFIX \
- "-DCMAKE_INSTALL_PREFIX=$(pwd)/release" \
- -DZIG_STATIC=ON \
- -DZIG_TARGET_TRIPLE=x86_64-freebsd-gnu \
- -GNinja
+ -DCMAKE_BUILD_TYPE=Release \
+ -DCMAKE_PREFIX_PATH=$PREFIX \
+ -DZIG_TARGET_TRIPLE="$TARGET" \
+ -DZIG_TARGET_MCPU="$MCPU" \
+ -DZIG_STATIC=ON \
+ -GNinja
samu install
-# Here we rebuild zig but this time using the Zig binary we just now produced to
-# build zig1.o rather than relying on the one built with stage0. This makes it
-# a stage3 build rather than a stage2 build.
-cmake .. -DZIG_EXECUTABLE="$PREFIX/bin/zig"
-samu install
+# TODO: eliminate this workaround. Without this, zig does not end up passing
+# -isystem /usr/include when building libc++, resulting in #include
+# "file not found" errors.
+stage2/bin/zig libc >libc.txt
-# Here we skip some tests to save time.
-release/bin/zig build test docs \
+ZIG_LIBC=libc.txt stage2/bin/zig build \
+ --prefix stage3-release \
--search-prefix "$PREFIX" \
-Dstatic-llvm \
+ -Drelease \
+ -Dstrip \
+ -Dtarget="$TARGET" \
+ -Denable-stage1
+
+# Here we skip some tests to save time.
+stage3-release/bin/zig build test docs \
+ -Dstatic-llvm \
+ --search-prefix "$PREFIX" \
-Dskip-stage1 \
-Dskip-non-native
if [ -f ~/.s3cfg ]; then
- mv ../LICENSE release/
- mv ../zig-cache/langref.html release/
- mv release/bin/zig release/
- rmdir release/bin
+ mv ../LICENSE stage3-release/
+ mv ../zig-cache/langref.html stage3-release/
+ mv stage3-release/bin/zig stage3-release/
+ rmdir stage3-release/bin
GITBRANCH=$(basename $GITHUB_REF)
- VERSION=$(release/zig version)
+ VERSION=$(stage3-release/zig version)
DIRNAME="zig-freebsd-x86_64-$VERSION"
TARBALL="$DIRNAME.tar.xz"
- mv release "$DIRNAME"
+ mv stage3-release "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
From 28e95b324027e08be4f0dd48772970254299b976 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Thu, 11 Aug 2022 18:20:30 -0700
Subject: [PATCH 13/24] CI: drone: simplify
Instead of a switch in a bash file we just properly name
the pipeline steps.
Also use zig build to produce the release artifact.
---
ci/drone/drone.yml | 42 +++++++++++------------
ci/drone/linux_script_build | 14 ++++----
ci/drone/linux_script_test | 51 ----------------------------
ci/drone/test_linux_behavior | 8 +++++
ci/drone/test_linux_cases | 6 ++++
ci/drone/test_linux_misc | 11 ++++++
ci/drone/test_linux_std_Debug | 5 +++
ci/drone/test_linux_std_ReleaseFast | 5 +++
ci/drone/test_linux_std_ReleaseSafe | 5 +++
ci/drone/test_linux_std_ReleaseSmall | 5 +++
10 files changed, 74 insertions(+), 78 deletions(-)
delete mode 100755 ci/drone/linux_script_test
create mode 100755 ci/drone/test_linux_behavior
create mode 100755 ci/drone/test_linux_cases
create mode 100755 ci/drone/test_linux_misc
create mode 100755 ci/drone/test_linux_std_Debug
create mode 100755 ci/drone/test_linux_std_ReleaseFast
create mode 100755 ci/drone/test_linux_std_ReleaseSafe
create mode 100755 ci/drone/test_linux_std_ReleaseSmall
diff --git a/ci/drone/drone.yml b/ci/drone/drone.yml
index 363d168a2124..6a66913a5acd 100644
--- a/ci/drone/drone.yml
+++ b/ci/drone/drone.yml
@@ -13,65 +13,65 @@ steps:
commands:
- ./ci/drone/linux_script_build
-- name: test-1
+- name: behavior
depends_on:
- build
image: ziglang/static-base:llvm14-aarch64-3
commands:
- - ./ci/drone/linux_script_test 1
+ - ./ci/drone/test_linux_behavior
-- name: test-2
+- name: std_Debug
depends_on:
- build
image: ziglang/static-base:llvm14-aarch64-3
commands:
- - ./ci/drone/linux_script_test 2
+ - ./ci/drone/test_linux_std_Debug
-- name: test-3
+- name: std_ReleaseSafe
depends_on:
- build
image: ziglang/static-base:llvm14-aarch64-3
commands:
- - ./ci/drone/linux_script_test 3
+ - ./ci/drone/test_linux_std_ReleaseSafe
-- name: test-4
+- name: std_ReleaseFast
depends_on:
- build
image: ziglang/static-base:llvm14-aarch64-3
commands:
- - ./ci/drone/linux_script_test 4
+ - ./ci/drone/test_linux_std_ReleaseFast
-- name: test-5
+- name: std_ReleaseSmall
depends_on:
- build
image: ziglang/static-base:llvm14-aarch64-3
commands:
- - ./ci/drone/linux_script_test 5
+ - ./ci/drone/test_linux_std_ReleaseSmall
-- name: test-6
+- name: misc
depends_on:
- build
image: ziglang/static-base:llvm14-aarch64-3
commands:
- - ./ci/drone/linux_script_test 6
+ - ./ci/drone/test_linux_misc
-- name: test-7
+- name: cases
depends_on:
- build
image: ziglang/static-base:llvm14-aarch64-3
commands:
- - ./ci/drone/linux_script_test 7
+ - ./ci/drone/test_linux_cases
- name: finalize
depends_on:
- build
- - test-1
- - test-2
- - test-3
- - test-4
- - test-5
- - test-6
- - test-7
+ - behavior
+ - std_Debug
+ - std_ReleaseSafe
+ - std_ReleaseFast
+ - std_ReleaseSmall
+ - misc
+ - cases
image: ziglang/static-base:llvm14-aarch64-3
environment:
SRHT_OAUTH_TOKEN:
diff --git a/ci/drone/linux_script_build b/ci/drone/linux_script_build
index 58dad5f14c60..6fe9756b92b2 100755
--- a/ci/drone/linux_script_build
+++ b/ci/drone/linux_script_build
@@ -42,7 +42,6 @@ git fetch --tags
mkdir build
cd build
cmake .. \
- -DCMAKE_INSTALL_PREFIX="$DISTDIR" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_AR="$PREFIX/bin/ar" \
@@ -58,8 +57,11 @@ unset CC
unset CXX
samu install
-# Here we rebuild Zig but this time using the Zig binary we just now produced to
-# build zig1.o rather than relying on the one built with stage0. See
-# https://github.com/ziglang/zig/issues/6830 for more details.
-cmake .. -DZIG_EXECUTABLE="$DISTDIR/bin/zig"
-samu install
+stage2/bin/zig build \
+ --prefix "$DISTDIR" \
+ --search-prefix "$PREFIX" \
+ -Dstatic-llvm \
+ -Drelease \
+ -Dstrip \
+ -Dtarget="$TARGET" \
+ -Denable-stage1
diff --git a/ci/drone/linux_script_test b/ci/drone/linux_script_test
deleted file mode 100755
index b748745da9b5..000000000000
--- a/ci/drone/linux_script_test
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/bin/sh
-
-. ./ci/drone/linux_script_base
-
-BUILD_FLAGS="-Dskip-non-native"
-
-case "$1" in
- 1)
- ./build/zig build $BUILD_FLAGS test-behavior
- ./build/zig build $BUILD_FLAGS test-compiler-rt
- ./build/zig build $BUILD_FLAGS test-fmt
- ./build/zig build $BUILD_FLAGS docs
- ;;
- 2)
- # Debug
- ./build/zig build $BUILD_FLAGS test-std -Dskip-release-safe -Dskip-release-fast -Dskip-release-small
- ;;
- 3)
- # ReleaseSafe
- ./build/zig build $BUILD_FLAGS test-std -Dskip-debug -Dskip-release-fast -Dskip-release-small -Dskip-non-native -Dskip-single-threaded
- ;;
- 4)
- # ReleaseFast
- ./build/zig build $BUILD_FLAGS test-std -Dskip-debug -Dskip-release-safe -Dskip-release-small -Dskip-non-native -Dskip-single-threaded
- ;;
- 5)
- # ReleaseSmall
- ./build/zig build $BUILD_FLAGS test-std -Dskip-debug -Dskip-release-safe -Dskip-release-fast
- ;;
- 6)
- ./build/zig build $BUILD_FLAGS test-universal-libc
- ./build/zig build $BUILD_FLAGS test-compare-output
- ./build/zig build $BUILD_FLAGS test-standalone -Dskip-release-safe
- ./build/zig build $BUILD_FLAGS test-stack-traces
- ./build/zig build $BUILD_FLAGS test-cli
- ./build/zig build $BUILD_FLAGS test-asm-link
- ./build/zig build $BUILD_FLAGS test-translate-c
- ;;
- 7)
- ./build/zig build $BUILD_FLAGS # test building self-hosted without LLVM
- ./build/zig build $BUILD_FLAGS test-cases
- ;;
- '')
- echo "error: expecting test group argument"
- exit 1
- ;;
- *)
- echo "error: unknown test group: $1"
- exit 1
- ;;
-esac
diff --git a/ci/drone/test_linux_behavior b/ci/drone/test_linux_behavior
new file mode 100755
index 000000000000..a06347c16984
--- /dev/null
+++ b/ci/drone/test_linux_behavior
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+. ./ci/drone/linux_script_base
+
+./build/zig build test-behavior -Dskip-non-native
+./build/zig build test-compiler-rt -Dskip-non-native
+./build/zig build test-fmt
+./build/zig build docs
diff --git a/ci/drone/test_linux_cases b/ci/drone/test_linux_cases
new file mode 100755
index 000000000000..702bb45f9148
--- /dev/null
+++ b/ci/drone/test_linux_cases
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+. ./ci/drone/linux_script_base
+
+./build/zig build -Dskip-non-native # test building self-hosted without LLVM
+./build/zig build -Dskip-non-native test-cases
diff --git a/ci/drone/test_linux_misc b/ci/drone/test_linux_misc
new file mode 100755
index 000000000000..6a19ee41f37d
--- /dev/null
+++ b/ci/drone/test_linux_misc
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+. ./ci/drone/linux_script_base
+
+./build/zig build test-universal-libc -Dskip-non-native
+./build/zig build test-compare-output -Dskip-non-native
+./build/zig build test-standalone -Dskip-non-native -Dskip-release-safe
+./build/zig build test-stack-traces -Dskip-non-native
+./build/zig build test-cli -Dskip-non-native
+./build/zig build test-asm-link -Dskip-non-native
+./build/zig build test-translate-c -Dskip-non-native
diff --git a/ci/drone/test_linux_std_Debug b/ci/drone/test_linux_std_Debug
new file mode 100755
index 000000000000..41fb34f8bc09
--- /dev/null
+++ b/ci/drone/test_linux_std_Debug
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. ./ci/drone/linux_script_base
+
+./build/zig build test-std -Dskip-release-safe -Dskip-release-fast -Dskip-release-small -Dskip-non-native
diff --git a/ci/drone/test_linux_std_ReleaseFast b/ci/drone/test_linux_std_ReleaseFast
new file mode 100755
index 000000000000..156406ac35a9
--- /dev/null
+++ b/ci/drone/test_linux_std_ReleaseFast
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. ./ci/drone/linux_script_base
+
+./build/zig build test-std -Dskip-debug -Dskip-release-safe -Dskip-release-small -Dskip-non-native -Dskip-single-threaded
diff --git a/ci/drone/test_linux_std_ReleaseSafe b/ci/drone/test_linux_std_ReleaseSafe
new file mode 100755
index 000000000000..f972d75f0bc7
--- /dev/null
+++ b/ci/drone/test_linux_std_ReleaseSafe
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. ./ci/drone/linux_script_base
+
+./build/zig build test-std -Dskip-debug -Dskip-release-fast -Dskip-release-small -Dskip-non-native -Dskip-single-threaded
diff --git a/ci/drone/test_linux_std_ReleaseSmall b/ci/drone/test_linux_std_ReleaseSmall
new file mode 100755
index 000000000000..9a5975ffe571
--- /dev/null
+++ b/ci/drone/test_linux_std_ReleaseSmall
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. ./ci/drone/linux_script_base
+
+./build/zig build test-std -Dskip-debug -Dskip-release-safe -Dskip-release-fast -Dskip-non-native
From 445b33cfc05771d35ca243cde15d0b5594129ae3 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Wed, 17 Aug 2022 22:24:07 -0700
Subject: [PATCH 14/24] fix std.os.windows.PathSpace.span
it was returning a pointer to a parameter.
---
lib/std/os/windows.zig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig
index c79ccb511375..b0a0f6d40747 100644
--- a/lib/std/os/windows.zig
+++ b/lib/std/os/windows.zig
@@ -1802,7 +1802,7 @@ pub const PathSpace = struct {
data: [PATH_MAX_WIDE:0]u16,
len: usize,
- pub fn span(self: PathSpace) [:0]const u16 {
+ pub fn span(self: *const PathSpace) [:0]const u16 {
return self.data[0..self.len :0];
}
};
From 5be2e8f941f78a5d1fda3ab4a2b4aa9487f1b519 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Wed, 17 Aug 2022 15:38:55 -0700
Subject: [PATCH 15/24] CI: update windows tarball
This includes a few recent bug fixes which may solve the Windows CI
failure.
---
ci/azure/build.zig | 974 -----------------------------------------
ci/azure/pipelines.yml | 8 +-
2 files changed, 4 insertions(+), 978 deletions(-)
delete mode 100644 ci/azure/build.zig
diff --git a/ci/azure/build.zig b/ci/azure/build.zig
deleted file mode 100644
index 00f1cce2bd95..000000000000
--- a/ci/azure/build.zig
+++ /dev/null
@@ -1,974 +0,0 @@
-const std = @import("std");
-const builtin = std.builtin;
-const Builder = std.build.Builder;
-const BufMap = std.BufMap;
-const mem = std.mem;
-const ArrayList = std.ArrayList;
-const io = std.io;
-const fs = std.fs;
-const InstallDirectoryOptions = std.build.InstallDirectoryOptions;
-const assert = std.debug.assert;
-
-const zig_version = std.builtin.Version{ .major = 0, .minor = 10, .patch = 0 };
-
-pub fn build(b: *Builder) !void {
- b.setPreferredReleaseMode(.ReleaseFast);
- const mode = b.standardReleaseOptions();
- const target = b.standardTargetOptions(.{});
- const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode");
- 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 docgen_exe = b.addExecutable("docgen", "doc/docgen.zig");
- docgen_exe.single_threaded = single_threaded;
-
- const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe);
- const langref_out_path = fs.path.join(
- b.allocator,
- &[_][]const u8{ b.cache_root, "langref.html" },
- ) catch unreachable;
- const docgen_cmd = docgen_exe.run();
- docgen_cmd.addArgs(&[_][]const u8{
- rel_zig_exe,
- "doc" ++ fs.path.sep_str ++ "langref.html.in",
- langref_out_path,
- });
- docgen_cmd.step.dependOn(&docgen_exe.step);
-
- const docs_step = b.step("docs", "Build documentation");
- docs_step.dependOn(&docgen_cmd.step);
-
- const have_stage1 = b.option(bool, "enable-stage1", "Include the stage1 compiler behind a feature flag") orelse false;
- const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false;
- const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (have_stage1 or static_llvm);
- const llvm_has_m68k = b.option(
- bool,
- "llvm-has-m68k",
- "Whether LLVM has the experimental target m68k enabled",
- ) orelse false;
- const llvm_has_csky = b.option(
- bool,
- "llvm-has-csky",
- "Whether LLVM has the experimental target csky enabled",
- ) orelse false;
- const llvm_has_arc = b.option(
- bool,
- "llvm-has-arc",
- "Whether LLVM has the experimental target arc enabled",
- ) orelse false;
- const config_h_path_option = b.option([]const u8, "config_h", "Path to the generated config.h");
-
- b.installDirectory(InstallDirectoryOptions{
- .source_dir = "lib",
- .install_dir = .lib,
- .install_subdir = "zig",
- .exclude_extensions = &[_][]const u8{
- // exclude files from lib/std/compress/
- ".gz",
- ".z.0",
- ".z.9",
- "rfc1951.txt",
- "rfc1952.txt",
- // exclude files from lib/std/compress/deflate/testdata
- ".expect",
- ".expect-noinput",
- ".golden",
- ".input",
- "compress-e.txt",
- "compress-gettysburg.txt",
- "compress-pi.txt",
- "rfc1951.txt",
- // exclude files from lib/std/tz/
- ".tzif",
- // others
- "README.md",
- },
- .blank_extensions = &[_][]const u8{
- "test.zig",
- },
- });
-
- const tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source");
- const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse false;
- const tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided") orelse false;
- const force_gpa = b.option(bool, "force-gpa", "Force the compiler to use GeneralPurposeAllocator") orelse false;
- const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse enable_llvm;
- const strip = b.option(bool, "strip", "Omit debug information") orelse false;
- const value_tracing = b.option(bool, "value-tracing", "Enable extra state tracking to help troubleshoot bugs in the compiler (using the std.debug.Trace API)") orelse false;
-
- const mem_leak_frames: u32 = b.option(u32, "mem-leak-frames", "How many stack frames to print when a memory leak occurs. Tests get 2x this amount.") orelse blk: {
- if (strip) break :blk @as(u32, 0);
- if (mode != .Debug) break :blk 0;
- break :blk 4;
- };
-
- const main_file: ?[]const u8 = if (have_stage1) null else "src/main.zig";
-
- const exe = b.addExecutable("zig", main_file);
- exe.strip = strip;
- exe.install();
- exe.setBuildMode(mode);
- exe.setTarget(target);
-
- 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;
- }
-
- const exe_options = b.addOptions();
- exe.addOptions("build_options", exe_options);
-
- exe_options.addOption(u32, "mem_leak_frames", mem_leak_frames);
- exe_options.addOption(bool, "skip_non_native", false);
- exe_options.addOption(bool, "have_llvm", enable_llvm);
- exe_options.addOption(bool, "llvm_has_m68k", llvm_has_m68k);
- exe_options.addOption(bool, "llvm_has_csky", llvm_has_csky);
- exe_options.addOption(bool, "llvm_has_arc", llvm_has_arc);
- exe_options.addOption(bool, "force_gpa", force_gpa);
-
- if (link_libc) {
- exe.linkLibC();
- }
-
- const is_debug = mode == .Debug;
- const enable_logging = b.option(bool, "log", "Enable debug logging with --debug-log") orelse is_debug;
- const enable_link_snapshots = b.option(bool, "link-snapshot", "Whether to enable linker state snapshots") orelse false;
-
- const opt_version_string = b.option([]const u8, "version-string", "Override Zig version string. Default is to find out with git.");
- const version = if (opt_version_string) |version| version else v: {
- const version_string = b.fmt("{d}.{d}.{d}", .{ zig_version.major, zig_version.minor, zig_version.patch });
-
- var code: u8 = undefined;
- const git_describe_untrimmed = b.execAllowFail(&[_][]const u8{
- "git", "-C", b.build_root, "describe", "--match", "*.*.*", "--tags",
- }, &code, .Ignore) catch {
- break :v version_string;
- };
- const git_describe = mem.trim(u8, git_describe_untrimmed, " \n\r");
-
- switch (mem.count(u8, git_describe, "-")) {
- 0 => {
- // Tagged release version (e.g. 0.9.0).
- if (!mem.eql(u8, git_describe, version_string)) {
- std.debug.print("Zig version '{s}' does not match Git tag '{s}'\n", .{ version_string, git_describe });
- std.process.exit(1);
- }
- break :v version_string;
- },
- 2 => {
- // Untagged development build (e.g. 0.9.0-dev.2025+ecf0050a9).
- var it = mem.split(u8, git_describe, "-");
- const tagged_ancestor = it.next() orelse unreachable;
- const commit_height = it.next() orelse unreachable;
- const commit_id = it.next() orelse unreachable;
-
- const ancestor_ver = try std.builtin.Version.parse(tagged_ancestor);
- if (zig_version.order(ancestor_ver) != .gt) {
- std.debug.print("Zig version '{}' must be greater than tagged ancestor '{}'\n", .{ zig_version, ancestor_ver });
- std.process.exit(1);
- }
-
- // Check that the commit hash is prefixed with a 'g' (a Git convention).
- if (commit_id.len < 1 or commit_id[0] != 'g') {
- std.debug.print("Unexpected `git describe` output: {s}\n", .{git_describe});
- break :v version_string;
- }
-
- // The version is reformatted in accordance with the https://semver.org specification.
- break :v b.fmt("{s}-dev.{s}+{s}", .{ version_string, commit_height, commit_id[1..] });
- },
- else => {
- std.debug.print("Unexpected `git describe` output: {s}\n", .{git_describe});
- break :v version_string;
- },
- }
- };
- exe_options.addOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version));
-
- if (enable_llvm) {
- const cmake_cfg = if (static_llvm) null else findAndParseConfigH(b, config_h_path_option);
-
- if (have_stage1) {
- const softfloat = b.addStaticLibrary("softfloat", null);
- softfloat.setBuildMode(.ReleaseFast);
- softfloat.setTarget(target);
- softfloat.addIncludeDir("deps/SoftFloat-3e-prebuilt");
- softfloat.addIncludeDir("deps/SoftFloat-3e/source/8086");
- softfloat.addIncludeDir("deps/SoftFloat-3e/source/include");
- softfloat.addCSourceFiles(&softfloat_sources, &[_][]const u8{ "-std=c99", "-O3" });
- softfloat.single_threaded = single_threaded;
-
- const zig0 = b.addExecutable("zig0", null);
- zig0.addCSourceFiles(&.{"src/stage1/zig0.cpp"}, &exe_cflags);
- zig0.addIncludeDir("zig-cache/tmp"); // for config.h
- zig0.defineCMacro("ZIG_VERSION_MAJOR", b.fmt("{d}", .{zig_version.major}));
- zig0.defineCMacro("ZIG_VERSION_MINOR", b.fmt("{d}", .{zig_version.minor}));
- zig0.defineCMacro("ZIG_VERSION_PATCH", b.fmt("{d}", .{zig_version.patch}));
- zig0.defineCMacro("ZIG_VERSION_STRING", b.fmt("\"{s}\"", .{version}));
-
- for ([_]*std.build.LibExeObjStep{ zig0, exe }) |artifact| {
- artifact.addIncludeDir("src");
- artifact.addIncludeDir("deps/SoftFloat-3e/source/include");
- artifact.addIncludeDir("deps/SoftFloat-3e-prebuilt");
-
- artifact.defineCMacro("ZIG_LINK_MODE", "Static");
-
- artifact.addCSourceFiles(&stage1_sources, &exe_cflags);
- artifact.addCSourceFiles(&optimized_c_sources, &[_][]const u8{ "-std=c99", "-O3" });
-
- artifact.linkLibrary(softfloat);
- artifact.linkLibCpp();
- }
-
- try addStaticLlvmOptionsToExe(zig0);
-
- const zig1_obj_ext = target.getObjectFormat().fileExt(target.getCpuArch());
- const zig1_obj_path = b.pathJoin(&.{ "zig-cache", "tmp", b.fmt("zig1{s}", .{zig1_obj_ext}) });
- const zig1_compiler_rt_path = b.pathJoin(&.{ b.pathFromRoot("lib"), "std", "special", "compiler_rt.zig" });
-
- const zig1_obj = zig0.run();
- zig1_obj.addArgs(&.{
- "src/stage1.zig",
- "-target",
- try target.zigTriple(b.allocator),
- "-mcpu=baseline",
- "--name",
- "zig1",
- "--zig-lib-dir",
- b.pathFromRoot("lib"),
- b.fmt("-femit-bin={s}", .{b.pathFromRoot(zig1_obj_path)}),
- "-fcompiler-rt",
- "-lc",
- });
- {
- zig1_obj.addArgs(&.{ "--pkg-begin", "build_options" });
- zig1_obj.addFileSourceArg(exe_options.getSource());
- zig1_obj.addArgs(&.{ "--pkg-end", "--pkg-begin", "compiler_rt", zig1_compiler_rt_path, "--pkg-end" });
- }
- switch (mode) {
- .Debug => {},
- .ReleaseFast => {
- zig1_obj.addArg("-OReleaseFast");
- zig1_obj.addArg("--strip");
- },
- .ReleaseSafe => {
- zig1_obj.addArg("-OReleaseSafe");
- zig1_obj.addArg("--strip");
- },
- .ReleaseSmall => {
- zig1_obj.addArg("-OReleaseSmall");
- zig1_obj.addArg("--strip");
- },
- }
- if (single_threaded orelse false) {
- zig1_obj.addArg("-fsingle-threaded");
- }
-
- exe.step.dependOn(&zig1_obj.step);
- exe.addObjectFile(zig1_obj_path);
-
- // 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");
- }
- if (cmake_cfg) |cfg| {
- // Inside this code path, we have to coordinate with system packaged LLVM, Clang, and LLD.
- // That means we also have to rely on stage1 compiled c++ files. We parse config.h to find
- // the information passed on to us from cmake.
- if (cfg.cmake_prefix_path.len > 0) {
- b.addSearchPrefix(cfg.cmake_prefix_path);
- }
-
- try addCmakeCfgOptionsToExe(b, cfg, exe, use_zig_libcxx);
- } else {
- // Here we are -Denable-llvm but no cmake integration.
- try addStaticLlvmOptionsToExe(exe);
- }
- }
-
- const semver = try std.SemanticVersion.parse(version);
- exe_options.addOption(std.SemanticVersion, "semver", semver);
-
- exe_options.addOption(bool, "enable_logging", enable_logging);
- exe_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots);
- exe_options.addOption(bool, "enable_tracy", tracy != null);
- exe_options.addOption(bool, "enable_tracy_callstack", tracy_callstack);
- exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
- exe_options.addOption(bool, "value_tracing", value_tracing);
- exe_options.addOption(bool, "have_stage1", have_stage1);
- if (tracy) |tracy_path| {
- const client_cpp = fs.path.join(
- b.allocator,
- &[_][]const u8{ tracy_path, "TracyClient.cpp" },
- ) catch unreachable;
-
- // On mingw, we need to opt into windows 7+ to get some features required by tracy.
- const tracy_c_flags: []const []const u8 = if (target.isWindows() and target.getAbi() == .gnu)
- &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" }
- else
- &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
-
- exe.addIncludeDir(tracy_path);
- exe.addCSourceFile(client_cpp, tracy_c_flags);
- if (!enable_llvm) {
- exe.linkSystemLibraryName("c++");
- }
- exe.linkLibC();
-
- if (target.isWindows()) {
- exe.linkSystemLibrary("dbghelp");
- exe.linkSystemLibrary("ws2_32");
- }
- }
-}
-
-const exe_cflags = [_][]const u8{
- "-std=c++14",
- "-D__STDC_CONSTANT_MACROS",
- "-D__STDC_FORMAT_MACROS",
- "-D__STDC_LIMIT_MACROS",
- "-D_GNU_SOURCE",
- "-fvisibility-inlines-hidden",
- "-fno-exceptions",
- "-fno-rtti",
- "-Werror=type-limits",
- "-Wno-missing-braces",
- "-Wno-comment",
-};
-
-fn addCmakeCfgOptionsToExe(
- b: *Builder,
- cfg: CMakeConfig,
- exe: *std.build.LibExeObjStep,
- use_zig_libcxx: bool,
-) !void {
- exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
- cfg.cmake_binary_dir,
- "zigcpp",
- b.fmt("{s}{s}{s}", .{ exe.target.libPrefix(), "zigcpp", exe.target.staticLibSuffix() }),
- }) catch unreachable);
- assert(cfg.lld_include_dir.len != 0);
- exe.addIncludeDir(cfg.lld_include_dir);
- addCMakeLibraryList(exe, cfg.clang_libraries);
- addCMakeLibraryList(exe, cfg.lld_libraries);
- addCMakeLibraryList(exe, cfg.llvm_libraries);
-
- if (use_zig_libcxx) {
- exe.linkLibCpp();
- } else {
- 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.
- if (exe.target.getOsTag() == .linux) {
- // First we try to static link against gcc libstdc++. If that doesn't work,
- // we fall back to -lc++ and cross our fingers.
- addCxxKnownPath(b, cfg, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) {
- error.RequiredLibraryNotFound => {
- exe.linkSystemLibrary("c++");
- },
- else => |e| return e,
- };
- exe.linkSystemLibrary("unwind");
- } else if (exe.target.isFreeBSD()) {
- try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
- exe.linkSystemLibrary("pthread");
- } else if (exe.target.getOsTag() == .openbsd) {
- try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
- try addCxxKnownPath(b, cfg, exe, "libc++abi.a", null, need_cpp_includes);
- } else if (exe.target.isDarwin()) {
- exe.linkSystemLibrary("c++");
- }
- }
-
- if (cfg.dia_guids_lib.len != 0) {
- exe.addObjectFile(cfg.dia_guids_lib);
- }
-}
-
-fn addStaticLlvmOptionsToExe(
- exe: *std.build.LibExeObjStep,
-) !void {
- // Adds the Zig C++ sources which both stage1 and stage2 need.
- //
- // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling
- // in a dependency on llvm::cfg::Update::dump() which is
- // unavailable when LLVM is compiled in Release mode.
- const zig_cpp_cflags = exe_cflags ++ [_][]const u8{"-DNDEBUG=1"};
- exe.addCSourceFiles(&zig_cpp_sources, &zig_cpp_cflags);
-
- for (clang_libs) |lib_name| {
- exe.linkSystemLibrary(lib_name);
- }
-
- for (lld_libs) |lib_name| {
- exe.linkSystemLibrary(lib_name);
- }
-
- for (llvm_libs) |lib_name| {
- exe.linkSystemLibrary(lib_name);
- }
-
- exe.linkSystemLibrary("z");
-
- // This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries.
- exe.linkSystemLibrary("c++");
-
- if (exe.target.getOs().tag == .windows) {
- exe.linkSystemLibrary("version");
- exe.linkSystemLibrary("uuid");
- exe.linkSystemLibrary("ole32");
- }
-}
-
-fn addCxxKnownPath(
- b: *Builder,
- ctx: CMakeConfig,
- exe: *std.build.LibExeObjStep,
- objname: []const u8,
- errtxt: ?[]const u8,
- need_cpp_includes: bool,
-) !void {
- const path_padded = try b.exec(&[_][]const u8{
- ctx.cxx_compiler,
- b.fmt("-print-file-name={s}", .{objname}),
- });
- const path_unpadded = mem.tokenize(u8, path_padded, "\r\n").next().?;
- if (mem.eql(u8, path_unpadded, objname)) {
- if (errtxt) |msg| {
- std.debug.print("{s}", .{msg});
- } else {
- std.debug.print("Unable to determine path to {s}\n", .{objname});
- }
- return error.RequiredLibraryNotFound;
- }
- exe.addObjectFile(path_unpadded);
-
- // TODO a way to integrate with system c++ include files here
- // cc -E -Wp,-v -xc++ /dev/null
- 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/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");
- }
-}
-
-fn addCMakeLibraryList(exe: *std.build.LibExeObjStep, list: []const u8) void {
- var it = mem.tokenize(u8, list, ";");
- while (it.next()) |lib| {
- if (mem.startsWith(u8, lib, "-l")) {
- exe.linkSystemLibrary(lib["-l".len..]);
- } else {
- exe.addObjectFile(lib);
- }
- }
-}
-
-const CMakeConfig = struct {
- cmake_binary_dir: []const u8,
- cmake_prefix_path: []const u8,
- cxx_compiler: []const u8,
- lld_include_dir: []const u8,
- lld_libraries: []const u8,
- clang_libraries: []const u8,
- llvm_libraries: []const u8,
- dia_guids_lib: []const u8,
-};
-
-const max_config_h_bytes = 1 * 1024 * 1024;
-
-fn findAndParseConfigH(b: *Builder, config_h_path_option: ?[]const u8) ?CMakeConfig {
- const config_h_text: []const u8 = if (config_h_path_option) |config_h_path| blk: {
- break :blk fs.cwd().readFileAlloc(b.allocator, config_h_path, max_config_h_bytes) catch unreachable;
- } else blk: {
- // TODO this should stop looking for config.h once it detects we hit the
- // zig source root directory.
- var check_dir = fs.path.dirname(b.zig_exe).?;
- while (true) {
- var dir = fs.cwd().openDir(check_dir, .{}) catch unreachable;
- defer dir.close();
-
- break :blk dir.readFileAlloc(b.allocator, "config.h", max_config_h_bytes) catch |err| switch (err) {
- error.FileNotFound => {
- const new_check_dir = fs.path.dirname(check_dir);
- if (new_check_dir == null or mem.eql(u8, new_check_dir.?, check_dir)) {
- return null;
- }
- check_dir = new_check_dir.?;
- continue;
- },
- else => unreachable,
- };
- } else unreachable; // TODO should not need `else unreachable`.
- };
-
- var ctx: CMakeConfig = .{
- .cmake_binary_dir = undefined,
- .cmake_prefix_path = undefined,
- .cxx_compiler = undefined,
- .lld_include_dir = undefined,
- .lld_libraries = undefined,
- .clang_libraries = undefined,
- .llvm_libraries = undefined,
- .dia_guids_lib = undefined,
- };
-
- const mappings = [_]struct { prefix: []const u8, field: []const u8 }{
- .{
- .prefix = "#define ZIG_CMAKE_BINARY_DIR ",
- .field = "cmake_binary_dir",
- },
- .{
- .prefix = "#define ZIG_CMAKE_PREFIX_PATH ",
- .field = "cmake_prefix_path",
- },
- .{
- .prefix = "#define ZIG_CXX_COMPILER ",
- .field = "cxx_compiler",
- },
- .{
- .prefix = "#define ZIG_LLD_INCLUDE_PATH ",
- .field = "lld_include_dir",
- },
- .{
- .prefix = "#define ZIG_LLD_LIBRARIES ",
- .field = "lld_libraries",
- },
- .{
- .prefix = "#define ZIG_CLANG_LIBRARIES ",
- .field = "clang_libraries",
- },
- .{
- .prefix = "#define ZIG_LLVM_LIBRARIES ",
- .field = "llvm_libraries",
- },
- .{
- .prefix = "#define ZIG_DIA_GUIDS_LIB ",
- .field = "dia_guids_lib",
- },
- };
-
- var lines_it = mem.tokenize(u8, config_h_text, "\r\n");
- while (lines_it.next()) |line| {
- inline for (mappings) |mapping| {
- if (mem.startsWith(u8, line, mapping.prefix)) {
- var it = mem.split(u8, line, "\"");
- _ = it.next().?; // skip the stuff before the quote
- const quoted = it.next().?; // the stuff inside the quote
- @field(ctx, mapping.field) = toNativePathSep(b, quoted);
- }
- }
- }
- return ctx;
-}
-
-fn toNativePathSep(b: *Builder, s: []const u8) []u8 {
- const duplicated = b.allocator.dupe(u8, s) catch unreachable;
- for (duplicated) |*byte| switch (byte.*) {
- '/' => byte.* = fs.path.sep,
- else => {},
- };
- return duplicated;
-}
-
-const softfloat_sources = [_][]const u8{
- "deps/SoftFloat-3e/source/8086/f128M_isSignalingNaN.c",
- "deps/SoftFloat-3e/source/8086/extF80M_isSignalingNaN.c",
- "deps/SoftFloat-3e/source/8086/s_commonNaNToF128M.c",
- "deps/SoftFloat-3e/source/8086/s_commonNaNToExtF80M.c",
- "deps/SoftFloat-3e/source/8086/s_commonNaNToF16UI.c",
- "deps/SoftFloat-3e/source/8086/s_commonNaNToF32UI.c",
- "deps/SoftFloat-3e/source/8086/s_commonNaNToF64UI.c",
- "deps/SoftFloat-3e/source/8086/s_f128MToCommonNaN.c",
- "deps/SoftFloat-3e/source/8086/s_extF80MToCommonNaN.c",
- "deps/SoftFloat-3e/source/8086/s_f16UIToCommonNaN.c",
- "deps/SoftFloat-3e/source/8086/s_f32UIToCommonNaN.c",
- "deps/SoftFloat-3e/source/8086/s_f64UIToCommonNaN.c",
- "deps/SoftFloat-3e/source/8086/s_propagateNaNF128M.c",
- "deps/SoftFloat-3e/source/8086/s_propagateNaNExtF80M.c",
- "deps/SoftFloat-3e/source/8086/s_propagateNaNF16UI.c",
- "deps/SoftFloat-3e/source/8086/softfloat_raiseFlags.c",
- "deps/SoftFloat-3e/source/f128M_add.c",
- "deps/SoftFloat-3e/source/f128M_div.c",
- "deps/SoftFloat-3e/source/f128M_eq.c",
- "deps/SoftFloat-3e/source/f128M_eq_signaling.c",
- "deps/SoftFloat-3e/source/f128M_le.c",
- "deps/SoftFloat-3e/source/f128M_le_quiet.c",
- "deps/SoftFloat-3e/source/f128M_lt.c",
- "deps/SoftFloat-3e/source/f128M_lt_quiet.c",
- "deps/SoftFloat-3e/source/f128M_mul.c",
- "deps/SoftFloat-3e/source/f128M_mulAdd.c",
- "deps/SoftFloat-3e/source/f128M_rem.c",
- "deps/SoftFloat-3e/source/f128M_roundToInt.c",
- "deps/SoftFloat-3e/source/f128M_sqrt.c",
- "deps/SoftFloat-3e/source/f128M_sub.c",
- "deps/SoftFloat-3e/source/f128M_to_f16.c",
- "deps/SoftFloat-3e/source/f128M_to_f32.c",
- "deps/SoftFloat-3e/source/f128M_to_f64.c",
- "deps/SoftFloat-3e/source/f128M_to_extF80M.c",
- "deps/SoftFloat-3e/source/f128M_to_i32.c",
- "deps/SoftFloat-3e/source/f128M_to_i32_r_minMag.c",
- "deps/SoftFloat-3e/source/f128M_to_i64.c",
- "deps/SoftFloat-3e/source/f128M_to_i64_r_minMag.c",
- "deps/SoftFloat-3e/source/f128M_to_ui32.c",
- "deps/SoftFloat-3e/source/f128M_to_ui32_r_minMag.c",
- "deps/SoftFloat-3e/source/f128M_to_ui64.c",
- "deps/SoftFloat-3e/source/f128M_to_ui64_r_minMag.c",
- "deps/SoftFloat-3e/source/extF80M_add.c",
- "deps/SoftFloat-3e/source/extF80M_div.c",
- "deps/SoftFloat-3e/source/extF80M_eq.c",
- "deps/SoftFloat-3e/source/extF80M_le.c",
- "deps/SoftFloat-3e/source/extF80M_lt.c",
- "deps/SoftFloat-3e/source/extF80M_mul.c",
- "deps/SoftFloat-3e/source/extF80M_rem.c",
- "deps/SoftFloat-3e/source/extF80M_roundToInt.c",
- "deps/SoftFloat-3e/source/extF80M_sqrt.c",
- "deps/SoftFloat-3e/source/extF80M_sub.c",
- "deps/SoftFloat-3e/source/extF80M_to_f16.c",
- "deps/SoftFloat-3e/source/extF80M_to_f32.c",
- "deps/SoftFloat-3e/source/extF80M_to_f64.c",
- "deps/SoftFloat-3e/source/extF80M_to_f128M.c",
- "deps/SoftFloat-3e/source/f16_add.c",
- "deps/SoftFloat-3e/source/f16_div.c",
- "deps/SoftFloat-3e/source/f16_eq.c",
- "deps/SoftFloat-3e/source/f16_isSignalingNaN.c",
- "deps/SoftFloat-3e/source/f16_lt.c",
- "deps/SoftFloat-3e/source/f16_mul.c",
- "deps/SoftFloat-3e/source/f16_mulAdd.c",
- "deps/SoftFloat-3e/source/f16_rem.c",
- "deps/SoftFloat-3e/source/f16_roundToInt.c",
- "deps/SoftFloat-3e/source/f16_sqrt.c",
- "deps/SoftFloat-3e/source/f16_sub.c",
- "deps/SoftFloat-3e/source/f16_to_extF80M.c",
- "deps/SoftFloat-3e/source/f16_to_f128M.c",
- "deps/SoftFloat-3e/source/f16_to_f64.c",
- "deps/SoftFloat-3e/source/f32_to_extF80M.c",
- "deps/SoftFloat-3e/source/f32_to_f128M.c",
- "deps/SoftFloat-3e/source/f64_to_extF80M.c",
- "deps/SoftFloat-3e/source/f64_to_f128M.c",
- "deps/SoftFloat-3e/source/f64_to_f16.c",
- "deps/SoftFloat-3e/source/i32_to_f128M.c",
- "deps/SoftFloat-3e/source/s_add256M.c",
- "deps/SoftFloat-3e/source/s_addCarryM.c",
- "deps/SoftFloat-3e/source/s_addComplCarryM.c",
- "deps/SoftFloat-3e/source/s_addF128M.c",
- "deps/SoftFloat-3e/source/s_addExtF80M.c",
- "deps/SoftFloat-3e/source/s_addM.c",
- "deps/SoftFloat-3e/source/s_addMagsF16.c",
- "deps/SoftFloat-3e/source/s_addMagsF32.c",
- "deps/SoftFloat-3e/source/s_addMagsF64.c",
- "deps/SoftFloat-3e/source/s_approxRecip32_1.c",
- "deps/SoftFloat-3e/source/s_approxRecipSqrt32_1.c",
- "deps/SoftFloat-3e/source/s_approxRecipSqrt_1Ks.c",
- "deps/SoftFloat-3e/source/s_approxRecip_1Ks.c",
- "deps/SoftFloat-3e/source/s_compare128M.c",
- "deps/SoftFloat-3e/source/s_compare96M.c",
- "deps/SoftFloat-3e/source/s_compareNonnormExtF80M.c",
- "deps/SoftFloat-3e/source/s_countLeadingZeros16.c",
- "deps/SoftFloat-3e/source/s_countLeadingZeros32.c",
- "deps/SoftFloat-3e/source/s_countLeadingZeros64.c",
- "deps/SoftFloat-3e/source/s_countLeadingZeros8.c",
- "deps/SoftFloat-3e/source/s_eq128.c",
- "deps/SoftFloat-3e/source/s_invalidF128M.c",
- "deps/SoftFloat-3e/source/s_invalidExtF80M.c",
- "deps/SoftFloat-3e/source/s_isNaNF128M.c",
- "deps/SoftFloat-3e/source/s_le128.c",
- "deps/SoftFloat-3e/source/s_lt128.c",
- "deps/SoftFloat-3e/source/s_mul128MTo256M.c",
- "deps/SoftFloat-3e/source/s_mul64To128M.c",
- "deps/SoftFloat-3e/source/s_mulAddF128M.c",
- "deps/SoftFloat-3e/source/s_mulAddF16.c",
- "deps/SoftFloat-3e/source/s_mulAddF32.c",
- "deps/SoftFloat-3e/source/s_mulAddF64.c",
- "deps/SoftFloat-3e/source/s_negXM.c",
- "deps/SoftFloat-3e/source/s_normExtF80SigM.c",
- "deps/SoftFloat-3e/source/s_normRoundPackMToF128M.c",
- "deps/SoftFloat-3e/source/s_normRoundPackMToExtF80M.c",
- "deps/SoftFloat-3e/source/s_normRoundPackToF16.c",
- "deps/SoftFloat-3e/source/s_normRoundPackToF32.c",
- "deps/SoftFloat-3e/source/s_normRoundPackToF64.c",
- "deps/SoftFloat-3e/source/s_normSubnormalF128SigM.c",
- "deps/SoftFloat-3e/source/s_normSubnormalF16Sig.c",
- "deps/SoftFloat-3e/source/s_normSubnormalF32Sig.c",
- "deps/SoftFloat-3e/source/s_normSubnormalF64Sig.c",
- "deps/SoftFloat-3e/source/s_remStepMBy32.c",
- "deps/SoftFloat-3e/source/s_roundMToI64.c",
- "deps/SoftFloat-3e/source/s_roundMToUI64.c",
- "deps/SoftFloat-3e/source/s_roundPackMToExtF80M.c",
- "deps/SoftFloat-3e/source/s_roundPackMToF128M.c",
- "deps/SoftFloat-3e/source/s_roundPackToF16.c",
- "deps/SoftFloat-3e/source/s_roundPackToF32.c",
- "deps/SoftFloat-3e/source/s_roundPackToF64.c",
- "deps/SoftFloat-3e/source/s_roundToI32.c",
- "deps/SoftFloat-3e/source/s_roundToI64.c",
- "deps/SoftFloat-3e/source/s_roundToUI32.c",
- "deps/SoftFloat-3e/source/s_roundToUI64.c",
- "deps/SoftFloat-3e/source/s_shiftLeftM.c",
- "deps/SoftFloat-3e/source/s_shiftNormSigF128M.c",
- "deps/SoftFloat-3e/source/s_shiftRightJam256M.c",
- "deps/SoftFloat-3e/source/s_shiftRightJam32.c",
- "deps/SoftFloat-3e/source/s_shiftRightJam64.c",
- "deps/SoftFloat-3e/source/s_shiftRightJamM.c",
- "deps/SoftFloat-3e/source/s_shiftRightM.c",
- "deps/SoftFloat-3e/source/s_shortShiftLeft64To96M.c",
- "deps/SoftFloat-3e/source/s_shortShiftLeftM.c",
- "deps/SoftFloat-3e/source/s_shortShiftRightExtendM.c",
- "deps/SoftFloat-3e/source/s_shortShiftRightJam64.c",
- "deps/SoftFloat-3e/source/s_shortShiftRightJamM.c",
- "deps/SoftFloat-3e/source/s_shortShiftRightM.c",
- "deps/SoftFloat-3e/source/s_sub1XM.c",
- "deps/SoftFloat-3e/source/s_sub256M.c",
- "deps/SoftFloat-3e/source/s_subM.c",
- "deps/SoftFloat-3e/source/s_subMagsF16.c",
- "deps/SoftFloat-3e/source/s_subMagsF32.c",
- "deps/SoftFloat-3e/source/s_subMagsF64.c",
- "deps/SoftFloat-3e/source/s_tryPropagateNaNF128M.c",
- "deps/SoftFloat-3e/source/s_tryPropagateNaNExtF80M.c",
- "deps/SoftFloat-3e/source/softfloat_state.c",
- "deps/SoftFloat-3e/source/ui32_to_f128M.c",
- "deps/SoftFloat-3e/source/ui64_to_f128M.c",
- "deps/SoftFloat-3e/source/ui32_to_extF80M.c",
- "deps/SoftFloat-3e/source/ui64_to_extF80M.c",
-};
-
-const stage1_sources = [_][]const u8{
- "src/stage1/analyze.cpp",
- "src/stage1/astgen.cpp",
- "src/stage1/bigfloat.cpp",
- "src/stage1/bigint.cpp",
- "src/stage1/buffer.cpp",
- "src/stage1/codegen.cpp",
- "src/stage1/errmsg.cpp",
- "src/stage1/error.cpp",
- "src/stage1/heap.cpp",
- "src/stage1/ir.cpp",
- "src/stage1/ir_print.cpp",
- "src/stage1/mem.cpp",
- "src/stage1/os.cpp",
- "src/stage1/parser.cpp",
- "src/stage1/range_set.cpp",
- "src/stage1/stage1.cpp",
- "src/stage1/target.cpp",
- "src/stage1/tokenizer.cpp",
- "src/stage1/util.cpp",
- "src/stage1/softfloat_ext.cpp",
-};
-const optimized_c_sources = [_][]const u8{
- "src/stage1/parse_f128.c",
-};
-const zig_cpp_sources = [_][]const u8{
- // These are planned to stay even when we are self-hosted.
- "src/zig_llvm.cpp",
- "src/zig_clang.cpp",
- "src/zig_llvm-ar.cpp",
- "src/zig_clang_driver.cpp",
- "src/zig_clang_cc1_main.cpp",
- "src/zig_clang_cc1as_main.cpp",
- // https://github.com/ziglang/zig/issues/6363
- "src/windows_sdk.cpp",
-};
-
-const clang_libs = [_][]const u8{
- "clangFrontendTool",
- "clangCodeGen",
- "clangFrontend",
- "clangDriver",
- "clangSerialization",
- "clangSema",
- "clangStaticAnalyzerFrontend",
- "clangStaticAnalyzerCheckers",
- "clangStaticAnalyzerCore",
- "clangAnalysis",
- "clangASTMatchers",
- "clangAST",
- "clangParse",
- "clangSema",
- "clangBasic",
- "clangEdit",
- "clangLex",
- "clangARCMigrate",
- "clangRewriteFrontend",
- "clangRewrite",
- "clangCrossTU",
- "clangIndex",
- "clangToolingCore",
-};
-const lld_libs = [_][]const u8{
- "lldMinGW",
- "lldELF",
- "lldCOFF",
- "lldWasm",
- "lldMachO",
- "lldCommon",
-};
-// This list can be re-generated with `llvm-config --libfiles` and then
-// reformatting using your favorite text editor. Note we do not execute
-// `llvm-config` here because we are cross compiling. Also omit LLVMTableGen
-// from these libs.
-const llvm_libs = [_][]const u8{
- "LLVMWindowsManifest",
- "LLVMXRay",
- "LLVMLibDriver",
- "LLVMDlltoolDriver",
- "LLVMCoverage",
- "LLVMLineEditor",
- "LLVMXCoreDisassembler",
- "LLVMXCoreCodeGen",
- "LLVMXCoreDesc",
- "LLVMXCoreInfo",
- "LLVMX86TargetMCA",
- "LLVMX86Disassembler",
- "LLVMX86AsmParser",
- "LLVMX86CodeGen",
- "LLVMX86Desc",
- "LLVMX86Info",
- "LLVMWebAssemblyDisassembler",
- "LLVMWebAssemblyAsmParser",
- "LLVMWebAssemblyCodeGen",
- "LLVMWebAssemblyDesc",
- "LLVMWebAssemblyUtils",
- "LLVMWebAssemblyInfo",
- "LLVMVEDisassembler",
- "LLVMVEAsmParser",
- "LLVMVECodeGen",
- "LLVMVEDesc",
- "LLVMVEInfo",
- "LLVMSystemZDisassembler",
- "LLVMSystemZAsmParser",
- "LLVMSystemZCodeGen",
- "LLVMSystemZDesc",
- "LLVMSystemZInfo",
- "LLVMSparcDisassembler",
- "LLVMSparcAsmParser",
- "LLVMSparcCodeGen",
- "LLVMSparcDesc",
- "LLVMSparcInfo",
- "LLVMRISCVDisassembler",
- "LLVMRISCVAsmParser",
- "LLVMRISCVCodeGen",
- "LLVMRISCVDesc",
- "LLVMRISCVInfo",
- "LLVMPowerPCDisassembler",
- "LLVMPowerPCAsmParser",
- "LLVMPowerPCCodeGen",
- "LLVMPowerPCDesc",
- "LLVMPowerPCInfo",
- "LLVMNVPTXCodeGen",
- "LLVMNVPTXDesc",
- "LLVMNVPTXInfo",
- "LLVMMSP430Disassembler",
- "LLVMMSP430AsmParser",
- "LLVMMSP430CodeGen",
- "LLVMMSP430Desc",
- "LLVMMSP430Info",
- "LLVMMipsDisassembler",
- "LLVMMipsAsmParser",
- "LLVMMipsCodeGen",
- "LLVMMipsDesc",
- "LLVMMipsInfo",
- "LLVMLanaiDisassembler",
- "LLVMLanaiCodeGen",
- "LLVMLanaiAsmParser",
- "LLVMLanaiDesc",
- "LLVMLanaiInfo",
- "LLVMHexagonDisassembler",
- "LLVMHexagonCodeGen",
- "LLVMHexagonAsmParser",
- "LLVMHexagonDesc",
- "LLVMHexagonInfo",
- "LLVMBPFDisassembler",
- "LLVMBPFAsmParser",
- "LLVMBPFCodeGen",
- "LLVMBPFDesc",
- "LLVMBPFInfo",
- "LLVMAVRDisassembler",
- "LLVMAVRAsmParser",
- "LLVMAVRCodeGen",
- "LLVMAVRDesc",
- "LLVMAVRInfo",
- "LLVMARMDisassembler",
- "LLVMARMAsmParser",
- "LLVMARMCodeGen",
- "LLVMARMDesc",
- "LLVMARMUtils",
- "LLVMARMInfo",
- "LLVMAMDGPUTargetMCA",
- "LLVMAMDGPUDisassembler",
- "LLVMAMDGPUAsmParser",
- "LLVMAMDGPUCodeGen",
- "LLVMAMDGPUDesc",
- "LLVMAMDGPUUtils",
- "LLVMAMDGPUInfo",
- "LLVMAArch64Disassembler",
- "LLVMAArch64AsmParser",
- "LLVMAArch64CodeGen",
- "LLVMAArch64Desc",
- "LLVMAArch64Utils",
- "LLVMAArch64Info",
- "LLVMOrcJIT",
- "LLVMMCJIT",
- "LLVMJITLink",
- "LLVMInterpreter",
- "LLVMExecutionEngine",
- "LLVMRuntimeDyld",
- "LLVMOrcTargetProcess",
- "LLVMOrcShared",
- "LLVMDWP",
- "LLVMSymbolize",
- "LLVMDebugInfoPDB",
- "LLVMDebugInfoGSYM",
- "LLVMOption",
- "LLVMObjectYAML",
- "LLVMMCA",
- "LLVMMCDisassembler",
- "LLVMLTO",
- "LLVMPasses",
- "LLVMCFGuard",
- "LLVMCoroutines",
- "LLVMObjCARCOpts",
- "LLVMipo",
- "LLVMVectorize",
- "LLVMLinker",
- "LLVMInstrumentation",
- "LLVMFrontendOpenMP",
- "LLVMFrontendOpenACC",
- "LLVMExtensions",
- "LLVMDWARFLinker",
- "LLVMGlobalISel",
- "LLVMMIRParser",
- "LLVMAsmPrinter",
- "LLVMDebugInfoMSF",
- "LLVMSelectionDAG",
- "LLVMCodeGen",
- "LLVMIRReader",
- "LLVMAsmParser",
- "LLVMInterfaceStub",
- "LLVMFileCheck",
- "LLVMFuzzMutate",
- "LLVMTarget",
- "LLVMScalarOpts",
- "LLVMInstCombine",
- "LLVMAggressiveInstCombine",
- "LLVMTransformUtils",
- "LLVMBitWriter",
- "LLVMAnalysis",
- "LLVMProfileData",
- "LLVMDebugInfoDWARF",
- "LLVMObject",
- "LLVMTextAPI",
- "LLVMMCParser",
- "LLVMMC",
- "LLVMDebugInfoCodeView",
- "LLVMBitReader",
- "LLVMCore",
- "LLVMRemarks",
- "LLVMBitstreamReader",
- "LLVMBinaryFormat",
- "LLVMSupport",
- "LLVMDemangle",
-};
diff --git a/ci/azure/pipelines.yml b/ci/azure/pipelines.yml
index 730ecbda23d5..090c133e63ee 100644
--- a/ci/azure/pipelines.yml
+++ b/ci/azure/pipelines.yml
@@ -27,7 +27,7 @@ jobs:
vmImage: 'windows-2019'
variables:
TARGET: 'x86_64-windows-gnu'
- ZIG_LLVM_CLANG_LLD_NAME: 'zig+llvm+lld+clang-${{ variables.TARGET }}-0.10.0-dev.3524+74673b7f6'
+ ZIG_LLVM_CLANG_LLD_NAME: 'zig+llvm+lld+clang-${{ variables.TARGET }}-0.10.0-dev.3619+21f5d73cf'
ZIG_LLVM_CLANG_LLD_URL: 'https://ziglang.org/deps/${{ variables.ZIG_LLVM_CLANG_LLD_NAME }}.zip'
steps:
- pwsh: |
@@ -59,16 +59,16 @@ jobs:
mkdir $ZIGBUILDDIR
cd $ZIGBUILDDIR
- & "${ZIGPREFIXPATH}/bin/zig.exe" build `
+ & "$ZIGPREFIXPATH\bin\zig.exe" build `
--prefix "$ZIGINSTALLDIR" `
--search-prefix "$ZIGPREFIXPATH" `
+ --zig-lib-dir "..\lib" `
-Denable-stage1 `
-Dstatic-llvm `
-Drelease `
-Dstrip `
-Duse-zig-libcxx `
- -Dtarget=$(TARGET) `
- -fno-stage1
+ -Dtarget=$(TARGET)
CheckLastExitCode
cd -
From c4466496ffb53fe83644ea2b0e43f9f46a3361b8 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Wed, 17 Aug 2022 22:17:19 -0700
Subject: [PATCH 16/24] build: hook up -Dskip-stage2-tests and remove
test-toolchain
---
build.zig | 48 +++++++++++++++++++-----------------------
ci/azure/pipelines.yml | 3 ++-
test/tests.zig | 6 ++++++
3 files changed, 30 insertions(+), 27 deletions(-)
diff --git a/build.zig b/build.zig
index bb3db637d63c..c8e757dc4ea0 100644
--- a/build.zig
+++ b/build.zig
@@ -15,6 +15,7 @@ const stack_size = 32 * 1024 * 1024;
pub fn build(b: *Builder) !void {
b.setPreferredReleaseMode(.ReleaseFast);
+ const test_step = b.step("test", "Run all the tests");
const mode = b.standardReleaseOptions();
const target = b.standardTargetOptions(.{});
const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode");
@@ -39,8 +40,6 @@ pub fn build(b: *Builder) !void {
const docs_step = b.step("docs", "Build documentation");
docs_step.dependOn(&docgen_cmd.step);
- const toolchain_step = b.step("test-toolchain", "Run the tests for the toolchain");
-
var test_cases = b.addTest("src/test.zig");
test_cases.stack_size = stack_size;
test_cases.setBuildMode(mode);
@@ -149,7 +148,7 @@ pub fn build(b: *Builder) !void {
exe.setBuildMode(mode);
exe.setTarget(target);
if (!skip_stage2_tests) {
- toolchain_step.dependOn(&exe.step);
+ test_step.dependOn(&exe.step);
}
b.default_step.dependOn(&exe.step);
@@ -415,7 +414,7 @@ pub fn build(b: *Builder) !void {
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) {
- toolchain_step.dependOn(test_cases_step);
+ test_step.dependOn(test_cases_step);
}
var chosen_modes: [4]builtin.Mode = undefined;
@@ -439,11 +438,11 @@ pub fn build(b: *Builder) !void {
const modes = chosen_modes[0..chosen_mode_index];
// run stage1 `zig fmt` on this build.zig file just to make sure it works
- toolchain_step.dependOn(&fmt_build_zig.step);
+ 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);
- toolchain_step.dependOn(tests.addPkgTests(
+ test_step.dependOn(tests.addPkgTests(
b,
test_filter,
"test/behavior.zig",
@@ -454,10 +453,10 @@ pub fn build(b: *Builder) !void {
skip_non_native,
skip_libc,
skip_stage1,
- false,
+ skip_stage2_tests,
));
- toolchain_step.dependOn(tests.addPkgTests(
+ test_step.dependOn(tests.addPkgTests(
b,
test_filter,
"lib/compiler_rt.zig",
@@ -468,10 +467,10 @@ pub fn build(b: *Builder) !void {
skip_non_native,
true, // skip_libc
skip_stage1,
- true, // TODO get these all passing
+ skip_stage2_tests or true, // TODO get these all passing
));
- toolchain_step.dependOn(tests.addPkgTests(
+ test_step.dependOn(tests.addPkgTests(
b,
test_filter,
"lib/c.zig",
@@ -482,35 +481,36 @@ pub fn build(b: *Builder) !void {
skip_non_native,
true, // skip_libc
skip_stage1,
- true, // TODO get these all passing
+ skip_stage2_tests or true, // TODO get these all passing
));
- toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
- toolchain_step.dependOn(tests.addStandaloneTests(
+ test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
+ test_step.dependOn(tests.addStandaloneTests(
b,
test_filter,
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,
));
- toolchain_step.dependOn(tests.addLinkTests(b, test_filter, modes, enable_macos_sdk));
- toolchain_step.dependOn(tests.addStackTraceTests(b, test_filter, modes));
- toolchain_step.dependOn(tests.addCliTests(b, test_filter, modes));
- toolchain_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes));
- toolchain_step.dependOn(tests.addTranslateCTests(b, test_filter));
+ test_step.dependOn(tests.addLinkTests(b, test_filter, modes, enable_macos_sdk, skip_stage2_tests));
+ test_step.dependOn(tests.addStackTraceTests(b, test_filter, modes));
+ test_step.dependOn(tests.addCliTests(b, test_filter, modes));
+ test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes));
+ test_step.dependOn(tests.addTranslateCTests(b, test_filter));
if (!skip_run_translated_c) {
- toolchain_step.dependOn(tests.addRunTranslatedCTests(b, test_filter, target));
+ test_step.dependOn(tests.addRunTranslatedCTests(b, test_filter, target));
}
// tests for this feature are disabled until we have the self-hosted compiler available
- // toolchain_step.dependOn(tests.addGenHTests(b, test_filter));
+ // test_step.dependOn(tests.addGenHTests(b, test_filter));
- const std_step = tests.addPkgTests(
+ test_step.dependOn(tests.addPkgTests(
b,
test_filter,
"lib/std/std.zig",
@@ -522,11 +522,7 @@ pub fn build(b: *Builder) !void {
skip_libc,
skip_stage1,
true, // TODO get these all passing
- );
-
- const test_step = b.step("test", "Run all the tests");
- test_step.dependOn(toolchain_step);
- test_step.dependOn(std_step);
+ ));
}
const exe_cflags = [_][]const u8{
diff --git a/ci/azure/pipelines.yml b/ci/azure/pipelines.yml
index 090c133e63ee..e6b65233bd5d 100644
--- a/ci/azure/pipelines.yml
+++ b/ci/azure/pipelines.yml
@@ -88,7 +88,8 @@ jobs:
& "$ZIGINSTALLDIR\bin\zig.exe" build test `
--search-prefix "$ZIGPREFIXPATH" `
-Dstatic-llvm `
- -Dskip-non-native
+ -Dskip-non-native `
+ -Dskip-stage2-tests
CheckLastExitCode
name: test
diff --git a/test/tests.zig b/test/tests.zig
index bd3c1c5dec39..5a58daecaa7c 100644
--- a/test/tests.zig
+++ b/test/tests.zig
@@ -462,6 +462,7 @@ pub fn addStandaloneTests(
skip_non_native: bool,
enable_macos_sdk: bool,
target: std.zig.CrossTarget,
+ omit_stage2: bool,
enable_darling: bool,
enable_qemu: bool,
enable_rosetta: bool,
@@ -478,6 +479,7 @@ pub fn addStandaloneTests(
.skip_non_native = skip_non_native,
.enable_macos_sdk = enable_macos_sdk,
.target = target,
+ .omit_stage2 = omit_stage2,
.enable_darling = enable_darling,
.enable_qemu = enable_qemu,
.enable_rosetta = enable_rosetta,
@@ -495,6 +497,7 @@ pub fn addLinkTests(
test_filter: ?[]const u8,
modes: []const Mode,
enable_macos_sdk: bool,
+ omit_stage2: bool,
) *build.Step {
const cases = b.allocator.create(StandaloneContext) catch unreachable;
cases.* = StandaloneContext{
@@ -506,6 +509,7 @@ pub fn addLinkTests(
.skip_non_native = true,
.enable_macos_sdk = enable_macos_sdk,
.target = .{},
+ .omit_stage2 = omit_stage2,
};
link.addCases(cases);
return cases.step;
@@ -973,6 +977,7 @@ pub const StandaloneContext = struct {
skip_non_native: bool,
enable_macos_sdk: bool,
target: std.zig.CrossTarget,
+ omit_stage2: bool,
enable_darling: bool = false,
enable_qemu: bool = false,
enable_rosetta: bool = false,
@@ -997,6 +1002,7 @@ pub const StandaloneContext = struct {
const b = self.b;
if (features.requires_macos_sdk and !self.enable_macos_sdk) return;
+ if (features.requires_stage2 and self.omit_stage2) return;
const annotated_case_name = b.fmt("build {s}", .{build_file});
if (self.test_filter) |filter| {
From 35f62bc7aeca5c84f4ddda5736ce902018d23964 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Wed, 17 Aug 2022 23:34:57 -0700
Subject: [PATCH 17/24] CI: windows: don't create build directory
Simplify the script by not creating an unnecessary build directory and
then changing directories to and from it.
---
ci/azure/pipelines.yml | 52 ++++++++++++------------------------------
1 file changed, 14 insertions(+), 38 deletions(-)
diff --git a/ci/azure/pipelines.yml b/ci/azure/pipelines.yml
index e6b65233bd5d..26befaae79bc 100644
--- a/ci/azure/pipelines.yml
+++ b/ci/azure/pipelines.yml
@@ -37,8 +37,8 @@ jobs:
displayName: 'Install ZIG/LLVM/CLANG/LLD'
- pwsh: |
- Set-Variable -Name ZIGBUILDDIR -Value "$(Get-Location)\build"
- Set-Variable -Name ZIGINSTALLDIR -Value "${ZIGBUILDDIR}\dist"
+ Set-Variable -Name ZIGLIBDIR -Value "$(Get-Location)\lib"
+ Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\stage3-release"
Set-Variable -Name ZIGPREFIXPATH -Value "$(Get-Location)\$(ZIG_LLVM_CLANG_LLD_NAME)"
function CheckLastExitCode {
@@ -56,13 +56,10 @@ jobs:
git fetch --unshallow # `git describe` won't work on a shallow repo
}
- mkdir $ZIGBUILDDIR
- cd $ZIGBUILDDIR
-
& "$ZIGPREFIXPATH\bin\zig.exe" build `
--prefix "$ZIGINSTALLDIR" `
--search-prefix "$ZIGPREFIXPATH" `
- --zig-lib-dir "..\lib" `
+ --zig-lib-dir "$ZIGLIBDIR" `
-Denable-stage1 `
-Dstatic-llvm `
-Drelease `
@@ -70,13 +67,11 @@ jobs:
-Duse-zig-libcxx `
-Dtarget=$(TARGET)
CheckLastExitCode
-
- cd -
name: build
displayName: 'Build'
- pwsh: |
- Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\build\dist"
+ Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\stage3-release"
function CheckLastExitCode {
if (!$?) {
@@ -85,39 +80,21 @@ jobs:
return 0
}
- & "$ZIGINSTALLDIR\bin\zig.exe" build test `
+ & "$ZIGINSTALLDIR\bin\zig.exe" build test docs `
--search-prefix "$ZIGPREFIXPATH" `
-Dstatic-llvm `
-Dskip-non-native `
-Dskip-stage2-tests
CheckLastExitCode
-
name: test
displayName: 'Test'
- - pwsh: |
- Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\build\dist"
-
- function CheckLastExitCode {
- if (!$?) {
- exit 1
- }
- return 0
- }
-
- & "$ZIGINSTALLDIR\bin\zig.exe" build docs
- CheckLastExitCode
- timeoutInMinutes: 60
- name: doc
- displayName: 'Documentation'
-
- task: DownloadSecureFile@1
inputs:
name: aws_credentials
secureFile: aws_credentials
- pwsh: |
- Set-Variable -Name ZIGBUILDDIR -Value "$(Get-Location)\build"
$Env:AWS_SHARED_CREDENTIALS_FILE = "$Env:DOWNLOADSECUREFILE_SECUREFILEPATH"
# Workaround Azure networking issue
@@ -125,21 +102,20 @@ jobs:
$Env:AWS_EC2_METADATA_DISABLED = "true"
$Env:AWS_REGION = "us-west-2"
- cd "$ZIGBUILDDIR"
- mv ../LICENSE dist/
- mv ../zig-cache/langref.html dist/
- mv dist/bin/zig.exe dist/
- rmdir dist/bin
+ mv LICENSE stage3-release/
+ mv zig-cache/langref.html stage3-release/
+ mv stage3-release/bin/zig.exe stage3-release/
+ rmdir stage3-release/bin
# Remove the unnecessary zig dir in $prefix/lib/zig/std/std.zig
- mv dist/lib/zig dist/lib2
- rmdir dist/lib
- mv dist/lib2 dist/lib
+ mv stage3-release/lib/zig stage3-release/lib2
+ rmdir stage3-release/lib
+ mv stage3-release/lib2 stage3-release/lib
- Set-Variable -Name VERSION -Value $(./dist/zig.exe version)
+ Set-Variable -Name VERSION -Value $(./stage3-release/zig.exe version)
Set-Variable -Name DIRNAME -Value "zig-windows-x86_64-$VERSION"
Set-Variable -Name TARBALL -Value "$DIRNAME.zip"
- mv dist "$DIRNAME"
+ mv stage3-release "$DIRNAME"
7z a "$TARBALL" "$DIRNAME"
aws s3 cp `
From 437311756d88984d9bf3057d9cd93986c15434fa Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Thu, 18 Aug 2022 10:49:09 -0700
Subject: [PATCH 18/24] LLVM: add DLL export attribute
This was present in stage1 but missing from self-hosted.
---
src/Compilation.zig | 2 +-
src/Module.zig | 4 ++++
src/codegen/llvm.zig | 3 +++
src/codegen/llvm/bindings.zig | 9 +++++++++
4 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 84dd2739470a..0914685c77f6 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -1231,7 +1231,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
break :blk lm;
} else default_link_mode;
- const dll_export_fns = if (options.dll_export_fns) |explicit| explicit else is_dyn_lib or options.rdynamic;
+ const dll_export_fns = options.dll_export_fns orelse (is_dyn_lib or options.rdynamic);
const libc_dirs = try detectLibCIncludeDirs(
arena,
diff --git a/src/Module.zig b/src/Module.zig
index 3ae61c264fea..3577115ded11 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -6529,3 +6529,7 @@ pub fn addGlobalAssembly(mod: *Module, decl_index: Decl.Index, source: []const u
mod.global_assembly.putAssumeCapacityNoClobber(decl_index, duped_source);
}
+
+pub fn wantDllExports(mod: Module) bool {
+ return mod.comp.bin_file.options.dll_export_fns and mod.getTarget().os.tag == .windows;
+}
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 0898c8fe87c6..d50b463606c1 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -1103,6 +1103,7 @@ pub const Object = struct {
}
llvm_global.setUnnamedAddr(.False);
llvm_global.setLinkage(.External);
+ if (module.wantDllExports()) llvm_global.setDLLStorageClass(.Default);
if (self.di_map.get(decl)) |di_node| {
if (try decl.isFunction()) {
const di_func = @ptrCast(*llvm.DISubprogram, di_node);
@@ -1128,6 +1129,7 @@ pub const Object = struct {
const exp_name = exports[0].options.name;
llvm_global.setValueName2(exp_name.ptr, exp_name.len);
llvm_global.setUnnamedAddr(.False);
+ if (module.wantDllExports()) llvm_global.setDLLStorageClass(.DLLExport);
if (self.di_map.get(decl)) |di_node| {
if (try decl.isFunction()) {
const di_func = @ptrCast(*llvm.DISubprogram, di_node);
@@ -1187,6 +1189,7 @@ pub const Object = struct {
defer module.gpa.free(fqn);
llvm_global.setValueName2(fqn.ptr, fqn.len);
llvm_global.setLinkage(.Internal);
+ if (module.wantDllExports()) llvm_global.setDLLStorageClass(.Default);
llvm_global.setUnnamedAddr(.True);
if (decl.val.castTag(.variable)) |variable| {
const single_threaded = module.comp.bin_file.options.single_threaded;
diff --git a/src/codegen/llvm/bindings.zig b/src/codegen/llvm/bindings.zig
index 9daa96eb8ff0..38f794cfda84 100644
--- a/src/codegen/llvm/bindings.zig
+++ b/src/codegen/llvm/bindings.zig
@@ -223,6 +223,9 @@ pub const Value = opaque {
pub const setInitializer = LLVMSetInitializer;
extern fn LLVMSetInitializer(GlobalVar: *const Value, ConstantVal: *const Value) void;
+ pub const setDLLStorageClass = LLVMSetDLLStorageClass;
+ extern fn LLVMSetDLLStorageClass(Global: *const Value, Class: DLLStorageClass) void;
+
pub const addCase = LLVMAddCase;
extern fn LLVMAddCase(Switch: *const Value, OnVal: *const Value, Dest: *const BasicBlock) void;
@@ -1482,6 +1485,12 @@ pub const CallAttr = enum(c_int) {
AlwaysInline,
};
+pub const DLLStorageClass = enum(c_uint) {
+ Default,
+ DLLImport,
+ DLLExport,
+};
+
pub const address_space = struct {
pub const default: c_uint = 0;
From 10b95d89f878c8ba780f573d65604ef79d6cbd9a Mon Sep 17 00:00:00 2001
From: Jakub Konka
Date: Thu, 18 Aug 2022 23:26:45 +0200
Subject: [PATCH 19/24] coff: change improperly used packed struct into extern
struct
---
lib/std/coff.zig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/std/coff.zig b/lib/std/coff.zig
index 7c077a9ec850..4371444b968f 100644
--- a/lib/std/coff.zig
+++ b/lib/std/coff.zig
@@ -383,7 +383,7 @@ const OptionalHeader = struct {
image_base: u64,
};
-const DebugDirectoryEntry = packed struct {
+const DebugDirectoryEntry = extern struct {
characteristiccs: u32,
time_date_stamp: u32,
major_version: u16,
From a85f41ec2c38eff7e64ba32c76c5a60b48274a8a Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Thu, 18 Aug 2022 19:40:08 -0700
Subject: [PATCH 20/24] test-stack-traces: relax parsing rules
* accept forward and backward slashes in file paths
* strip multiple extensions; e.g. if the basename is "test.exe.obj"
then it strips to "test".
---
test/tests.zig | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/test/tests.zig b/test/tests.zig
index 5a58daecaa7c..a622521182ed 100644
--- a/test/tests.zig
+++ b/test/tests.zig
@@ -923,7 +923,7 @@ pub const StackTracesContext = struct {
pos = marks[i] + delim.len;
}
// locate source basename
- pos = mem.lastIndexOfScalar(u8, line[0..marks[0]], fs.path.sep) orelse {
+ pos = mem.lastIndexOfAny(u8, line[0..marks[0]], "\\/") orelse {
// unexpected pattern: emit raw line and cont
try buf.appendSlice(line);
try buf.appendSlice("\n");
@@ -935,9 +935,9 @@ pub const StackTracesContext = struct {
try buf.appendSlice(line[pos + 1 .. marks[2] + delims[2].len]);
try buf.appendSlice(" [address]");
if (self.mode == .Debug) {
- if (mem.lastIndexOfScalar(u8, line[marks[4]..marks[5]], '.')) |idot| {
- // On certain platforms (windows) or possibly depending on how we choose to link main
- // the object file extension may be present so we simply strip any extension.
+ // On certain platforms (windows) or possibly depending on how we choose to link main
+ // the object file extension may be present so we simply strip any extension.
+ if (mem.indexOfScalar(u8, line[marks[4]..marks[5]], '.')) |idot| {
try buf.appendSlice(line[marks[3] .. marks[4] + idot]);
try buf.appendSlice(line[marks[5]..]);
} else {
From 4a27d2aac673751142b16ab78434c6978311e706 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Fri, 19 Aug 2022 16:25:09 -0700
Subject: [PATCH 21/24] std.os.linux.bpf: fix compile error
---
lib/std/os/linux/bpf.zig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/std/os/linux/bpf.zig b/lib/std/os/linux/bpf.zig
index 4cb9dbf5c539..147bf610d845 100644
--- a/lib/std/os/linux/bpf.zig
+++ b/lib/std/os/linux/bpf.zig
@@ -458,7 +458,7 @@ pub const Insn = packed struct {
else
ImmOrReg{ .imm = src };
- const src_type = switch (imm_or_reg) {
+ const src_type: u8 = switch (imm_or_reg) {
.imm => K,
.reg => X,
};
From 3ce80608182f3e4f03c6f59bdc93413332840da0 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Fri, 19 Aug 2022 16:34:41 -0700
Subject: [PATCH 22/24] CI: update windows tarball
---
ci/azure/pipelines.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ci/azure/pipelines.yml b/ci/azure/pipelines.yml
index 26befaae79bc..5eab6defff74 100644
--- a/ci/azure/pipelines.yml
+++ b/ci/azure/pipelines.yml
@@ -27,7 +27,7 @@ jobs:
vmImage: 'windows-2019'
variables:
TARGET: 'x86_64-windows-gnu'
- ZIG_LLVM_CLANG_LLD_NAME: 'zig+llvm+lld+clang-${{ variables.TARGET }}-0.10.0-dev.3619+21f5d73cf'
+ ZIG_LLVM_CLANG_LLD_NAME: 'zig+llvm+lld+clang-${{ variables.TARGET }}-0.10.0-dev.3653+7152a58c1'
ZIG_LLVM_CLANG_LLD_URL: 'https://ziglang.org/deps/${{ variables.ZIG_LLVM_CLANG_LLD_NAME }}.zip'
steps:
- pwsh: |
From e78e9f33c0a29d008838b8f23cb3e59667c5d6e0 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Fri, 19 Aug 2022 16:44:24 -0700
Subject: [PATCH 23/24] CI: update x86_64-linux tarball
---
ci/zinc/drone.yml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/ci/zinc/drone.yml b/ci/zinc/drone.yml
index 38185df7e7d7..fc14ad3ec97f 100644
--- a/ci/zinc/drone.yml
+++ b/ci/zinc/drone.yml
@@ -10,12 +10,12 @@ workspace:
steps:
- name: test_stage3_debug
- image: ci/debian-amd64:11.1-6
+ image: ci/debian-amd64:11.1-7
commands:
- ./ci/zinc/linux_test_stage3_debug.sh
- name: test_stage3_release
- image: ci/debian-amd64:11.1-6
+ image: ci/debian-amd64:11.1-7
commands:
- ./ci/zinc/linux_test_stage3_release.sh
@@ -28,7 +28,7 @@ steps:
- master
event:
- push
- image: ci/debian-amd64:11.1-6
+ image: ci/debian-amd64:11.1-7
environment:
AWS_ACCESS_KEY_ID:
from_secret: AWS_ACCESS_KEY_ID
From b75eeae5951f2dc4ff19f795ebd856c134722375 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Fri, 19 Aug 2022 17:24:23 -0700
Subject: [PATCH 24/24] CI: x86_64-linux: avoid cmake ZIG_EXECUTABLE hack
empirically this avoids a segfault on the CI.
---
ci/zinc/linux_test_stage3_debug.sh | 6 ------
1 file changed, 6 deletions(-)
diff --git a/ci/zinc/linux_test_stage3_debug.sh b/ci/zinc/linux_test_stage3_debug.sh
index 2bacf6d838e3..ba33311a4d09 100755
--- a/ci/zinc/linux_test_stage3_debug.sh
+++ b/ci/zinc/linux_test_stage3_debug.sh
@@ -35,12 +35,6 @@ unset CXX
ninja install
-# Here we rebuild zig but this time using the Zig binary we just now produced to
-# build zig1.o rather than relying on the one built with stage0. See
-# https://github.com/ziglang/zig/issues/6830 for more details.
-cmake .. -DZIG_EXECUTABLE="$DEBUG_STAGING/bin/zig"
-ninja install
-
cd $WORKSPACE
"$DEBUG_STAGING/bin/zig" build -p stage3 -Denable-stage1 -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"