authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-17 16:16:33-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-17 23:42:46-07:00
log419074a81ba7d7111bae7d07af26aad9c7deeb1f
treea84ac7699832e56585e18802ac14cb6eeda924a2
parent2f42a2617b55c497bc13a44f64a921e6d2620acf

CI: simplify linux script

* build.zig: remove detour through zig0. I'll add it back as an option later. This means you can build stage1 with a freshly built zig without detouring through zig0 again. * remove unused file windows_script.bat * drone.yml: remove unnecessary steps * ninja doesn't need a jobs parameter * build the release version of zig with zig build instead of cmake. * build stage2 with -Dstatic-llvm -Duse-zig-libcxx

7 files changed, 67 insertions(+), 172 deletions(-)

build.zig+9-66
...@@ -136,7 +136,7 @@ pub fn build(b: *Builder) !void {...@@ -136,7 +136,7 @@ pub fn build(b: *Builder) !void {
136 break :blk 4;136 break :blk 4;
137 };137 };
138138
139 const main_file: ?[]const u8 = if (is_stage1) null else "src/main.zig";139 const main_file: []const u8 = if (is_stage1) "src/stage1.zig" else "src/main.zig";
140140
141 const exe = b.addExecutable("zig", main_file);141 const exe = b.addExecutable("zig", main_file);
142 exe.strip = strip;142 exe.strip = strip;
...@@ -245,74 +245,17 @@ pub fn build(b: *Builder) !void {...@@ -245,74 +245,17 @@ pub fn build(b: *Builder) !void {
245 softfloat.addCSourceFiles(&softfloat_sources, &[_][]const u8{ "-std=c99", "-O3" });245 softfloat.addCSourceFiles(&softfloat_sources, &[_][]const u8{ "-std=c99", "-O3" });
246 softfloat.single_threaded = single_threaded;246 softfloat.single_threaded = single_threaded;
247247
248 const zig0 = b.addExecutable("zig0", null);248 exe.addIncludePath("src");
249 zig0.addCSourceFiles(&.{"src/stage1/zig0.cpp"}, &exe_cflags);249 exe.addIncludePath("deps/SoftFloat-3e/source/include");
250 zig0.addIncludePath("zig-cache/tmp"); // for config.h250 exe.addIncludePath("deps/SoftFloat-3e-prebuilt");
251 zig0.defineCMacro("ZIG_VERSION_MAJOR", b.fmt("{d}", .{zig_version.major}));
252 zig0.defineCMacro("ZIG_VERSION_MINOR", b.fmt("{d}", .{zig_version.minor}));
253 zig0.defineCMacro("ZIG_VERSION_PATCH", b.fmt("{d}", .{zig_version.patch}));
254 zig0.defineCMacro("ZIG_VERSION_STRING", b.fmt("\"{s}\"", .{version}));
255251
256 for ([_]*std.build.LibExeObjStep{ zig0, exe, test_stage2 }) |artifact| {252 exe.defineCMacro("ZIG_LINK_MODE", "Static");
257 artifact.addIncludePath("src");
258 artifact.addIncludePath("deps/SoftFloat-3e/source/include");
259 artifact.addIncludePath("deps/SoftFloat-3e-prebuilt");
260253
261 artifact.defineCMacro("ZIG_LINK_MODE", "Static");254 exe.addCSourceFiles(&stage1_sources, &exe_cflags);
255 exe.addCSourceFiles(&optimized_c_sources, &[_][]const u8{ "-std=c99", "-O3" });
262256
263 artifact.addCSourceFiles(&stage1_sources, &exe_cflags);257 exe.linkLibrary(softfloat);
264 artifact.addCSourceFiles(&optimized_c_sources, &[_][]const u8{ "-std=c99", "-O3" });258 exe.linkLibCpp();
265
266 artifact.linkLibrary(softfloat);
267 artifact.linkLibCpp();
268 }
269
270 try addStaticLlvmOptionsToExe(zig0);
271
272 const zig1_obj_ext = target.getObjectFormat().fileExt(target.getCpuArch());
273 const zig1_obj_path = b.pathJoin(&.{ "zig-cache", "tmp", b.fmt("zig1{s}", .{zig1_obj_ext}) });
274 const zig1_compiler_rt_path = b.pathJoin(&.{ b.pathFromRoot("lib"), "std", "special", "compiler_rt.zig" });
275
276 const zig1_obj = zig0.run();
277 zig1_obj.addArgs(&.{
278 "src/stage1.zig",
279 "-target",
280 try target.zigTriple(b.allocator),
281 "-mcpu=baseline",
282 "--name",
283 "zig1",
284 "--zig-lib-dir",
285 b.pathFromRoot("lib"),
286 b.fmt("-femit-bin={s}", .{b.pathFromRoot(zig1_obj_path)}),
287 "-fcompiler-rt",
288 "-lc",
289 });
290 {
291 zig1_obj.addArgs(&.{ "--pkg-begin", "build_options" });
292 zig1_obj.addFileSourceArg(exe_options.getSource());
293 zig1_obj.addArgs(&.{ "--pkg-end", "--pkg-begin", "compiler_rt", zig1_compiler_rt_path, "--pkg-end" });
294 }
295 switch (mode) {
296 .Debug => {},
297 .ReleaseFast => {
298 zig1_obj.addArg("-OReleaseFast");
299 zig1_obj.addArg("--strip");
300 },
301 .ReleaseSafe => {
302 zig1_obj.addArg("-OReleaseSafe");
303 zig1_obj.addArg("--strip");
304 },
305 .ReleaseSmall => {
306 zig1_obj.addArg("-OReleaseSmall");
307 zig1_obj.addArg("--strip");
308 },
309 }
310 if (single_threaded orelse false) {
311 zig1_obj.addArg("-fsingle-threaded");
312 }
313
314 exe.step.dependOn(&zig1_obj.step);
315 exe.addObjectFile(zig1_obj_path);
316259
317 // This is intentionally a dummy path. stage1.zig tries to @import("compiler_rt") in case260 // 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 that261 // of being built by cmake. But when built by zig it's gonna get a compiler_rt so that
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+58-3
...@@ -2,10 +2,53 @@...@@ -2,10 +2,53 @@
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"
8
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 .
649
7# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.50# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.
8$ZIG build -p stage2 -Denable-llvm51$ZIG build -p stage2 -Denable-llvm -Dstatic-llvm -Duse-zig-libcxx
952
10stage2/bin/zig test test/behavior.zig -I test -fLLVM53stage2/bin/zig test test/behavior.zig -I test -fLLVM
11stage2/bin/zig test test/behavior.zig -I test54stage2/bin/zig test test/behavior.zig -I test
...@@ -38,7 +81,7 @@ $ZIG build test-fmt -fqemu -fwasmtime...@@ -38,7 +81,7 @@ $ZIG build test-fmt -fqemu -fwasmtime
38$ZIG build test-stage2 -fqemu -fwasmtime81$ZIG build test-stage2 -fqemu -fwasmtime
3982
40# Produce the experimental std lib documentation.83# Produce the experimental std lib documentation.
41mkdir -p $RELEASE_STAGING/docs/std84mkdir -p "$RELEASE_STAGING/docs/std"
42$ZIG test lib/std/std.zig \85$ZIG test lib/std/std.zig \
43 --zig-lib-dir lib \86 --zig-lib-dir lib \
44 -femit-docs=$RELEASE_STAGING/docs/std \87 -femit-docs=$RELEASE_STAGING/docs/std \
...@@ -47,5 +90,17 @@ $ZIG test lib/std/std.zig \...@@ -47,5 +90,17 @@ $ZIG test lib/std/std.zig \
47# Look for HTML errors.90# Look for HTML errors.
48tidy --drop-empty-elements no -qe zig-cache/langref.html91tidy --drop-empty-elements no -qe zig-cache/langref.html
4992
93# Build release zig.
94$ZIG build
95 --prefix "RELEASE_STAGING" \
96 --search-prefix "$DEPS_LOCAL" \
97 -Denable-llvm \
98 -Dstatic-llvm \
99 -Drelease \
100 -Dstrip \
101 -Duse-zig-libcxx \
102 -Dtarget="$TARGET" \
103 -Dstage1
104
50# Explicit exit helps show last command duration.105# Explicit exit helps show last command duration.
51exit106exit