xref: /rust-libc-0.2.174/ci/verify-build.sh (revision 52035e1c)
1#!/usr/bin/env sh
2
3# Checks that libc builds properly for all supported targets on a particular
4# Rust version:
5# The FILTER environment variable can be used to select which target(s) to build.
6# For example: set FILTER to vxworks to select the targets that has vxworks in name
7
8set -eux
9
10: "${TOOLCHAIN?The TOOLCHAIN environment variable must be set.}"
11
12rust="$TOOLCHAIN"
13filter="${FILTER:-}"
14
15case "$(uname -s)" in
16    Linux*)     os=linux ;;
17    Darwin*)    os=macos ;;
18    MINGW*)     os=windows ;;
19    *)
20        echo "Unknown system $(uname -s)"
21        exit 1
22        ;;
23esac
24
25echo "Testing Rust $rust on $os"
26
27if [ "$TOOLCHAIN" = "nightly" ] ; then
28    rustup component add rust-src
29fi
30
31# Print GHA workflow commands
32echo_if_ci() {
33    # Discard stderr so the "set -x" trace doesn't show up
34    { [ -n "${CI:-}" ] && echo "$1"; } 2> /dev/null
35}
36
37# Run the tests for a specific target
38test_target() {
39    target="$1"
40    no_dist="$2"
41
42    RUSTFLAGS="${RUSTFLAGS:-}"
43
44    # The basic command that is run each time
45    cmd="cargo +$rust build --target $target"
46
47    if [ "${no_dist}" != "0" ]; then
48        # If we can't download a `core`, we need to build it
49        cmd="$cmd -Zbuild-std=core,alloc"
50
51        # FIXME: With `build-std` feature, `compiler_builtins` emits a lof of lint warnings.
52        RUSTFLAGS="${RUSTFLAGS:-} -Aimproper_ctypes_definitions"
53        export RUSTFLAGS
54    else
55        # Otherwise it is available for download; fetch it:
56
57        # FIXME: rustup often fails to download some artifacts due to network
58        # issues, so we retry this N times.
59        N=5
60        n=0
61        until [ $n -ge $N ]; do
62            if rustup target add "$target" --toolchain "$rust" ; then
63                break
64            fi
65            n=$((n+1))
66            sleep 1
67        done
68    fi
69
70    # Test with expected combinations of features
71    $cmd
72    $cmd --features const-extern-fn
73    $cmd --features extra_traits
74
75    if [ "$os" = "linux" ]; then
76        # Test with the equivalent of __USE_TIME_BITS64
77        RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64=1 $cmd
78        case "$target" in
79            arm*-gnu*|i*86*-gnu|powerpc-*-gnu*|mips*-gnu|sparc-*-gnu|thumb-*gnu*)
80                # Test with the equivalent of _FILE_OFFSET_BITS=64
81                RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS=64 $cmd
82                # Test with the equivalent of _TIME_BITS=64
83                RUST_LIBC_UNSTABLE_GNU_TIME_BITS=64 $cmd
84                ;;
85        esac
86    fi
87
88    # Test again without default features, i.e. without "std"
89    $cmd --no-default-features
90    $cmd --no-default-features --features extra_traits
91
92    # Ensure the crate will build when used with `std`
93    if [ "$rust" = "nightly" ]; then
94        $cmd --no-default-features --features rustc-dep-of-std
95    fi
96
97    # For tier 2 freebsd targets, check with the different versions we support
98    # if on nightly or stable
99    case "$rust-$target" in
100        stable-x86_64-*freebsd*) do_freebsd_checks=1 ;;
101        nightly-i686*freebsd*) do_freebsd_checks=1 ;;
102    esac
103
104    if [ -n "${do_freebsd_checks:-}" ]; then
105        for version in $freebsd_versions; do
106            export RUST_LIBC_UNSTABLE_FREEBSD_VERSION="$version"
107            $cmd
108            $cmd --no-default-features
109        done
110    fi
111}
112
113freebsd_versions="\
11411 \
11512 \
11613 \
11714 \
11815 \
119"
120
121rust_linux_targets="\
122aarch64-linux-android \
123aarch64-unknown-linux-gnu \
124aarch64-unknown-linux-musl \
125arm-linux-androideabi \
126arm-unknown-linux-gnueabi \
127arm-unknown-linux-gnueabihf \
128arm-unknown-linux-musleabi \
129arm-unknown-linux-musleabihf \
130armv7-linux-androideabi \
131armv7-unknown-linux-gnueabihf \
132armv7-unknown-linux-musleabihf \
133i586-unknown-linux-gnu \
134i586-unknown-linux-musl \
135i686-linux-android \
136i686-unknown-freebsd \
137i686-unknown-linux-gnu \
138i686-unknown-linux-musl \
139powerpc-unknown-linux-gnu \
140powerpc64-unknown-linux-gnu \
141powerpc64le-unknown-linux-gnu \
142s390x-unknown-linux-gnu \
143sparc64-unknown-linux-gnu \
144sparcv9-sun-solaris \
145wasm32-unknown-emscripten \
146wasm32-unknown-unknown \
147wasm32-wasip1 \
148wasm32-wasip2 \
149x86_64-linux-android \
150x86_64-unknown-freebsd \
151x86_64-unknown-linux-gnu \
152x86_64-unknown-linux-musl \
153x86_64-unknown-netbsd \
154"
155
156rust_nightly_linux_targets="\
157aarch64-unknown-fuchsia \
158armv5te-unknown-linux-gnueabi \
159armv5te-unknown-linux-musleabi \
160i686-pc-windows-gnu \
161riscv64gc-unknown-linux-gnu \
162x86_64-fortanix-unknown-sgx \
163x86_64-pc-solaris \
164x86_64-pc-windows-gnu \
165x86_64-unknown-fuchsia \
166x86_64-unknown-illumos \
167x86_64-unknown-linux-gnux32 \
168x86_64-unknown-redox \
169"
170
171rust_apple_targets="\
172aarch64-apple-darwin \
173aarch64-apple-ios \
174x86_64-apple-darwin \
175x86_64-apple-ios \
176"
177
178rust_nightly_apple_targets="\
179"
180
181# Must start with `x86_64-pc-windows-msvc` first.
182rust_nightly_windows_targets="\
183x86_64-pc-windows-msvc \
184x86_64-pc-windows-gnu \
185i686-pc-windows-msvc \
186"
187
188# Targets which are not available via rustup and must be built with -Zbuild-std
189# FIXME(hexagon): hexagon-unknown-linux-musl should be tested but currently has
190# duplicate symbol errors from `compiler_builtins`.
191rust_linux_no_dist_targets="\
192aarch64-pc-windows-msvc \
193aarch64-unknown-freebsd \
194aarch64-unknown-hermit \
195aarch64-unknown-netbsd \
196aarch64-unknown-openbsd \
197aarch64-wrs-vxworks \
198armebv7r-none-eabi \
199armebv7r-none-eabihf \
200armv7-wrs-vxworks-eabihf \
201armv7r-none-eabi \
202armv7r-none-eabihf \
203i686-pc-windows-msvc \
204i686-unknown-haiku \
205i686-unknown-netbsd \
206i686-unknown-openbsd \
207i686-wrs-vxworks \
208mips-unknown-linux-gnu \
209mips-unknown-linux-musl \
210mips64-unknown-linux-gnuabi64 \
211mips64-unknown-linux-muslabi64 \
212mips64el-unknown-linux-gnuabi64 \
213mips64el-unknown-linux-muslabi64 \
214mipsel-unknown-linux-gnu \
215mipsel-unknown-linux-musl \
216mipsel-sony-psp \
217nvptx64-nvidia-cuda \
218powerpc-unknown-linux-gnuspe \
219powerpc-unknown-netbsd \
220powerpc-wrs-vxworks \
221powerpc-wrs-vxworks-spe \
222powerpc64-unknown-freebsd \
223powerpc64-wrs-vxworks \
224riscv32i-unknown-none-elf \
225riscv32imac-unknown-none-elf \
226riscv32imc-unknown-none-elf \
227riscv32gc-unknown-linux-gnu \
228riscv32-wrs-vxworks \
229riscv64gc-unknown-freebsd \
230riscv64gc-unknown-hermit \
231riscv64gc-unknown-linux-musl \
232riscv64gc-unknown-none-elf \
233riscv64imac-unknown-none-elf \
234riscv64-wrs-vxworks \
235s390x-unknown-linux-musl \
236sparc-unknown-linux-gnu \
237sparc64-unknown-netbsd \
238
239thumbv6m-none-eabi \
240thumbv7em-none-eabi \
241thumbv7em-none-eabihf \
242thumbv7m-none-eabi \
243thumbv7neon-linux-androideabi \
244thumbv7neon-unknown-linux-gnueabihf \
245thumbv8m.main-none-eabi \
246x86_64-pc-windows-msvc \
247x86_64-unknown-dragonfly \
248x86_64-unknown-haiku \
249x86_64-unknown-hermit \
250x86_64-unknown-l4re-uclibc \
251x86_64-unknown-openbsd \
252x86_64-wrs-vxworks \
253"
254
255rust_apple_no_dist_targets="\
256armv7s-apple-ios \
257i686-apple-darwin \
258i386-apple-ios \
259"
260
261# The targets are listed here alphabetically
262if [ "$os" = "linux" ]; then
263    targets="$rust_linux_targets"
264    nightly_targets="$rust_nightly_linux_targets"
265    no_dist_targets="$rust_linux_no_dist_targets"
266elif [ "$os" = "macos" ]; then
267    targets="$rust_apple_targets"
268    nightly_targets="$rust_nightly_apple_targets"
269    no_dist_targets="$rust_apple_no_dist_targets"
270elif [ "$os" = "windows" ]; then
271    targets=${rust_nightly_windows_targets}
272else
273    exit 1
274fi
275
276if [ "$rust" = "nightly" ]; then
277    targets="$targets ${nightly_targets:-}"
278else
279    # build-std requires nightly
280    no_dist_targets=""
281fi
282
283case "$rust" in
284    "stable") supports_wasi_pn=1 ;;
285    "beta") supports_wasi_pn=1 ;;
286    "nightly") supports_wasi_pn=1 ;;
287    *) supports_wasi_pn=0 ;;
288esac
289
290some_tests_run=0
291
292# Apply the `FILTER` variable, do OS-specific tasks, and run a target
293filter_and_run() {
294    target="$1"
295    no_dist="${2:-0}"
296
297    if echo "$target" | grep -q "$filter"; then
298        if [ "$os" = "windows" ]; then
299            TARGET="$target" ./ci/install-rust.sh
300        fi
301
302        # `wasm32-wasip1` was renamed from `wasm32-wasi`
303        if [ "$target" = "wasm32-wasip1" ] && [ "$supports_wasi_pn" = "0" ]; then
304            target="wasm32-wasi"
305        fi
306
307        # `wasm32-wasip2` only exists in recent versions of Rust
308        if [ "$target" = "wasm32-wasip2" ] && [ "$supports_wasi_pn" = "0" ]; then
309            return
310        fi
311
312        test_target "$target" "$no_dist"
313        some_tests_run=1
314    fi
315}
316
317for target in $targets; do
318    echo_if_ci "::group::Target: $target"
319    filter_and_run "$target"
320    echo_if_ci "::endgroup::"
321done
322
323for target in ${no_dist_targets:-}; do
324    echo_if_ci "::group::Target: $target"
325    filter_and_run "$target" 1
326    echo_if_ci "::endgroup::"
327done
328
329# Make sure we didn't accidentally filter everything
330if [ "$some_tests_run" != 1 ]; then
331    echo "No tests were run"
332    exit 1
333fi
334