authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-18 01:54:34-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-02-18 01:54:34-05:00
log56e9575e827208b3df5c90472826f52bfc8342c0
treec6d113eef8fc045f45b7e2adcaf4e99e5e3b6ab6
parent9ea253b9c4085b9f577c4d7634da69b2d40d6cce
parenteee500c0b59487b78294696160a976f20fe64829
signature Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #10919 from ziglang/test-more-stage2

CI: more stage2 test coverage

9 files changed, 123 insertions(+), 127 deletions(-)

build.zig+11-6
...@@ -129,6 +129,7 @@ pub fn build(b: *Builder) !void {...@@ -129,6 +129,7 @@ pub fn build(b: *Builder) !void {
129 const force_gpa = b.option(bool, "force-gpa", "Force the compiler to use GeneralPurposeAllocator") orelse false;129 const force_gpa = b.option(bool, "force-gpa", "Force the compiler to use GeneralPurposeAllocator") orelse false;
130 const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse enable_llvm;130 const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse enable_llvm;
131 const strip = b.option(bool, "strip", "Omit debug information") orelse false;131 const strip = b.option(bool, "strip", "Omit debug information") orelse false;
132 const use_zig0 = b.option(bool, "zig0", "Bootstrap using zig0") orelse false;
132133
133 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: {134 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: {
134 if (strip) break :blk @as(u32, 0);135 if (strip) break :blk @as(u32, 0);
...@@ -136,7 +137,11 @@ pub fn build(b: *Builder) !void {...@@ -136,7 +137,11 @@ pub fn build(b: *Builder) !void {
136 break :blk 4;137 break :blk 4;
137 };138 };
138139
139 const main_file: ?[]const u8 = if (is_stage1) null else "src/main.zig";140 const main_file: ?[]const u8 = mf: {
141 if (!is_stage1) break :mf "src/main.zig";
142 if (use_zig0) break :mf null;
143 break :mf "src/stage1.zig";
144 };
140145
141 const exe = b.addExecutable("zig", main_file);146 const exe = b.addExecutable("zig", main_file);
142 exe.strip = strip;147 exe.strip = strip;
...@@ -311,8 +316,10 @@ pub fn build(b: *Builder) !void {...@@ -311,8 +316,10 @@ pub fn build(b: *Builder) !void {
311 zig1_obj.addArg("-fsingle-threaded");316 zig1_obj.addArg("-fsingle-threaded");
312 }317 }
313318
314 exe.step.dependOn(&zig1_obj.step);319 if (use_zig0) {
315 exe.addObjectFile(zig1_obj_path);320 exe.step.dependOn(&zig1_obj.step);
321 exe.addObjectFile(zig1_obj_path);
322 }
316323
317 // This is intentionally a dummy path. stage1.zig tries to @import("compiler_rt") in case324 // This is intentionally a dummy path. stage1.zig tries to @import("compiler_rt") in case
318 // of being built by cmake. But when built by zig it's gonna get a compiler_rt so that325 // of being built by cmake. But when built by zig it's gonna get a compiler_rt so that
...@@ -559,9 +566,7 @@ fn addCmakeCfgOptionsToExe(...@@ -559,9 +566,7 @@ fn addCmakeCfgOptionsToExe(
559 }566 }
560}567}
561568
562fn addStaticLlvmOptionsToExe(569fn addStaticLlvmOptionsToExe(exe: *std.build.LibExeObjStep) !void {
563 exe: *std.build.LibExeObjStep,
564) !void {
565 // Adds the Zig C++ sources which both stage1 and stage2 need.570 // Adds the Zig C++ sources which both stage1 and stage2 need.
566 //571 //
567 // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling572 // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling
ci/azure/macos_script+5-2
...@@ -55,8 +55,11 @@ make $JOBS install...@@ -55,8 +55,11 @@ make $JOBS install
55cmake .. -DZIG_EXECUTABLE="$(pwd)/release/bin/zig"55cmake .. -DZIG_EXECUTABLE="$(pwd)/release/bin/zig"
56make $JOBS install56make $JOBS install
5757
58# TODO figure out why this causes a segmentation fault58# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.
59# release/bin/zig test ../test/behavior.zig -fno-stage1 -fLLVM -I ../test59release/bin/zig build -p stage2 -Denable-llvm
60
61stage2/bin/zig test ../test/behavior.zig -I../test -fLLVM
62stage2/bin/zig test ../test/behavior.zig -I../test
6063
61release/bin/zig build test-toolchain -Denable-macos-sdk64release/bin/zig build test-toolchain -Denable-macos-sdk
62release/bin/zig build test-std65release/bin/zig build test-std
ci/azure/windows_script.bat deleted-8
...@@ -1,8 +0,0 @@
1@echo on
2SET "SRCROOT=%cd%"
3SET "PREVPATH=%PATH%"
4SET "PREVMSYSTEM=%MSYSTEM%"
5
6set "PATH=%CD:~0,2%\msys64\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem"
7SET "MSYSTEM=MINGW64"
8bash -lc "cd ${SRCROOT} && ci/azure/windows_script" || exit /b
ci/zinc/drone.yml-12
...@@ -9,19 +9,7 @@ workspace:...@@ -9,19 +9,7 @@ workspace:
9 path: /workspace9 path: /workspace
1010
11steps:11steps:
12- name: probe
13 image: ci/debian-amd64:11.1-3
14 commands:
15 - ./ci/zinc/linux_probe.sh
16
17- name: build
18 image: ci/debian-amd64:11.1-3
19 commands:
20 - ./ci/zinc/linux_build.sh
21
22- name: test12- name: test
23 depends_on:
24 - build
25 image: ci/debian-amd64:11.1-313 image: ci/debian-amd64:11.1-3
26 commands:14 commands:
27 - ./ci/zinc/linux_test.sh15 - ./ci/zinc/linux_test.sh
ci/zinc/linux_base.sh-1
...@@ -17,7 +17,6 @@ set -x...@@ -17,7 +17,6 @@ set -x
17set -e17set -e
1818
19ARCH="$(uname -m)"19ARCH="$(uname -m)"
20JOBS="-j$(nproc)"
2120
22DEPS_LOCAL="/deps/local"21DEPS_LOCAL="/deps/local"
23WORKSPACE="$DRONE_WORKSPACE"22WORKSPACE="$DRONE_WORKSPACE"
ci/zinc/linux_build.sh deleted-72
...@@ -1,72 +0,0 @@
1#!/bin/sh
2
3. ./ci/zinc/linux_base.sh
4
5ZIG="$DEPS_LOCAL/bin/zig"
6TARGET="${ARCH}-linux-musl"
7MCPU="baseline"
8
9# Make the `zig version` number consistent.
10# This will affect the cmake command below.
11git config core.abbrev 9
12
13# Build debug zig.
14echo "BUILD debug zig with zig:$($ZIG version)"
15
16export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
17export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
18
19mkdir _debug
20cd _debug
21cmake .. \
22 -DCMAKE_INSTALL_PREFIX="$DEBUG_STAGING" \
23 -DCMAKE_PREFIX_PATH="$DEPS_LOCAL" \
24 -DCMAKE_BUILD_TYPE=Debug \
25 -DZIG_TARGET_TRIPLE="$TARGET" \
26 -DZIG_TARGET_MCPU="$MCPU" \
27 -DZIG_STATIC=ON \
28 -GNinja
29
30# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
31# so that installation and testing do not get affected by them.
32unset CC
33unset CXX
34
35ninja $JOBS install
36
37ZIG=$DEBUG_STAGING/bin/zig
38
39# Here we rebuild zig but this time using the Zig binary we just now produced to
40# build zig1.o rather than relying on the one built with stage0. See
41# https://github.com/ziglang/zig/issues/6830 for more details.
42cmake .. -DZIG_EXECUTABLE="$ZIG"
43ninja $JOBS install
44
45cd $WORKSPACE
46
47# Build release zig.
48echo "BUILD release zig with zig:$($ZIG version)"
49export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
50export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
51mkdir _release
52cd _release
53cmake .. \
54 -DCMAKE_INSTALL_PREFIX="$RELEASE_STAGING" \
55 -DCMAKE_PREFIX_PATH="$DEPS_LOCAL" \
56 -DCMAKE_BUILD_TYPE=Release \
57 -DZIG_TARGET_TRIPLE="$TARGET" \
58 -DZIG_TARGET_MCPU="$MCPU" \
59 -DZIG_STATIC=ON \
60 -GNinja
61unset CC
62unset CXX
63ninja $JOBS install
64
65cd $WORKSPACE
66
67# Look for non-conforming code formatting.
68# Formatting errors can be fixed by running `zig fmt` on the files printed here.
69$ZIG fmt --check .
70
71# Explicit exit helps show last command duration.
72exit
ci/zinc/linux_probe.sh deleted-10
...@@ -1,10 +0,0 @@
1#!/bin/sh
2
3. ./ci/zinc/linux_base.sh
4
5# Probe CPU/brand details.
6echo "lscpu:"
7(lscpu | sed 's,^, : ,') 1>&2
8
9# Explicit exit helps show last command duration.
10exit
ci/zinc/linux_test.sh+70-9
...@@ -2,15 +2,65 @@...@@ -2,15 +2,65 @@
22
3. ./ci/zinc/linux_base.sh3. ./ci/zinc/linux_base.sh
44
5ZIG=$DEBUG_STAGING/bin/zig5ZIG="$DEPS_LOCAL/bin/zig"
6TARGET="${ARCH}-linux-musl"
7MCPU="baseline"
68
7$ZIG test test/behavior.zig -fno-stage1 -I test -fLLVM9# Make the `zig version` number consistent.
8$ZIG test test/behavior.zig -fno-stage1 -I test -fLLVM -target aarch64-linux --test-cmd qemu-aarch64 --test-cmd-bin10# This will affect the cmake command below.
9$ZIG test test/behavior.zig -fno-stage1 -I test -ofmt=c11git config core.abbrev 9
10$ZIG test test/behavior.zig -fno-stage1 -I test -target wasm32-wasi --test-cmd wasmtime --test-cmd-bin12
11$ZIG test test/behavior.zig -fno-stage1 -I test -target arm-linux --test-cmd qemu-arm --test-cmd-bin13echo "BUILD debug zig with zig:$($ZIG version)"
12$ZIG test test/behavior.zig -fno-stage1 -I test -target aarch64-linux --test-cmd qemu-aarch64 --test-cmd-bin14
13$ZIG test test/behavior.zig -fno-stage1 -I test15export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
16export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
17
18mkdir _debug
19cd _debug
20cmake .. \
21 -DCMAKE_INSTALL_PREFIX="$DEBUG_STAGING" \
22 -DCMAKE_PREFIX_PATH="$DEPS_LOCAL" \
23 -DCMAKE_BUILD_TYPE=Debug \
24 -DZIG_TARGET_TRIPLE="$TARGET" \
25 -DZIG_TARGET_MCPU="$MCPU" \
26 -DZIG_STATIC=ON \
27 -GNinja
28
29# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
30# so that installation and testing do not get affected by them.
31unset CC
32unset CXX
33
34ninja install
35
36ZIG="$DEBUG_STAGING/bin/zig"
37
38# Here we rebuild zig but this time using the Zig binary we just now produced to
39# build zig1.o rather than relying on the one built with stage0. See
40# https://github.com/ziglang/zig/issues/6830 for more details.
41cmake .. -DZIG_EXECUTABLE="$ZIG"
42ninja install
43
44cd $WORKSPACE
45
46# Look for non-conforming code formatting.
47# Formatting errors can be fixed by running `zig fmt` on the files printed here.
48$ZIG fmt --check .
49
50# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.
51$ZIG build -p stage2 -Denable-llvm -Duse-zig-libcxx
52
53stage2/bin/zig test test/behavior.zig -I test -fLLVM
54stage2/bin/zig test test/behavior.zig -I test
55stage2/bin/zig test test/behavior.zig -I test -fLLVM -target aarch64-linux --test-cmd qemu-aarch64 --test-cmd-bin
56stage2/bin/zig test test/behavior.zig -I test -target aarch64-linux --test-cmd qemu-aarch64 --test-cmd-bin
57stage2/bin/zig test test/behavior.zig -I test -ofmt=c
58stage2/bin/zig test test/behavior.zig -I test -target wasm32-wasi --test-cmd wasmtime --test-cmd-bin
59stage2/bin/zig test test/behavior.zig -I test -target arm-linux --test-cmd qemu-arm --test-cmd-bin
60stage2/bin/zig test test/behavior.zig -I test -fLLVM -target aarch64-macos --test-no-exec
61stage2/bin/zig test test/behavior.zig -I test -target aarch64-macos --test-no-exec
62stage2/bin/zig test test/behavior.zig -I test -fLLVM -target x86_64-macos --test-no-exec
63stage2/bin/zig test test/behavior.zig -I test -target x86_64-macos --test-no-exec
1464
15$ZIG build test-behavior -fqemu -fwasmtime65$ZIG build test-behavior -fqemu -fwasmtime
16$ZIG build test-compiler-rt -fqemu -fwasmtime66$ZIG build test-compiler-rt -fqemu -fwasmtime
...@@ -31,7 +81,7 @@ $ZIG build test-fmt -fqemu -fwasmtime...@@ -31,7 +81,7 @@ $ZIG build test-fmt -fqemu -fwasmtime
31$ZIG build test-stage2 -fqemu -fwasmtime81$ZIG build test-stage2 -fqemu -fwasmtime
3282
33# Produce the experimental std lib documentation.83# Produce the experimental std lib documentation.
34mkdir -p $RELEASE_STAGING/docs/std84mkdir -p "$RELEASE_STAGING/docs/std"
35$ZIG test lib/std/std.zig \85$ZIG test lib/std/std.zig \
36 --zig-lib-dir lib \86 --zig-lib-dir lib \
37 -femit-docs=$RELEASE_STAGING/docs/std \87 -femit-docs=$RELEASE_STAGING/docs/std \
...@@ -40,5 +90,16 @@ $ZIG test lib/std/std.zig \...@@ -40,5 +90,16 @@ $ZIG test lib/std/std.zig \
40# Look for HTML errors.90# Look for HTML errors.
41tidy --drop-empty-elements no -qe zig-cache/langref.html91tidy --drop-empty-elements no -qe zig-cache/langref.html
4292
93# Build release zig.
94$ZIG build \
95 --prefix "$RELEASE_STAGING" \
96 --search-prefix "$DEPS_LOCAL" \
97 -Denable-llvm \
98 -Duse-zig-libcxx \
99 -Drelease \
100 -Dstrip \
101 -Dtarget="$TARGET" \
102 -Dstage1
103
43# Explicit exit helps show last command duration.104# Explicit exit helps show last command duration.
44exit105exit
src/main.zig+37-7
...@@ -2008,28 +2008,34 @@ fn buildOutputType(...@@ -2008,28 +2008,34 @@ fn buildOutputType(
2008 // are part of libc or libc++. We remove them from the list and communicate their2008 // are part of libc or libc++. We remove them from the list and communicate their
2009 // existence via flags instead.2009 // existence via flags instead.
2010 {2010 {
2011 // Similarly, if any libs in this list are statically provided, we remove
2012 // them from this list and populate the link_objects array instead.
2013 const sep = fs.path.sep_str;
2014 var test_path = std.ArrayList(u8).init(gpa);
2015 defer test_path.deinit();
2016
2011 var i: usize = 0;2017 var i: usize = 0;
2012 while (i < system_libs.count()) {2018 syslib: while (i < system_libs.count()) {
2013 const lib_name = system_libs.keys()[i];2019 const lib_name = system_libs.keys()[i];
20142020
2015 if (target_util.is_libc_lib_name(target_info.target, lib_name)) {2021 if (target_util.is_libc_lib_name(target_info.target, lib_name)) {
2016 link_libc = true;2022 link_libc = true;
2017 _ = system_libs.orderedRemove(lib_name);2023 system_libs.orderedRemoveAt(i);
2018 continue;2024 continue;
2019 }2025 }
2020 if (target_util.is_libcpp_lib_name(target_info.target, lib_name)) {2026 if (target_util.is_libcpp_lib_name(target_info.target, lib_name)) {
2021 link_libcpp = true;2027 link_libcpp = true;
2022 _ = system_libs.orderedRemove(lib_name);2028 system_libs.orderedRemoveAt(i);
2023 continue;2029 continue;
2024 }2030 }
2025 if (mem.eql(u8, lib_name, "unwind")) {2031 if (mem.eql(u8, lib_name, "unwind")) {
2026 link_libunwind = true;2032 link_libunwind = true;
2027 _ = system_libs.orderedRemove(lib_name);2033 system_libs.orderedRemoveAt(i);
2028 continue;2034 continue;
2029 }2035 }
2030 if (target_util.is_compiler_rt_lib_name(target_info.target, lib_name)) {2036 if (target_util.is_compiler_rt_lib_name(target_info.target, lib_name)) {
2031 std.log.warn("ignoring superfluous library '{s}': this dependency is fulfilled instead by compiler-rt which zig unconditionally provides", .{lib_name});2037 std.log.warn("ignoring superfluous library '{s}': this dependency is fulfilled instead by compiler-rt which zig unconditionally provides", .{lib_name});
2032 _ = system_libs.orderedRemove(lib_name);2038 system_libs.orderedRemoveAt(i);
2033 continue;2039 continue;
2034 }2040 }
2035 if (std.fs.path.isAbsolute(lib_name)) {2041 if (std.fs.path.isAbsolute(lib_name)) {
...@@ -2038,10 +2044,32 @@ fn buildOutputType(...@@ -2038,10 +2044,32 @@ fn buildOutputType(
2038 if (target_info.target.os.tag == .wasi) {2044 if (target_info.target.os.tag == .wasi) {
2039 if (wasi_libc.getEmulatedLibCRTFile(lib_name)) |crt_file| {2045 if (wasi_libc.getEmulatedLibCRTFile(lib_name)) |crt_file| {
2040 try wasi_emulated_libs.append(crt_file);2046 try wasi_emulated_libs.append(crt_file);
2041 _ = system_libs.orderedRemove(lib_name);2047 system_libs.orderedRemoveAt(i);
2042 continue;2048 continue;
2043 }2049 }
2044 }2050 }
2051
2052 for (lib_dirs.items) |lib_dir_path| {
2053 test_path.clearRetainingCapacity();
2054 try test_path.writer().print("{s}" ++ sep ++ "{s}{s}{s}", .{
2055 lib_dir_path,
2056 target_info.target.libPrefix(),
2057 lib_name,
2058 target_info.target.staticLibSuffix(),
2059 });
2060 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
2061 error.FileNotFound => continue,
2062 else => |e| fatal("unable to search for static library '{s}': {s}", .{
2063 test_path.items, @errorName(e),
2064 }),
2065 };
2066 try link_objects.append(.{ .path = try arena.dupe(u8, test_path.items) });
2067 system_libs.orderedRemoveAt(i);
2068 continue :syslib;
2069 }
2070
2071 std.log.scoped(.cli).debug("depending on system for -l{s}", .{lib_name});
2072
2045 i += 1;2073 i += 1;
2046 }2074 }
2047 }2075 }
...@@ -2068,7 +2096,9 @@ fn buildOutputType(...@@ -2068,7 +2096,9 @@ fn buildOutputType(
2068 want_native_include_dirs = true;2096 want_native_include_dirs = true;
2069 }2097 }
20702098
2071 if (sysroot == null and cross_target.isNativeOs() and (system_libs.count() != 0 or want_native_include_dirs)) {2099 if (sysroot == null and cross_target.isNativeOs() and
2100 (system_libs.count() != 0 or want_native_include_dirs))
2101 {
2072 const paths = std.zig.system.NativePaths.detect(arena, target_info) catch |err| {2102 const paths = std.zig.system.NativePaths.detect(arena, target_info) catch |err| {
2073 fatal("unable to detect native system paths: {s}", .{@errorName(err)});2103 fatal("unable to detect native system paths: {s}", .{@errorName(err)});
2074 };2104 };