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 31test_target() { 32 target="${1}" 33 no_dist="${2:-0}" 34 35 RUSTFLAGS="${RUSTFLAGS:-}" 36 37 # The basic command that is run each time 38 cmd="cargo +$rust build --target $target" 39 40 if [ "${no_dist}" != "0" ]; then 41 # If we can't download a `core`, we need to build it 42 cmd="$cmd -Zbuild-std=core,alloc" 43 44 # FIXME: With `build-std` feature, `compiler_builtins` emits a lof of lint warnings. 45 RUSTFLAGS="${RUSTFLAGS:-} -Aimproper_ctypes_definitions" 46 export RUSTFLAGS 47 else 48 # Otherwise it is available for download; fetch it: 49 50 # FIXME: rustup often fails to download some artifacts due to network 51 # issues, so we retry this N times. 52 N=5 53 n=0 54 until [ $n -ge $N ]; do 55 if rustup target add "$target" --toolchain "$rust" ; then 56 break 57 fi 58 n=$((n+1)) 59 sleep 1 60 done 61 fi 62 63 # Test with expected combinations of features 64 $cmd 65 $cmd --features const-extern-fn 66 $cmd --features extra_traits 67 68 # Test again without default features, i.e. without "std" 69 $cmd --no-default-features 70 $cmd --no-default-features --features extra_traits 71} 72 73rust_linux_targets="\ 74aarch64-linux-android \ 75aarch64-unknown-linux-gnu \ 76aarch64-unknown-linux-musl \ 77arm-linux-androideabi \ 78arm-unknown-linux-gnueabi \ 79arm-unknown-linux-gnueabihf \ 80arm-unknown-linux-musleabi \ 81arm-unknown-linux-musleabihf \ 82armv7-linux-androideabi \ 83armv7-unknown-linux-gnueabihf \ 84armv7-unknown-linux-musleabihf \ 85i586-unknown-linux-gnu \ 86i586-unknown-linux-musl \ 87i686-linux-android \ 88i686-unknown-freebsd \ 89i686-unknown-linux-gnu \ 90i686-unknown-linux-musl \ 91powerpc-unknown-linux-gnu \ 92powerpc64-unknown-linux-gnu \ 93powerpc64le-unknown-linux-gnu \ 94s390x-unknown-linux-gnu \ 95sparc64-unknown-linux-gnu \ 96sparcv9-sun-solaris \ 97wasm32-unknown-emscripten \ 98wasm32-unknown-unknown \ 99x86_64-linux-android \ 100x86_64-unknown-freebsd \ 101x86_64-unknown-linux-gnu \ 102x86_64-unknown-linux-musl \ 103x86_64-unknown-netbsd \ 104" 105 106rust_nightly_linux_targets="\ 107aarch64-unknown-fuchsia \ 108armv5te-unknown-linux-gnueabi \ 109armv5te-unknown-linux-musleabi \ 110i686-pc-windows-gnu \ 111riscv64gc-unknown-linux-gnu \ 112x86_64-fortanix-unknown-sgx \ 113x86_64-pc-solaris \ 114x86_64-pc-windows-gnu \ 115x86_64-unknown-fuchsia \ 116x86_64-unknown-illumos \ 117x86_64-unknown-linux-gnux32 \ 118x86_64-unknown-redox \ 119" 120 121rust_apple_targets="\ 122aarch64-apple-darwin \ 123aarch64-apple-ios \ 124x86_64-apple-darwin \ 125x86_64-apple-ios \ 126" 127 128rust_nightly_apple_targets="\ 129" 130 131# Must start with `x86_64-pc-windows-msvc` first. 132rust_nightly_windows_targets="\ 133x86_64-pc-windows-msvc \ 134x86_64-pc-windows-gnu \ 135i686-pc-windows-msvc \ 136" 137 138# Targets which are not available via rustup and must be built with -Zbuild-std 139# FIXME(hexagon): hexagon-unknown-linux-musl should be tested but currently has 140# duplicate symbol errors from `compiler_builtins`. 141rust_linux_no_dist_targets="\ 142aarch64-pc-windows-msvc \ 143aarch64-unknown-freebsd \ 144aarch64-unknown-hermit \ 145aarch64-unknown-netbsd \ 146aarch64-unknown-openbsd \ 147aarch64-wrs-vxworks \ 148armebv7r-none-eabi \ 149armebv7r-none-eabihf \ 150armv7-wrs-vxworks-eabihf \ 151armv7r-none-eabi \ 152armv7r-none-eabihf \ 153i586-pc-windows-msvc \ 154i686-pc-windows-msvc \ 155i686-unknown-haiku \ 156i686-unknown-netbsd \ 157i686-unknown-openbsd \ 158i686-wrs-vxworks \ 159mips-unknown-linux-gnu \ 160mips-unknown-linux-musl \ 161mips64-unknown-linux-gnuabi64 \ 162mips64-unknown-linux-muslabi64 \ 163mips64el-unknown-linux-gnuabi64 \ 164mips64el-unknown-linux-muslabi64 \ 165mipsel-unknown-linux-gnu \ 166mipsel-unknown-linux-musl \ 167mipsel-sony-psp \ 168nvptx64-nvidia-cuda \ 169powerpc-unknown-linux-gnuspe \ 170powerpc-unknown-netbsd \ 171powerpc-wrs-vxworks \ 172powerpc-wrs-vxworks-spe \ 173powerpc64-unknown-freebsd \ 174powerpc64-wrs-vxworks \ 175riscv32i-unknown-none-elf \ 176riscv32imac-unknown-none-elf \ 177riscv32imc-unknown-none-elf \ 178riscv32gc-unknown-linux-gnu \ 179riscv32-wrs-vxworks \ 180riscv64gc-unknown-freebsd \ 181riscv64gc-unknown-hermit \ 182riscv64gc-unknown-linux-musl \ 183riscv64gc-unknown-none-elf \ 184riscv64imac-unknown-none-elf \ 185riscv64-wrs-vxworks \ 186s390x-unknown-linux-musl \ 187sparc-unknown-linux-gnu \ 188sparc64-unknown-netbsd \ 189 190thumbv6m-none-eabi \ 191thumbv7em-none-eabi \ 192thumbv7em-none-eabihf \ 193thumbv7m-none-eabi \ 194thumbv7neon-linux-androideabi \ 195thumbv7neon-unknown-linux-gnueabihf \ 196thumbv8m.main-none-eabi \ 197x86_64-pc-windows-msvc \ 198x86_64-unknown-dragonfly \ 199x86_64-unknown-haiku \ 200x86_64-unknown-hermit \ 201x86_64-unknown-l4re-uclibc \ 202x86_64-unknown-openbsd \ 203x86_64-wrs-vxworks \ 204" 205 206rust_apple_no_dist_targets="\ 207armv7s-apple-ios \ 208i686-apple-darwin \ 209i386-apple-ios \ 210" 211 212# The targets are listed here alphabetically 213if [ "$os" = "linux" ]; then 214 targets="$rust_linux_targets" 215 nightly_targets="$rust_nightly_linux_targets" 216 no_dist_targets="$rust_linux_no_dist_targets" 217elif [ "$os" = "macos" ]; then 218 targets="$rust_apple_targets" 219 nightly_targets="$rust_nightly_apple_targets" 220 no_dist_targets="$rust_apple_no_dist_targets" 221elif [ "$os" = "windows" ]; then 222 targets=${rust_nightly_windows_targets} 223else 224 exit 1 225fi 226 227if [ "$rust" = "nightly" ]; then 228 targets="$targets ${nightly_targets:-}" 229else 230 # build-std requires nightly 231 no_dist_targets="" 232fi 233 234for target in $targets; do 235 if echo "$target" | grep -q "$filter"; then 236 if [ "$os" = "windows" ]; then 237 TARGET="$target" ./ci/install-rust.sh 238 test_target "$target" 239 else 240 test_target "$target" 241 fi 242 243 test_run=1 244 fi 245done 246 247for target in ${no_dist_targets:-}; do 248 if echo "$target" | grep -q "$filter"; then 249 if [ "$os" = "windows" ]; then 250 TARGET="$target" ./ci/install-rust.sh 251 test_target "$target" 1 252 else 253 test_target "$target" 1 254 fi 255 256 test_run=1 257 fi 258done 259 260# Make sure we didn't accidentally filter everything 261if [ "${test_run:-}" != 1 ]; then 262 echo "No tests were run" 263 exit 1 264fi 265