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 -ex 9 10: "${TOOLCHAIN?The TOOLCHAIN environment variable must be set.}" 11: "${OS?The OS environment variable must be set.}" 12 13RUST=${TOOLCHAIN} 14 15echo "Testing Rust ${RUST} on ${OS}" 16 17if [ "${TOOLCHAIN}" = "nightly" ] ; then 18 rustup component add rust-src 19fi 20 21test_target() { 22 BUILD_CMD="${1}" 23 TARGET="${2}" 24 NO_STD="${3}" 25 26 # If there is a std component, fetch it: 27 if [ "${NO_STD}" != "1" ]; then 28 # FIXME: rustup often fails to download some artifacts due to network 29 # issues, so we retry this N times. 30 N=5 31 n=0 32 until [ $n -ge $N ] 33 do 34 if rustup target add "${TARGET}" --toolchain "${RUST}" ; then 35 break 36 fi 37 n=$((n+1)) 38 sleep 1 39 done 40 fi 41 42 # Test that libc builds without any default features (no std) 43 if [ "${NO_STD}" != "1" ]; then 44 cargo "+${RUST}" "${BUILD_CMD}" -vv --no-default-features --target "${TARGET}" 45 else 46 # FIXME: With `build-std` feature, `compiler_builtins` emits a lof of lint warnings. 47 RUSTFLAGS="-A improper_ctypes_definitions" cargo "+${RUST}" "${BUILD_CMD}" \ 48 -Z build-std=core,alloc -vv --no-default-features --target "${TARGET}" 49 fi 50 # Test that libc builds with default features (e.g. std) 51 # if the target supports std 52 if [ "$NO_STD" != "1" ]; then 53 cargo "+${RUST}" "${BUILD_CMD}" -vv --target "${TARGET}" 54 else 55 RUSTFLAGS="-A improper_ctypes_definitions" cargo "+${RUST}" "${BUILD_CMD}" \ 56 -Z build-std=core,alloc -vv --target "${TARGET}" 57 fi 58 59 # Test that libc builds with the `extra_traits` feature 60 if [ "${NO_STD}" != "1" ]; then 61 cargo "+${RUST}" "${BUILD_CMD}" -vv --no-default-features --target "${TARGET}" \ 62 --features extra_traits 63 else 64 RUSTFLAGS="-A improper_ctypes_definitions" cargo "+${RUST}" "${BUILD_CMD}" \ 65 -Z build-std=core,alloc -vv --no-default-features \ 66 --target "${TARGET}" --features extra_traits 67 fi 68 69 # Test the 'const-extern-fn' feature on nightly 70 if [ "${RUST}" = "nightly" ]; then 71 if [ "${NO_STD}" != "1" ]; then 72 cargo "+${RUST}" "${BUILD_CMD}" -vv --no-default-features --target "${TARGET}" \ 73 --features const-extern-fn 74 else 75 RUSTFLAGS="-A improper_ctypes_definitions" cargo "+${RUST}" "${BUILD_CMD}" \ 76 -Z build-std=core,alloc -vv --no-default-features \ 77 --target "${TARGET}" --features const-extern-fn 78 fi 79 fi 80 81 # Also test that it builds with `extra_traits` and default features: 82 if [ "$NO_STD" != "1" ]; then 83 cargo "+${RUST}" "${BUILD_CMD}" -vv --target "${TARGET}" \ 84 --features extra_traits 85 else 86 RUSTFLAGS="-A improper_ctypes_definitions" cargo "+${RUST}" "${BUILD_CMD}" \ 87 -Z build-std=core,alloc -vv --target "${TARGET}" \ 88 --features extra_traits 89 fi 90} 91 92RUST_LINUX_TARGETS="\ 93aarch64-linux-android \ 94aarch64-unknown-linux-gnu \ 95arm-linux-androideabi \ 96arm-unknown-linux-gnueabi \ 97arm-unknown-linux-gnueabihf \ 98armv7-linux-androideabi \ 99armv7-unknown-linux-gnueabihf \ 100i586-unknown-linux-gnu \ 101i686-linux-android \ 102i686-unknown-freebsd \ 103i686-unknown-linux-gnu \ 104i686-unknown-linux-musl \ 105powerpc-unknown-linux-gnu \ 106powerpc64-unknown-linux-gnu \ 107powerpc64le-unknown-linux-gnu \ 108s390x-unknown-linux-gnu \ 109x86_64-unknown-freebsd \ 110x86_64-unknown-linux-gnu \ 111x86_64-unknown-linux-musl \ 112x86_64-unknown-netbsd \ 113" 114 115RUST_GT_1_13_LINUX_TARGETS="\ 116arm-unknown-linux-musleabi \ 117arm-unknown-linux-musleabihf \ 118armv7-unknown-linux-musleabihf \ 119sparc64-unknown-linux-gnu \ 120wasm32-unknown-emscripten \ 121x86_64-linux-android \ 122" 123RUST_GT_1_19_LINUX_TARGETS="\ 124aarch64-unknown-linux-musl \ 125sparcv9-sun-solaris \ 126wasm32-unknown-unknown \ 127" 128RUST_GT_1_24_LINUX_TARGETS="\ 129i586-unknown-linux-musl \ 130" 131 132RUST_NIGHTLY_LINUX_TARGETS="\ 133aarch64-unknown-fuchsia \ 134armv5te-unknown-linux-gnueabi \ 135armv5te-unknown-linux-musleabi \ 136i686-pc-windows-gnu \ 137riscv64gc-unknown-linux-gnu \ 138wasm32-wasi \ 139x86_64-fortanix-unknown-sgx \ 140x86_64-unknown-fuchsia \ 141x86_64-pc-solaris \ 142x86_64-pc-windows-gnu \ 143x86_64-unknown-illumos \ 144x86_64-unknown-linux-gnux32 \ 145x86_64-unknown-redox \ 146" 147 148RUST_APPLE_TARGETS="\ 149aarch64-apple-ios \ 150x86_64-apple-darwin \ 151x86_64-apple-ios \ 152" 153 154RUST_NIGHTLY_APPLE_TARGETS="\ 155aarch64-apple-darwin \ 156" 157 158# Must start with `x86_64-pc-windows-msvc` first. 159RUST_NIGHTLY_WINDOWS_TARGETS="\ 160x86_64-pc-windows-msvc \ 161x86_64-pc-windows-gnu \ 162i686-pc-windows-msvc \ 163" 164 165# The targets are listed here alphabetically 166TARGETS="" 167case "${OS}" in 168 linux*) 169 TARGETS="${RUST_LINUX_TARGETS}" 170 171 if [ "${RUST}" != "1.13.0" ]; then 172 TARGETS="${TARGETS} ${RUST_GT_1_13_LINUX_TARGETS}" 173 if [ "${RUST}" != "1.19.0" ]; then 174 TARGETS="${TARGETS} ${RUST_GT_1_19_LINUX_TARGETS}" 175 if [ "${RUST}" != "1.24.0" ]; then 176 TARGETS="${TARGETS} ${RUST_GT_1_24_LINUX_TARGETS}" 177 fi 178 fi 179 fi 180 181 if [ "${RUST}" = "nightly" ]; then 182 TARGETS="${TARGETS} ${RUST_NIGHTLY_LINUX_TARGETS}" 183 fi 184 185 ;; 186 macos*) 187 TARGETS="${RUST_APPLE_TARGETS}" 188 189 if [ "${RUST}" = "nightly" ]; then 190 TARGETS="${TARGETS} ${RUST_NIGHTLY_APPLE_TARGETS}" 191 fi 192 193 ;; 194 windows*) 195 TARGETS=${RUST_NIGHTLY_WINDOWS_TARGETS} 196 197 ;; 198 *) 199 ;; 200esac 201 202for TARGET in $TARGETS; do 203 if echo "$TARGET"|grep -q "$FILTER"; then 204 if [ "${OS}" = "windows" ]; then 205 TARGET="$TARGET" sh ./ci/install-rust.sh 206 test_target build "$TARGET" 207 else 208 test_target build "$TARGET" 209 fi 210 fi 211done 212 213# Targets which are not available via rustup and must be built with -Zbuild-std 214RUST_LINUX_NO_CORE_TARGETS="\ 215aarch64-pc-windows-msvc \ 216aarch64-unknown-freebsd \ 217aarch64-unknown-hermit \ 218aarch64-unknown-netbsd \ 219aarch64-unknown-openbsd \ 220aarch64-wrs-vxworks \ 221armebv7r-none-eabi \ 222armebv7r-none-eabihf \ 223armv7-wrs-vxworks-eabihf \ 224armv7r-none-eabi \ 225armv7r-none-eabihf \ 226hexagon-unknown-linux-musl \ 227i586-pc-windows-msvc \ 228i686-pc-windows-msvc \ 229i686-unknown-haiku \ 230i686-unknown-netbsd \ 231i686-unknown-openbsd \ 232i686-wrs-vxworks \ 233mips-unknown-linux-gnu \ 234mips-unknown-linux-musl \ 235mips64-unknown-linux-gnuabi64 \ 236mips64-unknown-linux-muslabi64 \ 237mips64el-unknown-linux-gnuabi64 \ 238mips64el-unknown-linux-muslabi64 \ 239mipsel-unknown-linux-gnu \ 240mipsel-unknown-linux-musl \ 241mipsel-sony-psp \ 242nvptx64-nvidia-cuda \ 243powerpc-unknown-linux-gnuspe \ 244powerpc-unknown-netbsd \ 245powerpc-wrs-vxworks \ 246powerpc-wrs-vxworks-spe \ 247powerpc64-unknown-freebsd \ 248powerpc64-wrs-vxworks \ 249riscv32i-unknown-none-elf \ 250riscv32imac-unknown-none-elf \ 251riscv32imc-unknown-none-elf \ 252riscv32gc-unknown-linux-gnu \ 253riscv64gc-unknown-freebsd \ 254riscv64gc-unknown-hermit \ 255riscv64gc-unknown-linux-musl \ 256riscv64gc-unknown-none-elf \ 257riscv64imac-unknown-none-elf \ 258s390x-unknown-linux-musl \ 259sparc-unknown-linux-gnu \ 260sparc64-unknown-netbsd \ 261 262thumbv6m-none-eabi \ 263thumbv7em-none-eabi \ 264thumbv7em-none-eabihf \ 265thumbv7m-none-eabi \ 266thumbv7neon-linux-androideabi \ 267thumbv7neon-unknown-linux-gnueabihf \ 268thumbv8m.main-none-eabi \ 269x86_64-pc-windows-msvc \ 270x86_64-unknown-dragonfly \ 271x86_64-unknown-haiku \ 272x86_64-unknown-hermit \ 273x86_64-unknown-l4re-uclibc \ 274x86_64-unknown-openbsd \ 275x86_64-wrs-vxworks \ 276" 277 278if [ "${RUST}" = "nightly" ] && [ "${OS}" = "linux" ]; then 279 for TARGET in $RUST_LINUX_NO_CORE_TARGETS; do 280 if echo "$TARGET"|grep -q "$FILTER"; then 281 test_target build "$TARGET" 1 282 fi 283 done 284fi 285 286RUST_APPLE_NO_CORE_TARGETS="\ 287armv7s-apple-ios \ 288i686-apple-darwin \ 289i386-apple-ios \ 290" 291 292if [ "${RUST}" = "nightly" ] && [ "${OS}" = "macos" ]; then 293 for TARGET in $RUST_APPLE_NO_CORE_TARGETS; do 294 if echo "$TARGET" | grep -q "$FILTER"; then 295 test_target build "$TARGET" 1 296 fi 297 done 298fi 299