2222
2323# Test our implementation
2424if [ " ${BUILD_ONLY:- } " = " 1" ]; then
25- echo " nothing to do for no_std "
25+ echo " no tests to run for build-only targets "
2626else
27- run=" cargo test --package builtins-test --no-fail-fast --target $target "
28- $run
29- $run --release
30- $run --features c
31- $run --features c --release
32- $run --features no-asm
33- $run --features no-asm --release
34- $run --features no-f16-f128
35- $run --features no-f16-f128 --release
36- $run --benches
37- $run --benches --release
38- fi
27+ test_builtins=(cargo test --package builtins-test --no-fail-fast --target " $target " )
28+ " ${test_builtins[@]} "
29+ " ${test_builtins[@]} " --release
30+ " ${test_builtins[@]} " --features c
31+ " ${test_builtins[@]} " --features c --release
32+ " ${test_builtins[@]} " --features no-asm
33+ " ${test_builtins[@]} " --features no-asm --release
34+ " ${test_builtins[@]} " --features no-f16-f128
35+ " ${test_builtins[@]} " --features no-f16-f128 --release
36+ " ${test_builtins[@]} " --benches
37+ " ${test_builtins[@]} " --benches --release
3938
40- if [ " ${TEST_VERBATIM:- } " = " 1" ]; then
41- verb_path=$( cmd.exe //C echo \\\\ ? \\ %cd%\\ builtins-test\\ target2)
42- cargo build --package builtins-test \
43- --target " $target " --target-dir " $verb_path " --features c
39+ if [ " ${TEST_VERBATIM:- } " = " 1" ]; then
40+ verb_path=$( cmd.exe //C echo \\\\ ? \\ %cd%\\ builtins-test\\ target2)
41+ " ${test_builtins[@]} " --target-dir " $verb_path " --features c
42+ fi
4443fi
4544
45+
4646declare -a rlib_paths
4747
4848# Set the `rlib_paths` global array to a list of all compiler-builtins rlibs
@@ -61,11 +61,131 @@ rm -f "${rlib_paths[@]}"
6161cargo build -p compiler_builtins --target " $target "
6262cargo build -p compiler_builtins --target " $target " --release
6363cargo build -p compiler_builtins --target " $target " --features c
64- cargo build -p compiler_builtins --target " $target " --release -- features c
64+ cargo build -p compiler_builtins --target " $target " --features c --release
6565cargo build -p compiler_builtins --target " $target " --features no-asm
66- cargo build -p compiler_builtins --target " $target " --release -- features no-asm
66+ cargo build -p compiler_builtins --target " $target " --features no-asm --release
6767cargo build -p compiler_builtins --target " $target " --features no-f16-f128
68- cargo build -p compiler_builtins --target " $target " --release --features no-f16-f128
68+ cargo build -p compiler_builtins --target " $target " --features no-f16-f128 --release
69+
70+ mflags=()
71+
72+ # We enumerate features manually.
73+ mflags+=(--no-default-features)
74+
75+ # Enable arch-specific routines when available.
76+ mflags+=(--features arch)
77+
78+ # Always enable `unstable-float` since it expands available API but does not
79+ # change any implementations.
80+ mflags+=(--features unstable-float)
81+
82+ # We need to specifically skip tests for musl-math-sys on systems that can't
83+ # build musl since otherwise `--all` will activate it.
84+ case " $target " in
85+ # Can't build at all on MSVC, WASM, or thumb
86+ * windows-msvc* ) mflags+=(--exclude musl-math-sys) ;;
87+ * wasm* ) mflags+=(--exclude musl-math-sys) ;;
88+ * thumb* ) mflags+=(--exclude musl-math-sys) ;;
89+
90+ # We can build musl on MinGW but running tests gets a stack overflow
91+ * windows-gnu* ) ;;
92+ # FIXME(#309): LE PPC crashes calling the musl version of some functions. It
93+ # seems like a qemu bug but should be investigated further at some point.
94+ # See <https://github.com/rust-lang/libm/issues/309>.
95+ * powerpc64le* ) ;;
96+
97+ # Everything else gets musl enabled
98+ * ) mflags+=(--features libm-test/build-musl) ;;
99+ esac
100+
101+
102+ # Configure which targets test against MPFR
103+ case " $target " in
104+ # MSVC cannot link MPFR
105+ * windows-msvc* ) ;;
106+ # FIXME: MinGW should be able to build MPFR, but setup in CI is nontrivial.
107+ * windows-gnu* ) ;;
108+ # Targets that aren't cross compiled in CI work fine
109+ aarch64* apple* ) mflags+=(--features libm-test/build-mpfr) ;;
110+ aarch64* linux* ) mflags+=(--features libm-test/build-mpfr) ;;
111+ i586* ) mflags+=(--features libm-test/build-mpfr --features gmp-mpfr-sys/force-cross) ;;
112+ i686* ) mflags+=(--features libm-test/build-mpfr) ;;
113+ x86_64* ) mflags+=(--features libm-test/build-mpfr) ;;
114+ esac
115+
116+ # FIXME: `STATUS_DLL_NOT_FOUND` testing macros on CI.
117+ # <https://github.com/rust-lang/rust/issues/128944>
118+ case " $target " in
119+ * windows-gnu) mflags+=(--exclude libm-macros) ;;
120+ esac
121+
122+ # Make sure a simple build works
123+ cargo check -p libm --no-default-features --target " $target "
124+
125+
126+ if [ " ${BUILD_ONLY:- } " = " 1" ]; then
127+ # If we are on targets that can't run tests, verify that we can build.
128+ cmd=(cargo build --target " $target " --package libm)
129+ " ${cmd[@]} "
130+ " ${cmd[@]} " --features unstable-intrinsics
131+
132+ echo " can't run tests on $target ; skipping"
133+ else
134+ mflags+=(--all --target " $target " )
135+ cmd=(cargo test " ${mflags[@]} " )
136+ profile=" --profile"
137+
138+ # If nextest is available, use that
139+ command -v cargo-nextest && nextest=1 || nextest=0
140+ if [ " $nextest " = " 1" ]; then
141+ cfg_flags=()
142+ # Workaround for https://github.com/nextest-rs/nextest/issues/2066
143+ if [ -f /.dockerenv ]; then
144+ cfg_file=" /tmp/nextest-config.toml"
145+ echo " [store]" >> " $cfg_file "
146+ echo " dir = \" $CARGO_TARGET_DIR /nextest\" " >> " $cfg_file "
147+ cfg_flags=(--config-file " $cfg_file " )
148+ fi
149+
150+ cmd=(cargo nextest run " ${cfg_flags[@]} " --max-fail=10 " ${mflags[@]} " )
151+ profile=" --cargo-profile"
152+ fi
153+
154+ # Test once without intrinsics
155+ " ${cmd[@]} "
156+
157+ # Run doctests if they were excluded by nextest
158+ [ " $nextest " = " 1" ] && cargo test --doc " ${mflags[@]} "
159+
160+ # Exclude the macros and utile crates from the rest of the tests to save CI
161+ # runtime, they shouldn't have anything feature- or opt-level-dependent.
162+ cmd+=(--exclude util --exclude libm-macros)
163+
164+ # Test once with intrinsics enabled
165+ " ${cmd[@]} " --features unstable-intrinsics
166+ " ${cmd[@]} " --features unstable-intrinsics --benches
167+
168+ # Test the same in release mode, which also increases coverage. Also ensure
169+ # the soft float routines are checked.
170+ " ${cmd[@]} " " $profile " release-checked
171+ " ${cmd[@]} " " $profile " release-checked --features force-soft-floats
172+ " ${cmd[@]} " " $profile " release-checked --features unstable-intrinsics
173+ " ${cmd[@]} " " $profile " release-checked --features unstable-intrinsics --benches
174+
175+ # Ensure that the routines do not panic.
176+ #
177+ # `--tests` must be passed because no-panic is only enabled as a dev
178+ # dependency. The `release-opt` profile must be used to enable LTO and a
179+ # single CGU.
180+ ENSURE_NO_PANIC=1 cargo build \
181+ -p libm \
182+ --target " $target " \
183+ --no-default-features \
184+ --features unstable-float \
185+ --tests \
186+ --profile release-opt
187+ fi
188+
69189
70190PREFIX=${target// unknown-/ } -
71191case " $target " in
0 commit comments