1#!/bin/sh
2
3# Requires cmake ninja-build
4
5set -x
6set -e
7
8TARGET="riscv64-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
14# Override the cache directories because they won't actually help other CI runs
15# which will be testing alternate versions of zig, and ultimately would just
16# fill up space on the hard drive for no reason.
17export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
18export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
19
20mkdir build-release
21cd build-release
22
23export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
24export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
25
26cmake .. \
27 -DCMAKE_INSTALL_PREFIX="stage3-release" \
28 -DCMAKE_PREFIX_PATH="$PREFIX" \
29 -DCMAKE_BUILD_TYPE=Release \
30 -DZIG_TARGET_TRIPLE="$TARGET" \
31 -DZIG_TARGET_MCPU="$MCPU" \
32 -DZIG_STATIC=ON \
33 -DZIG_NO_LIB=ON \
34 -GNinja
35
36# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
37# so that installation and testing do not get affected by them.
38unset CC
39unset CXX
40
41ninja install
42
43# Must be done after zig cc is finished.
44export ZIG_LIB_DIR="$PWD/../lib"
45
46# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
47stage3-release/bin/zig build test docs \
48 --maxrss ${ZSF_MAX_RSS:-0} \
49 -Dstatic-llvm \
50 -Dskip-non-native \
51 -Dtarget=native-native-musl \
52 --search-prefix "$PREFIX" \
53 --test-timeout 4m
54
55# Ensure that stage3 and stage4 are byte-for-byte identical.
56stage3-release/bin/zig build \
57 --prefix stage4-release \
58 -Denable-llvm \
59 -Dno-lib \
60 -Doptimize=ReleaseFast \
61 -Dstrip \
62 -Dtarget=$TARGET \
63 -Duse-zig-libcxx \
64 -Dversion-string="$(stage3-release/bin/zig version)"
65
66echo "If the following command fails, it means nondeterminism has been"
67echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
68diff stage3-release/bin/zig stage4-release/bin/zig