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 # Test again without default features, i.e. without "std" 76 $cmd --no-default-features 77 $cmd --no-default-features --features extra_traits 78 79 # Ensure the crate will build when used with `std` 80 if [ "$rust" = "nightly" ]; then 81 $cmd --no-default-features --features rustc-dep-of-std 82 fi 83 84 # For tier 2 freebsd targets, check with the different versions we support 85 # if on nightly or stable 86 case "$rust-$target" in 87 stable-x86_64-*freebsd*) do_freebsd_checks=1 ;; 88 nightly-i686*freebsd*) do_freebsd_checks=1 ;; 89 esac 90 91 if [ -n "${do_freebsd_checks:-}" ]; then 92 for version in $freebsd_versions; do 93 export RUST_LIBC_UNSTABLE_FREEBSD_VERSION="$version" 94 $cmd 95 $cmd --no-default-features 96 done 97 fi 98} 99 100freebsd_versions="\ 10111 \ 10212 \ 10313 \ 10414 \ 10515 \ 106" 107 108rust_linux_targets="\ 109aarch64-linux-android \ 110aarch64-unknown-linux-gnu \ 111aarch64-unknown-linux-musl \ 112arm-linux-androideabi \ 113arm-unknown-linux-gnueabi \ 114arm-unknown-linux-gnueabihf \ 115arm-unknown-linux-musleabi \ 116arm-unknown-linux-musleabihf \ 117armv7-linux-androideabi \ 118armv7-unknown-linux-gnueabihf \ 119armv7-unknown-linux-musleabihf \ 120i586-unknown-linux-gnu \ 121i586-unknown-linux-musl \ 122i686-linux-android \ 123i686-unknown-freebsd \ 124i686-unknown-linux-gnu \ 125i686-unknown-linux-musl \ 126powerpc-unknown-linux-gnu \ 127powerpc64-unknown-linux-gnu \ 128powerpc64le-unknown-linux-gnu \ 129s390x-unknown-linux-gnu \ 130sparc64-unknown-linux-gnu \ 131sparcv9-sun-solaris \ 132wasm32-unknown-emscripten \ 133wasm32-unknown-unknown \ 134wasm32-wasip1 \ 135wasm32-wasip2 \ 136x86_64-linux-android \ 137x86_64-unknown-freebsd \ 138x86_64-unknown-linux-gnu \ 139x86_64-unknown-linux-musl \ 140x86_64-unknown-netbsd \ 141" 142 143rust_nightly_linux_targets="\ 144aarch64-unknown-fuchsia \ 145armv5te-unknown-linux-gnueabi \ 146armv5te-unknown-linux-musleabi \ 147i686-pc-windows-gnu \ 148riscv64gc-unknown-linux-gnu \ 149x86_64-fortanix-unknown-sgx \ 150x86_64-pc-solaris \ 151x86_64-pc-windows-gnu \ 152x86_64-unknown-fuchsia \ 153x86_64-unknown-illumos \ 154x86_64-unknown-linux-gnux32 \ 155x86_64-unknown-redox \ 156" 157 158rust_apple_targets="\ 159aarch64-apple-darwin \ 160aarch64-apple-ios \ 161x86_64-apple-darwin \ 162x86_64-apple-ios \ 163" 164 165rust_nightly_apple_targets="\ 166" 167 168# Must start with `x86_64-pc-windows-msvc` first. 169rust_nightly_windows_targets="\ 170x86_64-pc-windows-msvc \ 171x86_64-pc-windows-gnu \ 172i686-pc-windows-msvc \ 173" 174 175# Targets which are not available via rustup and must be built with -Zbuild-std 176# FIXME(hexagon): hexagon-unknown-linux-musl should be tested but currently has 177# duplicate symbol errors from `compiler_builtins`. 178rust_linux_no_dist_targets="\ 179aarch64-pc-windows-msvc \ 180aarch64-unknown-freebsd \ 181aarch64-unknown-hermit \ 182aarch64-unknown-netbsd \ 183aarch64-unknown-openbsd \ 184aarch64-wrs-vxworks \ 185armebv7r-none-eabi \ 186armebv7r-none-eabihf \ 187armv7-wrs-vxworks-eabihf \ 188armv7r-none-eabi \ 189armv7r-none-eabihf \ 190i586-pc-windows-msvc \ 191i686-pc-windows-msvc \ 192i686-unknown-haiku \ 193i686-unknown-netbsd \ 194i686-unknown-openbsd \ 195i686-wrs-vxworks \ 196mips-unknown-linux-gnu \ 197mips-unknown-linux-musl \ 198mips64-unknown-linux-gnuabi64 \ 199mips64-unknown-linux-muslabi64 \ 200mips64el-unknown-linux-gnuabi64 \ 201mips64el-unknown-linux-muslabi64 \ 202mipsel-unknown-linux-gnu \ 203mipsel-unknown-linux-musl \ 204mipsel-sony-psp \ 205nvptx64-nvidia-cuda \ 206powerpc-unknown-linux-gnuspe \ 207powerpc-unknown-netbsd \ 208powerpc-wrs-vxworks \ 209powerpc-wrs-vxworks-spe \ 210powerpc64-unknown-freebsd \ 211powerpc64-wrs-vxworks \ 212riscv32i-unknown-none-elf \ 213riscv32imac-unknown-none-elf \ 214riscv32imc-unknown-none-elf \ 215riscv32gc-unknown-linux-gnu \ 216riscv32-wrs-vxworks \ 217riscv64gc-unknown-freebsd \ 218riscv64gc-unknown-hermit \ 219riscv64gc-unknown-linux-musl \ 220riscv64gc-unknown-none-elf \ 221riscv64imac-unknown-none-elf \ 222riscv64-wrs-vxworks \ 223s390x-unknown-linux-musl \ 224sparc-unknown-linux-gnu \ 225sparc64-unknown-netbsd \ 226 227thumbv6m-none-eabi \ 228thumbv7em-none-eabi \ 229thumbv7em-none-eabihf \ 230thumbv7m-none-eabi \ 231thumbv7neon-linux-androideabi \ 232thumbv7neon-unknown-linux-gnueabihf \ 233thumbv8m.main-none-eabi \ 234x86_64-pc-windows-msvc \ 235x86_64-unknown-dragonfly \ 236x86_64-unknown-haiku \ 237x86_64-unknown-hermit \ 238x86_64-unknown-l4re-uclibc \ 239x86_64-unknown-openbsd \ 240x86_64-wrs-vxworks \ 241" 242 243rust_apple_no_dist_targets="\ 244armv7s-apple-ios \ 245i686-apple-darwin \ 246i386-apple-ios \ 247" 248 249# The targets are listed here alphabetically 250if [ "$os" = "linux" ]; then 251 targets="$rust_linux_targets" 252 nightly_targets="$rust_nightly_linux_targets" 253 no_dist_targets="$rust_linux_no_dist_targets" 254elif [ "$os" = "macos" ]; then 255 targets="$rust_apple_targets" 256 nightly_targets="$rust_nightly_apple_targets" 257 no_dist_targets="$rust_apple_no_dist_targets" 258elif [ "$os" = "windows" ]; then 259 targets=${rust_nightly_windows_targets} 260else 261 exit 1 262fi 263 264if [ "$rust" = "nightly" ]; then 265 targets="$targets ${nightly_targets:-}" 266else 267 # build-std requires nightly 268 no_dist_targets="" 269fi 270 271case "$rust" in 272 "stable") supports_wasi_pn=1 ;; 273 "beta") supports_wasi_pn=1 ;; 274 "nightly") supports_wasi_pn=1 ;; 275 *) supports_wasi_pn=0 ;; 276esac 277 278some_tests_run=0 279 280# Apply the `FILTER` variable, do OS-specific tasks, and run a target 281filter_and_run() { 282 target="$1" 283 no_dist="${2:-0}" 284 285 if echo "$target" | grep -q "$filter"; then 286 if [ "$os" = "windows" ]; then 287 TARGET="$target" ./ci/install-rust.sh 288 fi 289 290 # `wasm32-wasip1` was renamed from `wasm32-wasi` 291 if [ "$target" = "wasm32-wasip1" ] && [ "$supports_wasi_pn" = "0" ]; then 292 target="wasm32-wasi" 293 fi 294 295 # `wasm32-wasip2` only exists in recent versions of Rust 296 if [ "$target" = "wasm32-wasip2" ] && [ "$supports_wasi_pn" = "0" ]; then 297 return 298 fi 299 300 test_target "$target" "$no_dist" 301 some_tests_run=1 302 fi 303} 304 305for target in $targets; do 306 echo_if_ci "::group::Target: $target" 307 filter_and_run "$target" 308 echo_if_ci "::endgroup::" 309done 310 311for target in ${no_dist_targets:-}; do 312 echo_if_ci "::group::Target: $target" 313 filter_and_run "$target" 1 314 echo_if_ci "::endgroup::" 315done 316 317# Make sure we didn't accidentally filter everything 318if [ "$some_tests_run" != 1 ]; then 319 echo "No tests were run" 320 exit 1 321fi 322