1#!/bin/sh
2
3# Requires cc cmake ninja-build
4
5set -x
6set -e
7
8TARGET="x86_64-linux-musl"
9MCPU="baseline"
10CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.17.0-dev.203+073889523"
11PREFIX="$HOME/deps/$CACHE_BASENAME"
12ZIG="$PREFIX/bin/zig"
13
14export PATH="$HOME/deps/wasmtime-v46.0.1-x86_64-linux:$HOME/deps/qemu-linux-x86_64-11.1.1/bin:$HOME/local/bin:$PATH"
15
16# Override the cache directories because they won't actually help other CI runs
17# which will be testing alternate versions of zig, and ultimately would just
18# fill up space on the hard drive for no reason.
19export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
20export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
21
22# Test building from source without LLVM.
23cc -o bootstrap bootstrap.c
24./bootstrap
25./zig2 build -Dno-lib
26./zig-out/bin/zig test test/behavior.zig
27
28mkdir build-release
29cd build-release
30
31export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
32export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
33
34cmake .. \
35 -DCMAKE_INSTALL_PREFIX="stage3-release" \
36 -DCMAKE_PREFIX_PATH="$PREFIX" \
37 -DCMAKE_BUILD_TYPE=Release \
38 -DZIG_TARGET_TRIPLE="$TARGET" \
39 -DZIG_TARGET_MCPU="$MCPU" \
40 -DZIG_STATIC=ON \
41 -DZIG_NO_LIB=ON \
42 -GNinja
43
44# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
45# so that installation and testing do not get affected by them.
46unset CC
47unset CXX
48
49ninja install
50
51# Must not be set while using the other `zig cc` which has its own zig lib dir.
52export ZIG_LIB_DIR="$PWD/../lib"
53
54# Covers several things:
55# 1. building the compiler without LLVM
56# 2. 32-bit
57# 3. arm
58stage3-release/bin/zig build \
59 -Dtarget=arm-linux-musleabihf \
60 -Dno-lib
61
62stage3-release/bin/zig build test docs \
63 --maxrss ${ZSF_MAX_RSS:-0} \
64 -Dlldb=$HOME/deps/lldb-zig/Release-7c1090fd46/bin/lldb \
65 -Dlibc-test-path=$HOME/deps/libc-test-b95fe84 \
66 -fqemu \
67 --libc-runtimes $HOME/deps/glibc-2.43-musl-1.2.5 \
68 -fwasmtime \
69 -Dstatic-llvm \
70 -Dtarget=native-native-musl \
71 --search-prefix "$PREFIX" \
72 -Denable-superhtml \
73 --test-timeout 12m
74
75# Ensure that the fuzzer at least compiles.
76stage3-release/bin/zig build test-std --fuzz=1K -Dno-lib -Dfuzz-only -Doptimize=ReleaseSafe
77stage3-release/bin/zig build test-std --fuzz=1K -Dno-lib -Dfuzz-only -Doptimize=Debug
78
79# Ensure that stage3 and stage4 are byte-for-byte identical.
80stage3-release/bin/zig build \
81 --prefix stage4-release \
82 -Denable-llvm \
83 -Dno-lib \
84 -Doptimize=ReleaseFast \
85 -Dstrip \
86 -Dtarget=$TARGET \
87 -Duse-zig-libcxx \
88 -Dversion-string="$(stage3-release/bin/zig version)"
89
90echo "If the following command fails, it means nondeterminism has been"
91echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
92diff stage3-release/bin/zig stage4-release/bin/zig
93
94# Ensure that updating the wasm binary from this commit will result in a viable build.
95stage3-release/bin/zig build update-zig1
96
97mkdir ../build-new
98cd ../build-new
99
100export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
101export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
102unset ZIG_LIB_DIR
103
104cmake .. \
105 -DCMAKE_PREFIX_PATH="$PREFIX" \
106 -DCMAKE_BUILD_TYPE=Release \
107 -DZIG_TARGET_TRIPLE="$TARGET" \
108 -DZIG_TARGET_MCPU="$MCPU" \
109 -DZIG_STATIC=ON \
110 -DZIG_NO_LIB=ON \
111 -GNinja \
112 -DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
113 -DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
114# https://github.com/ziglang/zig/issues/22213
115
116unset CC
117unset CXX
118
119ninja install
120
121export ZIG_LIB_DIR="$PWD/../lib"
122
123stage3/bin/zig test ../test/behavior.zig
124stage3/bin/zig build -p stage4 \
125 -Dstatic-llvm \
126 -Dtarget=native-native-musl \
127 -Dno-lib \
128 --search-prefix "$PREFIX"
129stage4/bin/zig test ../test/behavior.zig