12add0d91Sopenharmony_ci#!/usr/bin/env sh 22add0d91Sopenharmony_ci 32add0d91Sopenharmony_ci# Checks that libc builds properly for all supported targets on a particular 42add0d91Sopenharmony_ci# Rust version: 52add0d91Sopenharmony_ci# The FILTER environment variable can be used to select which target(s) to build. 62add0d91Sopenharmony_ci# For example: set FILTER to vxworks to select the targets that has vxworks in name 72add0d91Sopenharmony_ci 82add0d91Sopenharmony_ciset -ex 92add0d91Sopenharmony_ci 102add0d91Sopenharmony_ci: "${TOOLCHAIN?The TOOLCHAIN environment variable must be set.}" 112add0d91Sopenharmony_ci: "${OS?The OS environment variable must be set.}" 122add0d91Sopenharmony_ci 132add0d91Sopenharmony_ciRUST=${TOOLCHAIN} 142add0d91Sopenharmony_ci 152add0d91Sopenharmony_ciecho "Testing Rust ${RUST} on ${OS}" 162add0d91Sopenharmony_ci 172add0d91Sopenharmony_ciif [ "${TOOLCHAIN}" = "nightly" ] ; then 182add0d91Sopenharmony_ci rustup component add rust-src 192add0d91Sopenharmony_cifi 202add0d91Sopenharmony_ci 212add0d91Sopenharmony_citest_target() { 222add0d91Sopenharmony_ci BUILD_CMD="${1}" 232add0d91Sopenharmony_ci TARGET="${2}" 242add0d91Sopenharmony_ci NO_STD="${3}" 252add0d91Sopenharmony_ci 262add0d91Sopenharmony_ci # If there is a std component, fetch it: 272add0d91Sopenharmony_ci if [ "${NO_STD}" != "1" ]; then 282add0d91Sopenharmony_ci # FIXME: rustup often fails to download some artifacts due to network 292add0d91Sopenharmony_ci # issues, so we retry this N times. 302add0d91Sopenharmony_ci N=5 312add0d91Sopenharmony_ci n=0 322add0d91Sopenharmony_ci until [ $n -ge $N ] 332add0d91Sopenharmony_ci do 342add0d91Sopenharmony_ci if rustup target add "${TARGET}" --toolchain "${RUST}" ; then 352add0d91Sopenharmony_ci break 362add0d91Sopenharmony_ci fi 372add0d91Sopenharmony_ci n=$((n+1)) 382add0d91Sopenharmony_ci sleep 1 392add0d91Sopenharmony_ci done 402add0d91Sopenharmony_ci fi 412add0d91Sopenharmony_ci 422add0d91Sopenharmony_ci # Test that libc builds without any default features (no libstd) 432add0d91Sopenharmony_ci if [ "${NO_STD}" != "1" ]; then 442add0d91Sopenharmony_ci cargo "+${RUST}" "${BUILD_CMD}" -vv --no-default-features --target "${TARGET}" 452add0d91Sopenharmony_ci else 462add0d91Sopenharmony_ci # FIXME: With `build-std` feature, `compiler_builtins` emits a lof of lint warnings. 472add0d91Sopenharmony_ci RUSTFLAGS="-A improper_ctypes_definitions" cargo "+${RUST}" "${BUILD_CMD}" \ 482add0d91Sopenharmony_ci -Z build-std=core,alloc -vv --no-default-features --target "${TARGET}" 492add0d91Sopenharmony_ci fi 502add0d91Sopenharmony_ci # Test that libc builds with default features (e.g. libstd) 512add0d91Sopenharmony_ci # if the target supports libstd 522add0d91Sopenharmony_ci if [ "$NO_STD" != "1" ]; then 532add0d91Sopenharmony_ci cargo "+${RUST}" "${BUILD_CMD}" -vv --target "${TARGET}" 542add0d91Sopenharmony_ci else 552add0d91Sopenharmony_ci RUSTFLAGS="-A improper_ctypes_definitions" cargo "+${RUST}" "${BUILD_CMD}" \ 562add0d91Sopenharmony_ci -Z build-std=core,alloc -vv --target "${TARGET}" 572add0d91Sopenharmony_ci fi 582add0d91Sopenharmony_ci 592add0d91Sopenharmony_ci # Test that libc builds with the `extra_traits` feature 602add0d91Sopenharmony_ci if [ "${NO_STD}" != "1" ]; then 612add0d91Sopenharmony_ci cargo "+${RUST}" "${BUILD_CMD}" -vv --no-default-features --target "${TARGET}" \ 622add0d91Sopenharmony_ci --features extra_traits 632add0d91Sopenharmony_ci else 642add0d91Sopenharmony_ci RUSTFLAGS="-A improper_ctypes_definitions" cargo "+${RUST}" "${BUILD_CMD}" \ 652add0d91Sopenharmony_ci -Z build-std=core,alloc -vv --no-default-features \ 662add0d91Sopenharmony_ci --target "${TARGET}" --features extra_traits 672add0d91Sopenharmony_ci fi 682add0d91Sopenharmony_ci 692add0d91Sopenharmony_ci # Test the 'const-extern-fn' feature on nightly 702add0d91Sopenharmony_ci if [ "${RUST}" = "nightly" ]; then 712add0d91Sopenharmony_ci if [ "${NO_STD}" != "1" ]; then 722add0d91Sopenharmony_ci cargo "+${RUST}" "${BUILD_CMD}" -vv --no-default-features --target "${TARGET}" \ 732add0d91Sopenharmony_ci --features const-extern-fn 742add0d91Sopenharmony_ci else 752add0d91Sopenharmony_ci RUSTFLAGS="-A improper_ctypes_definitions" cargo "+${RUST}" "${BUILD_CMD}" \ 762add0d91Sopenharmony_ci -Z build-std=core,alloc -vv --no-default-features \ 772add0d91Sopenharmony_ci --target "${TARGET}" --features const-extern-fn 782add0d91Sopenharmony_ci fi 792add0d91Sopenharmony_ci fi 802add0d91Sopenharmony_ci 812add0d91Sopenharmony_ci # Also test that it builds with `extra_traits` and default features: 822add0d91Sopenharmony_ci if [ "$NO_STD" != "1" ]; then 832add0d91Sopenharmony_ci cargo "+${RUST}" "${BUILD_CMD}" -vv --target "${TARGET}" \ 842add0d91Sopenharmony_ci --features extra_traits 852add0d91Sopenharmony_ci else 862add0d91Sopenharmony_ci RUSTFLAGS="-A improper_ctypes_definitions" cargo "+${RUST}" "${BUILD_CMD}" \ 872add0d91Sopenharmony_ci -Z build-std=core,alloc -vv --target "${TARGET}" \ 882add0d91Sopenharmony_ci --features extra_traits 892add0d91Sopenharmony_ci fi 902add0d91Sopenharmony_ci} 912add0d91Sopenharmony_ci 922add0d91Sopenharmony_ciRUST_LINUX_TARGETS="\ 932add0d91Sopenharmony_ciaarch64-linux-android \ 942add0d91Sopenharmony_ciaarch64-unknown-linux-gnu \ 952add0d91Sopenharmony_ciarm-linux-androideabi \ 962add0d91Sopenharmony_ciarm-unknown-linux-gnueabi \ 972add0d91Sopenharmony_ciarm-unknown-linux-gnueabihf \ 982add0d91Sopenharmony_ciarmv7-linux-androideabi \ 992add0d91Sopenharmony_ciarmv7-unknown-linux-gnueabihf \ 1002add0d91Sopenharmony_cii586-unknown-linux-gnu \ 1012add0d91Sopenharmony_cii686-linux-android \ 1022add0d91Sopenharmony_cii686-unknown-freebsd \ 1032add0d91Sopenharmony_cii686-unknown-linux-gnu \ 1042add0d91Sopenharmony_cii686-unknown-linux-musl \ 1052add0d91Sopenharmony_cimips-unknown-linux-gnu \ 1062add0d91Sopenharmony_cimips-unknown-linux-musl \ 1072add0d91Sopenharmony_cimips64-unknown-linux-gnuabi64 \ 1082add0d91Sopenharmony_cimips64el-unknown-linux-gnuabi64 \ 1092add0d91Sopenharmony_cimipsel-unknown-linux-gnu \ 1102add0d91Sopenharmony_cimipsel-unknown-linux-musl \ 1112add0d91Sopenharmony_cipowerpc-unknown-linux-gnu \ 1122add0d91Sopenharmony_cipowerpc64-unknown-linux-gnu \ 1132add0d91Sopenharmony_cipowerpc64le-unknown-linux-gnu \ 1142add0d91Sopenharmony_cis390x-unknown-linux-gnu \ 1152add0d91Sopenharmony_cix86_64-unknown-freebsd \ 1162add0d91Sopenharmony_cix86_64-unknown-linux-gnu \ 1172add0d91Sopenharmony_cix86_64-unknown-linux-musl \ 1182add0d91Sopenharmony_cix86_64-unknown-netbsd \ 1192add0d91Sopenharmony_ci" 1202add0d91Sopenharmony_ci 1212add0d91Sopenharmony_ciRUST_GT_1_13_LINUX_TARGETS="\ 1222add0d91Sopenharmony_ciarm-unknown-linux-musleabi \ 1232add0d91Sopenharmony_ciarm-unknown-linux-musleabihf \ 1242add0d91Sopenharmony_ciarmv7-unknown-linux-musleabihf \ 1252add0d91Sopenharmony_cisparc64-unknown-linux-gnu \ 1262add0d91Sopenharmony_ciwasm32-unknown-emscripten \ 1272add0d91Sopenharmony_cix86_64-linux-android \ 1282add0d91Sopenharmony_ci" 1292add0d91Sopenharmony_ciRUST_GT_1_19_LINUX_TARGETS="\ 1302add0d91Sopenharmony_ciaarch64-unknown-linux-musl \ 1312add0d91Sopenharmony_cisparcv9-sun-solaris \ 1322add0d91Sopenharmony_ciwasm32-unknown-unknown \ 1332add0d91Sopenharmony_ci" 1342add0d91Sopenharmony_ciRUST_GT_1_24_LINUX_TARGETS="\ 1352add0d91Sopenharmony_cii586-unknown-linux-musl \ 1362add0d91Sopenharmony_ci" 1372add0d91Sopenharmony_ci 1382add0d91Sopenharmony_ciRUST_NIGHTLY_LINUX_TARGETS="\ 1392add0d91Sopenharmony_ciaarch64-fuchsia \ 1402add0d91Sopenharmony_ciarmv5te-unknown-linux-gnueabi \ 1412add0d91Sopenharmony_ciarmv5te-unknown-linux-musleabi \ 1422add0d91Sopenharmony_cii686-pc-windows-gnu \ 1432add0d91Sopenharmony_ciriscv64gc-unknown-linux-gnu \ 1442add0d91Sopenharmony_ciwasm32-wasi \ 1452add0d91Sopenharmony_cix86_64-fortanix-unknown-sgx \ 1462add0d91Sopenharmony_cix86_64-fuchsia \ 1472add0d91Sopenharmony_cix86_64-pc-solaris \ 1482add0d91Sopenharmony_cix86_64-pc-windows-gnu \ 1492add0d91Sopenharmony_cix86_64-unknown-illumos \ 1502add0d91Sopenharmony_cix86_64-unknown-linux-gnux32 \ 1512add0d91Sopenharmony_cix86_64-unknown-redox \ 1522add0d91Sopenharmony_ci" 1532add0d91Sopenharmony_ci 1542add0d91Sopenharmony_ciRUST_APPLE_TARGETS="\ 1552add0d91Sopenharmony_ciaarch64-apple-ios \ 1562add0d91Sopenharmony_cix86_64-apple-darwin \ 1572add0d91Sopenharmony_cix86_64-apple-ios \ 1582add0d91Sopenharmony_ci" 1592add0d91Sopenharmony_ci 1602add0d91Sopenharmony_ciRUST_NIGHTLY_APPLE_TARGETS="\ 1612add0d91Sopenharmony_ciaarch64-apple-darwin \ 1622add0d91Sopenharmony_ci" 1632add0d91Sopenharmony_ci 1642add0d91Sopenharmony_ci# Must start with `x86_64-pc-windows-msvc` first. 1652add0d91Sopenharmony_ciRUST_NIGHTLY_WINDOWS_TARGETS="\ 1662add0d91Sopenharmony_cix86_64-pc-windows-msvc \ 1672add0d91Sopenharmony_cix86_64-pc-windows-gnu \ 1682add0d91Sopenharmony_cii686-pc-windows-msvc \ 1692add0d91Sopenharmony_ci" 1702add0d91Sopenharmony_ci 1712add0d91Sopenharmony_ci# The targets are listed here alphabetically 1722add0d91Sopenharmony_ciTARGETS="" 1732add0d91Sopenharmony_cicase "${OS}" in 1742add0d91Sopenharmony_ci linux*) 1752add0d91Sopenharmony_ci TARGETS="${RUST_LINUX_TARGETS}" 1762add0d91Sopenharmony_ci 1772add0d91Sopenharmony_ci if [ "${RUST}" != "1.13.0" ]; then 1782add0d91Sopenharmony_ci TARGETS="${TARGETS} ${RUST_GT_1_13_LINUX_TARGETS}" 1792add0d91Sopenharmony_ci if [ "${RUST}" != "1.19.0" ]; then 1802add0d91Sopenharmony_ci TARGETS="${TARGETS} ${RUST_GT_1_19_LINUX_TARGETS}" 1812add0d91Sopenharmony_ci if [ "${RUST}" != "1.24.0" ]; then 1822add0d91Sopenharmony_ci TARGETS="${TARGETS} ${RUST_GT_1_24_LINUX_TARGETS}" 1832add0d91Sopenharmony_ci fi 1842add0d91Sopenharmony_ci fi 1852add0d91Sopenharmony_ci fi 1862add0d91Sopenharmony_ci 1872add0d91Sopenharmony_ci if [ "${RUST}" = "nightly" ]; then 1882add0d91Sopenharmony_ci TARGETS="${TARGETS} ${RUST_NIGHTLY_LINUX_TARGETS}" 1892add0d91Sopenharmony_ci fi 1902add0d91Sopenharmony_ci 1912add0d91Sopenharmony_ci ;; 1922add0d91Sopenharmony_ci macos*) 1932add0d91Sopenharmony_ci TARGETS="${RUST_APPLE_TARGETS}" 1942add0d91Sopenharmony_ci 1952add0d91Sopenharmony_ci if [ "${RUST}" = "nightly" ]; then 1962add0d91Sopenharmony_ci TARGETS="${TARGETS} ${RUST_NIGHTLY_APPLE_TARGETS}" 1972add0d91Sopenharmony_ci fi 1982add0d91Sopenharmony_ci 1992add0d91Sopenharmony_ci ;; 2002add0d91Sopenharmony_ci windows*) 2012add0d91Sopenharmony_ci TARGETS=${RUST_NIGHTLY_WINDOWS_TARGETS} 2022add0d91Sopenharmony_ci 2032add0d91Sopenharmony_ci ;; 2042add0d91Sopenharmony_ci *) 2052add0d91Sopenharmony_ci ;; 2062add0d91Sopenharmony_ciesac 2072add0d91Sopenharmony_ci 2082add0d91Sopenharmony_cifor TARGET in $TARGETS; do 2092add0d91Sopenharmony_ci if echo "$TARGET"|grep -q "$FILTER"; then 2102add0d91Sopenharmony_ci if [ "${OS}" = "windows" ]; then 2112add0d91Sopenharmony_ci TARGET="$TARGET" sh ./ci/install-rust.sh 2122add0d91Sopenharmony_ci test_target build "$TARGET" 2132add0d91Sopenharmony_ci else 2142add0d91Sopenharmony_ci test_target build "$TARGET" 2152add0d91Sopenharmony_ci fi 2162add0d91Sopenharmony_ci fi 2172add0d91Sopenharmony_cidone 2182add0d91Sopenharmony_ci 2192add0d91Sopenharmony_ci# Targets which are not available via rustup and must be built with -Zbuild-std 2202add0d91Sopenharmony_ciRUST_LINUX_NO_CORE_TARGETS="\ 2212add0d91Sopenharmony_ciaarch64-pc-windows-msvc \ 2222add0d91Sopenharmony_ciaarch64-unknown-freebsd \ 2232add0d91Sopenharmony_ciaarch64-unknown-hermit \ 2242add0d91Sopenharmony_ciaarch64-unknown-netbsd \ 2252add0d91Sopenharmony_ciaarch64-unknown-openbsd \ 2262add0d91Sopenharmony_ciaarch64-wrs-vxworks \ 2272add0d91Sopenharmony_ciarmebv7r-none-eabi \ 2282add0d91Sopenharmony_ciarmebv7r-none-eabihf \ 2292add0d91Sopenharmony_ciarmv7-wrs-vxworks-eabihf \ 2302add0d91Sopenharmony_ciarmv7r-none-eabi \ 2312add0d91Sopenharmony_ciarmv7r-none-eabihf \ 2322add0d91Sopenharmony_cihexagon-unknown-linux-musl \ 2332add0d91Sopenharmony_cii586-pc-windows-msvc \ 2342add0d91Sopenharmony_cii686-pc-windows-msvc \ 2352add0d91Sopenharmony_cii686-unknown-haiku \ 2362add0d91Sopenharmony_cii686-unknown-netbsd \ 2372add0d91Sopenharmony_cii686-unknown-openbsd \ 2382add0d91Sopenharmony_cii686-wrs-vxworks \ 2392add0d91Sopenharmony_cimipsel-sony-psp \ 2402add0d91Sopenharmony_cimips64-unknown-linux-muslabi64 \ 2412add0d91Sopenharmony_cimips64el-unknown-linux-muslabi64 \ 2422add0d91Sopenharmony_cinvptx64-nvidia-cuda \ 2432add0d91Sopenharmony_cipowerpc-unknown-linux-gnuspe \ 2442add0d91Sopenharmony_cipowerpc-unknown-netbsd \ 2452add0d91Sopenharmony_cipowerpc-wrs-vxworks \ 2462add0d91Sopenharmony_cipowerpc-wrs-vxworks-spe \ 2472add0d91Sopenharmony_cipowerpc64-unknown-freebsd \ 2482add0d91Sopenharmony_cipowerpc64-wrs-vxworks \ 2492add0d91Sopenharmony_ciriscv32i-unknown-none-elf \ 2502add0d91Sopenharmony_ciriscv32imac-unknown-none-elf \ 2512add0d91Sopenharmony_ciriscv32imc-unknown-none-elf \ 2522add0d91Sopenharmony_ciriscv32gc-unknown-linux-gnu \ 2532add0d91Sopenharmony_ciriscv64gc-unknown-freebsd \ 2542add0d91Sopenharmony_ciriscv64gc-unknown-linux-musl \ 2552add0d91Sopenharmony_ciriscv64gc-unknown-none-elf \ 2562add0d91Sopenharmony_ciriscv64imac-unknown-none-elf \ 2572add0d91Sopenharmony_cis390x-unknown-linux-musl \ 2582add0d91Sopenharmony_cisparc-unknown-linux-gnu \ 2592add0d91Sopenharmony_cisparc64-unknown-netbsd \ 2602add0d91Sopenharmony_ci 2612add0d91Sopenharmony_cithumbv6m-none-eabi \ 2622add0d91Sopenharmony_cithumbv7em-none-eabi \ 2632add0d91Sopenharmony_cithumbv7em-none-eabihf \ 2642add0d91Sopenharmony_cithumbv7m-none-eabi \ 2652add0d91Sopenharmony_cithumbv7neon-linux-androideabi \ 2662add0d91Sopenharmony_cithumbv7neon-unknown-linux-gnueabihf \ 2672add0d91Sopenharmony_cithumbv8m.main-none-eabi \ 2682add0d91Sopenharmony_cix86_64-pc-windows-msvc \ 2692add0d91Sopenharmony_cix86_64-unknown-dragonfly \ 2702add0d91Sopenharmony_cix86_64-unknown-haiku \ 2712add0d91Sopenharmony_cix86_64-unknown-hermit \ 2722add0d91Sopenharmony_cix86_64-unknown-l4re-uclibc \ 2732add0d91Sopenharmony_cix86_64-unknown-openbsd \ 2742add0d91Sopenharmony_cix86_64-wrs-vxworks \ 2752add0d91Sopenharmony_ci" 2762add0d91Sopenharmony_ci 2772add0d91Sopenharmony_ciif [ "${RUST}" = "nightly" ] && [ "${OS}" = "linux" ]; then 2782add0d91Sopenharmony_ci for TARGET in $RUST_LINUX_NO_CORE_TARGETS; do 2792add0d91Sopenharmony_ci if echo "$TARGET"|grep -q "$FILTER"; then 2802add0d91Sopenharmony_ci test_target build "$TARGET" 1 2812add0d91Sopenharmony_ci fi 2822add0d91Sopenharmony_ci done 2832add0d91Sopenharmony_cifi 2842add0d91Sopenharmony_ci 2852add0d91Sopenharmony_ciRUST_APPLE_NO_CORE_TARGETS="\ 2862add0d91Sopenharmony_ciarmv7-apple-ios \ 2872add0d91Sopenharmony_ciarmv7s-apple-ios \ 2882add0d91Sopenharmony_cii686-apple-darwin \ 2892add0d91Sopenharmony_cii386-apple-ios \ 2902add0d91Sopenharmony_ci" 2912add0d91Sopenharmony_ci 2922add0d91Sopenharmony_ciif [ "${RUST}" = "nightly" ] && [ "${OS}" = "macos" ]; then 2932add0d91Sopenharmony_ci for TARGET in $RUST_APPLE_NO_CORE_TARGETS; do 2942add0d91Sopenharmony_ci if echo "$TARGET" | grep -q "$FILTER"; then 2952add0d91Sopenharmony_ci test_target build "$TARGET" 1 2962add0d91Sopenharmony_ci fi 2972add0d91Sopenharmony_ci done 2982add0d91Sopenharmony_cifi 299