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 libstd) 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. libstd) 51 # if the target supports libstd 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 \ 105mips-unknown-linux-gnu \ 106mips-unknown-linux-musl \ 107mips64-unknown-linux-gnuabi64 \ 108mips64el-unknown-linux-gnuabi64 \ 109mipsel-unknown-linux-gnu \ 110mipsel-unknown-linux-musl \ 111powerpc-unknown-linux-gnu \ 112powerpc64-unknown-linux-gnu \ 113powerpc64le-unknown-linux-gnu \ 114s390x-unknown-linux-gnu \ 115x86_64-unknown-freebsd \ 116x86_64-unknown-linux-gnu \ 117x86_64-unknown-linux-musl \ 118x86_64-unknown-netbsd \ 119" 120 121RUST_GT_1_13_LINUX_TARGETS="\ 122arm-unknown-linux-musleabi \ 123arm-unknown-linux-musleabihf \ 124armv7-unknown-linux-musleabihf \ 125sparc64-unknown-linux-gnu \ 126wasm32-unknown-emscripten \ 127x86_64-linux-android \ 128" 129RUST_GT_1_19_LINUX_TARGETS="\ 130aarch64-unknown-linux-musl \ 131sparcv9-sun-solaris \ 132wasm32-unknown-unknown \ 133" 134RUST_GT_1_24_LINUX_TARGETS="\ 135i586-unknown-linux-musl \ 136" 137 138RUST_NIGHTLY_LINUX_TARGETS="\ 139aarch64-fuchsia \ 140armv5te-unknown-linux-gnueabi \ 141armv5te-unknown-linux-musleabi \ 142i686-pc-windows-gnu \ 143riscv64gc-unknown-linux-gnu \ 144wasm32-wasi \ 145x86_64-fortanix-unknown-sgx \ 146x86_64-fuchsia \ 147x86_64-pc-solaris \ 148x86_64-pc-windows-gnu \ 149x86_64-unknown-illumos \ 150x86_64-unknown-linux-gnux32 \ 151x86_64-unknown-redox \ 152" 153 154RUST_APPLE_TARGETS="\ 155aarch64-apple-ios \ 156x86_64-apple-darwin \ 157x86_64-apple-ios \ 158" 159 160RUST_NIGHTLY_APPLE_TARGETS="\ 161aarch64-apple-darwin \ 162" 163 164# Must start with `x86_64-pc-windows-msvc` first. 165RUST_NIGHTLY_WINDOWS_TARGETS="\ 166x86_64-pc-windows-msvc \ 167x86_64-pc-windows-gnu \ 168i686-pc-windows-msvc \ 169" 170 171# The targets are listed here alphabetically 172TARGETS="" 173case "${OS}" in 174 linux*) 175 TARGETS="${RUST_LINUX_TARGETS}" 176 177 if [ "${RUST}" != "1.13.0" ]; then 178 TARGETS="${TARGETS} ${RUST_GT_1_13_LINUX_TARGETS}" 179 if [ "${RUST}" != "1.19.0" ]; then 180 TARGETS="${TARGETS} ${RUST_GT_1_19_LINUX_TARGETS}" 181 if [ "${RUST}" != "1.24.0" ]; then 182 TARGETS="${TARGETS} ${RUST_GT_1_24_LINUX_TARGETS}" 183 fi 184 fi 185 fi 186 187 if [ "${RUST}" = "nightly" ]; then 188 TARGETS="${TARGETS} ${RUST_NIGHTLY_LINUX_TARGETS}" 189 fi 190 191 ;; 192 macos*) 193 TARGETS="${RUST_APPLE_TARGETS}" 194 195 if [ "${RUST}" = "nightly" ]; then 196 TARGETS="${TARGETS} ${RUST_NIGHTLY_APPLE_TARGETS}" 197 fi 198 199 ;; 200 windows*) 201 TARGETS=${RUST_NIGHTLY_WINDOWS_TARGETS} 202 203 ;; 204 *) 205 ;; 206esac 207 208for TARGET in $TARGETS; do 209 if echo "$TARGET"|grep -q "$FILTER"; then 210 if [ "${OS}" = "windows" ]; then 211 TARGET="$TARGET" sh ./ci/install-rust.sh 212 test_target build "$TARGET" 213 else 214 test_target build "$TARGET" 215 fi 216 fi 217done 218 219# Targets which are not available via rustup and must be built with -Zbuild-std 220RUST_LINUX_NO_CORE_TARGETS="\ 221aarch64-pc-windows-msvc \ 222aarch64-unknown-freebsd \ 223aarch64-unknown-hermit \ 224aarch64-unknown-netbsd \ 225aarch64-unknown-openbsd \ 226aarch64-wrs-vxworks \ 227armebv7r-none-eabi \ 228armebv7r-none-eabihf \ 229armv7-wrs-vxworks-eabihf \ 230armv7r-none-eabi \ 231armv7r-none-eabihf \ 232hexagon-unknown-linux-musl \ 233i586-pc-windows-msvc \ 234i686-pc-windows-msvc \ 235i686-unknown-haiku \ 236i686-unknown-netbsd \ 237i686-unknown-openbsd \ 238i686-wrs-vxworks \ 239mipsel-sony-psp \ 240mips64-unknown-linux-muslabi64 \ 241mips64el-unknown-linux-muslabi64 \ 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-linux-musl \ 255riscv64gc-unknown-none-elf \ 256riscv64imac-unknown-none-elf \ 257s390x-unknown-linux-musl \ 258sparc-unknown-linux-gnu \ 259sparc64-unknown-netbsd \ 260 261thumbv6m-none-eabi \ 262thumbv7em-none-eabi \ 263thumbv7em-none-eabihf \ 264thumbv7m-none-eabi \ 265thumbv7neon-linux-androideabi \ 266thumbv7neon-unknown-linux-gnueabihf \ 267thumbv8m.main-none-eabi \ 268x86_64-pc-windows-msvc \ 269x86_64-unknown-dragonfly \ 270x86_64-unknown-haiku \ 271x86_64-unknown-hermit \ 272x86_64-unknown-l4re-uclibc \ 273x86_64-unknown-openbsd \ 274x86_64-wrs-vxworks \ 275" 276 277if [ "${RUST}" = "nightly" ] && [ "${OS}" = "linux" ]; then 278 for TARGET in $RUST_LINUX_NO_CORE_TARGETS; do 279 if echo "$TARGET"|grep -q "$FILTER"; then 280 test_target build "$TARGET" 1 281 fi 282 done 283fi 284 285RUST_APPLE_NO_CORE_TARGETS="\ 286armv7-apple-ios \ 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