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 {
129129 const force_gpa = b.option(bool, "force-gpa", "Force the compiler to use GeneralPurposeAllocator") orelse false;
130130 const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse enable_llvm;
131131 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
133134 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: {
134135 if (strip) break :blk @as(u32, 0);
......@@ -136,7 +137,11 @@ pub fn build(b: *Builder) !void {
136137 break :blk 4;
137138 };
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
141146 const exe = b.addExecutable("zig", main_file);
142147 exe.strip = strip;
......@@ -311,8 +316,10 @@ pub fn build(b: *Builder) !void {
311316 zig1_obj.addArg("-fsingle-threaded");
312317 }
313318
314 exe.step.dependOn(&zig1_obj.step);
315 exe.addObjectFile(zig1_obj_path);
319 if (use_zig0) {
320 exe.step.dependOn(&zig1_obj.step);
321 exe.addObjectFile(zig1_obj_path);
322 }
316323
317324 // This is intentionally a dummy path. stage1.zig tries to @import("compiler_rt") in case
318325 // 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(
559566 }
560567}
561568
562fn addStaticLlvmOptionsToExe(
563 exe: *std.build.LibExeObjStep,
564) !void {
569fn addStaticLlvmOptionsToExe(exe: *std.build.LibExeObjStep) !void {
565570 // Adds the Zig C++ sources which both stage1 and stage2 need.
566571 //
567572 // 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
5555cmake .. -DZIG_EXECUTABLE="$(pwd)/release/bin/zig"
5656make $JOBS install
5757
58# TODO figure out why this causes a segmentation fault
59# release/bin/zig test ../test/behavior.zig -fno-stage1 -fLLVM -I ../test
58# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.
59release/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
6164release/bin/zig build test-toolchain -Denable-macos-sdk
6265release/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:
99 path: /workspace
1010
1111steps:
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
2212- name: test
23 depends_on:
24 - build
2513 image: ci/debian-amd64:11.1-3
2614 commands:
2715 - ./ci/zinc/linux_test.sh
ci/zinc/linux_base.sh-1
......@@ -17,7 +17,6 @@ set -x
1717set -e
1818
1919ARCH="$(uname -m)"
20JOBS="-j$(nproc)"
2120
2221DEPS_LOCAL="/deps/local"
2322WORKSPACE="$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 @@
22
33. ./ci/zinc/linux_base.sh
44
5ZIG=$DEBUG_STAGING/bin/zig
5ZIG="$DEPS_LOCAL/bin/zig"
6TARGET="${ARCH}-linux-musl"
7MCPU="baseline"
68
7$ZIG test test/behavior.zig -fno-stage1 -I test -fLLVM
8$ZIG test test/behavior.zig -fno-stage1 -I test -fLLVM -target aarch64-linux --test-cmd qemu-aarch64 --test-cmd-bin
9$ZIG test test/behavior.zig -fno-stage1 -I test -ofmt=c
10$ZIG test test/behavior.zig -fno-stage1 -I test -target wasm32-wasi --test-cmd wasmtime --test-cmd-bin
11$ZIG test test/behavior.zig -fno-stage1 -I test -target arm-linux --test-cmd qemu-arm --test-cmd-bin
12$ZIG test test/behavior.zig -fno-stage1 -I test -target aarch64-linux --test-cmd qemu-aarch64 --test-cmd-bin
13$ZIG test test/behavior.zig -fno-stage1 -I test
9# Make the `zig version` number consistent.
10# This will affect the cmake command below.
11git config core.abbrev 9
12
13echo "BUILD debug zig with zig:$($ZIG version)"
14
15export 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
1565$ZIG build test-behavior -fqemu -fwasmtime
1666$ZIG build test-compiler-rt -fqemu -fwasmtime
......@@ -31,7 +81,7 @@ $ZIG build test-fmt -fqemu -fwasmtime
3181$ZIG build test-stage2 -fqemu -fwasmtime
3282
3383# Produce the experimental std lib documentation.
34mkdir -p $RELEASE_STAGING/docs/std
84mkdir -p "$RELEASE_STAGING/docs/std"
3585$ZIG test lib/std/std.zig \
3686 --zig-lib-dir lib \
3787 -femit-docs=$RELEASE_STAGING/docs/std \
......@@ -40,5 +90,16 @@ $ZIG test lib/std/std.zig \
4090# Look for HTML errors.
4191tidy --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
43104# Explicit exit helps show last command duration.
44105exit
src/main.zig+37-7
......@@ -2008,28 +2008,34 @@ fn buildOutputType(
20082008 // are part of libc or libc++. We remove them from the list and communicate their
20092009 // existence via flags instead.
20102010 {
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
20112017 var i: usize = 0;
2012 while (i < system_libs.count()) {
2018 syslib: while (i < system_libs.count()) {
20132019 const lib_name = system_libs.keys()[i];
20142020
20152021 if (target_util.is_libc_lib_name(target_info.target, lib_name)) {
20162022 link_libc = true;
2017 _ = system_libs.orderedRemove(lib_name);
2023 system_libs.orderedRemoveAt(i);
20182024 continue;
20192025 }
20202026 if (target_util.is_libcpp_lib_name(target_info.target, lib_name)) {
20212027 link_libcpp = true;
2022 _ = system_libs.orderedRemove(lib_name);
2028 system_libs.orderedRemoveAt(i);
20232029 continue;
20242030 }
20252031 if (mem.eql(u8, lib_name, "unwind")) {
20262032 link_libunwind = true;
2027 _ = system_libs.orderedRemove(lib_name);
2033 system_libs.orderedRemoveAt(i);
20282034 continue;
20292035 }
20302036 if (target_util.is_compiler_rt_lib_name(target_info.target, lib_name)) {
20312037 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);
20332039 continue;
20342040 }
20352041 if (std.fs.path.isAbsolute(lib_name)) {
......@@ -2038,10 +2044,32 @@ fn buildOutputType(
20382044 if (target_info.target.os.tag == .wasi) {
20392045 if (wasi_libc.getEmulatedLibCRTFile(lib_name)) |crt_file| {
20402046 try wasi_emulated_libs.append(crt_file);
2041 _ = system_libs.orderedRemove(lib_name);
2047 system_libs.orderedRemoveAt(i);
20422048 continue;
20432049 }
20442050 }
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
20452073 i += 1;
20462074 }
20472075 }
......@@ -2068,7 +2096,9 @@ fn buildOutputType(
20682096 want_native_include_dirs = true;
20692097 }
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 {
20722102 const paths = std.zig.system.NativePaths.detect(arena, target_info) catch |err| {
20732103 fatal("unable to detect native system paths: {s}", .{@errorName(err)});
20742104 };