2024-04-15 14:44:39 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2024-04-13 00:42:36 -04:00
|
|
|
set -eux
|
|
|
|
|
|
2024-05-19 05:02:25 -04:00
|
|
|
export RUST_BACKTRACE="${RUST_BACKTRACE:-full}"
|
2025-04-19 03:16:02 +00:00
|
|
|
export NEXTEST_STATUS_LEVEL=all
|
|
|
|
|
|
|
|
|
|
target="${1:-}"
|
2024-05-19 05:02:25 -04:00
|
|
|
|
|
|
|
|
if [ -z "$target" ]; then
|
2024-04-13 00:42:36 -04:00
|
|
|
host_target=$(rustc -vV | awk '/^host/ { print $2 }')
|
|
|
|
|
echo "Defaulted to host target $host_target"
|
|
|
|
|
target="$host_target"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "${USING_CONTAINER_RUSTC:-}" = 1 ]; then
|
|
|
|
|
# Install nonstandard components if we have control of the environment
|
|
|
|
|
rustup target list --installed |
|
|
|
|
|
grep -E "^$target\$" ||
|
|
|
|
|
rustup target add "$target"
|
|
|
|
|
fi
|
2016-09-30 19:04:48 -05:00
|
|
|
|
2016-09-29 18:50:04 -05:00
|
|
|
# Test our implementation
|
2025-04-19 03:16:02 +00:00
|
|
|
if [ "${BUILD_ONLY:-}" = "1" ]; then
|
2024-04-13 00:42:36 -04:00
|
|
|
echo "nothing to do for no_std"
|
2019-04-02 11:44:28 -07:00
|
|
|
else
|
2025-03-18 09:52:53 +00:00
|
|
|
run="cargo test --package builtins-test --no-fail-fast --target $target"
|
2019-04-02 11:44:28 -07:00
|
|
|
$run
|
|
|
|
|
$run --release
|
|
|
|
|
$run --features c
|
|
|
|
|
$run --features c --release
|
2020-11-09 07:24:25 -08:00
|
|
|
$run --features no-asm
|
|
|
|
|
$run --features no-asm --release
|
2024-04-14 08:05:18 +01:00
|
|
|
$run --features no-f16-f128
|
|
|
|
|
$run --features no-f16-f128 --release
|
2024-05-19 05:02:25 -04:00
|
|
|
$run --benches
|
|
|
|
|
$run --benches --release
|
2019-04-02 11:44:28 -07:00
|
|
|
fi
|
2016-09-29 18:50:04 -05:00
|
|
|
|
2024-05-15 11:05:20 -07:00
|
|
|
if [ "${TEST_VERBATIM:-}" = "1" ]; then
|
2025-03-18 09:52:53 +00:00
|
|
|
verb_path=$(cmd.exe //C echo \\\\?\\%cd%\\builtins-test\\target2)
|
|
|
|
|
cargo build --package builtins-test \
|
2024-09-28 19:53:09 -04:00
|
|
|
--target "$target" --target-dir "$verb_path" --features c
|
2024-05-15 10:32:06 -07:00
|
|
|
fi
|
|
|
|
|
|
2024-09-28 19:53:09 -04:00
|
|
|
declare -a rlib_paths
|
|
|
|
|
|
|
|
|
|
# Set the `rlib_paths` global array to a list of all compiler-builtins rlibs
|
|
|
|
|
update_rlib_paths() {
|
|
|
|
|
if [ -d /builtins-target ]; then
|
|
|
|
|
rlib_paths=( /builtins-target/"${target}"/debug/deps/libcompiler_builtins-*.rlib )
|
|
|
|
|
else
|
|
|
|
|
rlib_paths=( target/"${target}"/debug/deps/libcompiler_builtins-*.rlib )
|
|
|
|
|
fi
|
|
|
|
|
}
|
2024-03-24 20:27:38 +00:00
|
|
|
|
|
|
|
|
# Remove any existing artifacts from previous tests that don't set #![compiler_builtins]
|
2024-09-28 19:53:09 -04:00
|
|
|
update_rlib_paths
|
|
|
|
|
rm -f "${rlib_paths[@]}"
|
2024-03-24 20:27:38 +00:00
|
|
|
|
2024-04-13 00:42:36 -04:00
|
|
|
cargo build --target "$target"
|
|
|
|
|
cargo build --target "$target" --release
|
|
|
|
|
cargo build --target "$target" --features c
|
|
|
|
|
cargo build --target "$target" --release --features c
|
|
|
|
|
cargo build --target "$target" --features no-asm
|
|
|
|
|
cargo build --target "$target" --release --features no-asm
|
2024-04-14 08:05:18 +01:00
|
|
|
cargo build --target "$target" --features no-f16-f128
|
|
|
|
|
cargo build --target "$target" --release --features no-f16-f128
|
2019-05-14 12:26:09 -07:00
|
|
|
|
2024-04-15 14:44:39 -04:00
|
|
|
PREFIX=${target//unknown-/}-
|
2024-04-13 00:42:36 -04:00
|
|
|
case "$target" in
|
2016-09-29 18:50:04 -05:00
|
|
|
armv7-*)
|
|
|
|
|
PREFIX=arm-linux-gnueabihf-
|
|
|
|
|
;;
|
|
|
|
|
thumb*)
|
|
|
|
|
PREFIX=arm-none-eabi-
|
|
|
|
|
;;
|
2016-09-29 19:47:44 -05:00
|
|
|
*86*-*)
|
2016-09-29 18:50:04 -05:00
|
|
|
PREFIX=
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2024-04-15 14:44:39 -04:00
|
|
|
NM=$(find "$(rustc --print sysroot)" \( -name llvm-nm -o -name llvm-nm.exe \) )
|
2020-05-29 14:38:29 -05:00
|
|
|
if [ "$NM" = "" ]; then
|
2024-04-13 00:42:36 -04:00
|
|
|
NM="${PREFIX}nm"
|
2020-05-29 14:38:29 -05:00
|
|
|
fi
|
2024-09-28 19:53:09 -04:00
|
|
|
|
2024-03-24 20:27:38 +00:00
|
|
|
# i686-pc-windows-gnu tools have a dependency on some DLLs, so run it with
|
|
|
|
|
# rustup run to ensure that those are in PATH.
|
2024-04-13 00:42:36 -04:00
|
|
|
TOOLCHAIN="$(rustup show active-toolchain | sed 's/ (default)//')"
|
|
|
|
|
if [[ "$TOOLCHAIN" == *i686-pc-windows-gnu ]]; then
|
2024-03-24 20:27:38 +00:00
|
|
|
NM="rustup run $TOOLCHAIN $NM"
|
2016-10-07 14:29:34 -05:00
|
|
|
fi
|
|
|
|
|
|
2017-06-23 11:52:22 -07:00
|
|
|
# Look out for duplicated symbols when we include the compiler-rt (C) implementation
|
2024-09-28 19:53:09 -04:00
|
|
|
update_rlib_paths
|
|
|
|
|
for rlib in "${rlib_paths[@]}"; do
|
2017-06-23 10:44:29 -07:00
|
|
|
set +x
|
2019-05-02 13:35:50 -07:00
|
|
|
echo "================================================================"
|
2024-04-13 00:42:36 -04:00
|
|
|
echo "checking $rlib for duplicate symbols"
|
2019-05-02 13:35:50 -07:00
|
|
|
echo "================================================================"
|
2024-09-28 19:53:09 -04:00
|
|
|
set -x
|
2024-04-15 14:44:39 -04:00
|
|
|
|
|
|
|
|
duplicates_found=0
|
2019-05-02 13:35:50 -07:00
|
|
|
|
2017-06-24 10:12:17 -07:00
|
|
|
# NOTE On i586, It's normal that the get_pc_thunk symbol appears several
|
|
|
|
|
# times so ignore it
|
2024-04-15 14:44:39 -04:00
|
|
|
$NM -g --defined-only "$rlib" 2>&1 |
|
|
|
|
|
sort |
|
|
|
|
|
uniq -d |
|
|
|
|
|
grep -v __x86.get_pc_thunk --quiet |
|
|
|
|
|
grep 'T __' && duplicates_found=1
|
|
|
|
|
|
|
|
|
|
if [ "$duplicates_found" != 0 ]; then
|
|
|
|
|
echo "error: found duplicate symbols"
|
2016-12-30 23:18:17 -05:00
|
|
|
exit 1
|
2024-04-15 14:44:39 -04:00
|
|
|
else
|
|
|
|
|
echo "success; no duplicate symbols found"
|
2016-12-30 23:18:17 -05:00
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
2024-09-28 19:53:09 -04:00
|
|
|
rm -f "${rlib_paths[@]}"
|
2024-04-15 14:44:39 -04:00
|
|
|
|
2025-03-18 10:13:47 +00:00
|
|
|
build_intrinsics_test() {
|
|
|
|
|
cargo build --target "$target" -v --package builtins-test-intrinsics "$@"
|
2024-04-15 14:44:39 -04:00
|
|
|
}
|
2017-06-23 15:16:07 -07:00
|
|
|
|
2025-03-18 10:13:47 +00:00
|
|
|
# Verify that we haven't dropped any intrinsics/symbols
|
|
|
|
|
build_intrinsics_test
|
|
|
|
|
build_intrinsics_test --release
|
|
|
|
|
build_intrinsics_test --features c
|
|
|
|
|
build_intrinsics_test --features c --release
|
2017-06-24 10:04:00 -07:00
|
|
|
|
|
|
|
|
# Verify that there are no undefined symbols to `panic` within our
|
|
|
|
|
# implementations
|
2024-03-24 20:27:38 +00:00
|
|
|
CARGO_PROFILE_DEV_LTO=true \
|
2025-03-18 10:13:47 +00:00
|
|
|
cargo build --target "$target" --package builtins-test-intrinsics
|
2020-04-29 15:30:10 -05:00
|
|
|
CARGO_PROFILE_RELEASE_LTO=true \
|
2025-03-18 10:13:47 +00:00
|
|
|
cargo build --target "$target" --package builtins-test-intrinsics --release
|
2017-06-23 15:16:07 -07:00
|
|
|
|
2024-03-24 20:27:38 +00:00
|
|
|
# Ensure no references to any symbols from core
|
2024-09-28 19:53:09 -04:00
|
|
|
update_rlib_paths
|
|
|
|
|
for rlib in "${rlib_paths[@]}"; do
|
2024-04-13 00:42:36 -04:00
|
|
|
set +x
|
2024-03-24 20:27:38 +00:00
|
|
|
echo "================================================================"
|
2024-04-13 00:42:36 -04:00
|
|
|
echo "checking $rlib for references to core"
|
2024-03-24 20:27:38 +00:00
|
|
|
echo "================================================================"
|
2024-04-13 00:42:36 -04:00
|
|
|
set -x
|
|
|
|
|
|
|
|
|
|
tmpdir="${CARGO_TARGET_DIR:-target}/tmp"
|
|
|
|
|
test -d "$tmpdir" || mkdir "$tmpdir"
|
|
|
|
|
defined="$tmpdir/defined_symbols.txt"
|
|
|
|
|
undefined="$tmpdir/defined_symbols.txt"
|
|
|
|
|
|
2024-04-15 14:44:39 -04:00
|
|
|
$NM --quiet -U "$rlib" | grep 'T _ZN4core' | awk '{print $3}' | sort | uniq > "$defined"
|
|
|
|
|
$NM --quiet -u "$rlib" | grep 'U _ZN4core' | awk '{print $2}' | sort | uniq > "$undefined"
|
|
|
|
|
grep_has_results=0
|
|
|
|
|
grep -v -F -x -f "$defined" "$undefined" && grep_has_results=1
|
2024-04-13 00:42:36 -04:00
|
|
|
|
|
|
|
|
if [ "$target" = "powerpc64-unknown-linux-gnu" ]; then
|
|
|
|
|
echo "FIXME: powerpc64 fails these tests"
|
2024-04-15 14:44:39 -04:00
|
|
|
elif [ "$grep_has_results" != 0 ]; then
|
2024-04-13 00:42:36 -04:00
|
|
|
echo "error: found unexpected references to core"
|
2017-06-23 11:52:22 -07:00
|
|
|
exit 1
|
2024-04-13 00:42:36 -04:00
|
|
|
else
|
|
|
|
|
echo "success; no references to core found"
|
2017-06-23 11:52:22 -07:00
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
2016-12-30 23:18:17 -05:00
|
|
|
true
|