@@ -13,6 +13,11 @@ if [ -z "$target" ]; then
1313 target=" $host_target "
1414fi
1515
16+ if [[ " $target " = * " wasm" * ]]; then
17+ # Enable the random backend
18+ export RUSTFLAGS=" ${RUSTFLAGS:- } --cfg getrandom_backend=\" wasm_js\" "
19+ fi
20+
1621if [ " ${USING_CONTAINER_RUSTC:- } " = 1 ]; then
1722 # Install nonstandard components if we have control of the environment
1823 rustup target list --installed |
2227
2328# Test our implementation
2429if [ " ${BUILD_ONLY:- } " = " 1" ]; then
25- echo " nothing to do for no_std "
30+ echo " no tests to run for build-only targets "
2631else
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
32+ test_builtins=(cargo test --package builtins-test --no-fail-fast --target " $target " )
33+ " ${test_builtins[@]} "
34+ " ${test_builtins[@]} " --release
35+ " ${test_builtins[@]} " --features c
36+ " ${test_builtins[@]} " --features c --release
37+ " ${test_builtins[@]} " --features no-asm
38+ " ${test_builtins[@]} " --features no-asm --release
39+ " ${test_builtins[@]} " --features no-f16-f128
40+ " ${test_builtins[@]} " --features no-f16-f128 --release
41+ " ${test_builtins[@]} " --benches
42+ " ${test_builtins[@]} " --benches --release
3943
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
44+ if [ " ${TEST_VERBATIM:- } " = " 1" ]; then
45+ verb_path=$( cmd.exe //C echo \\\\ ? \\ %cd%\\ builtins-test\\ target2)
46+ " ${test_builtins[@]} " --target-dir " $verb_path " --features c
47+ fi
4448fi
4549
50+
4651declare -a rlib_paths
4752
4853# Set the `rlib_paths` global array to a list of all compiler-builtins rlibs
@@ -61,11 +66,11 @@ rm -f "${rlib_paths[@]}"
6166cargo build -p compiler_builtins --target " $target "
6267cargo build -p compiler_builtins --target " $target " --release
6368cargo build -p compiler_builtins --target " $target " --features c
64- cargo build -p compiler_builtins --target " $target " --release -- features c
69+ cargo build -p compiler_builtins --target " $target " --features c --release
6570cargo build -p compiler_builtins --target " $target " --features no-asm
66- cargo build -p compiler_builtins --target " $target " --release -- features no-asm
71+ cargo build -p compiler_builtins --target " $target " --features no-asm --release
6772cargo build -p compiler_builtins --target " $target " --features no-f16-f128
68- cargo build -p compiler_builtins --target " $target " --release -- features no-f16-f128
73+ cargo build -p compiler_builtins --target " $target " --features no-f16-f128 --release
6974
7075PREFIX=${target// unknown-/ } -
7176case " $target " in
@@ -167,4 +172,124 @@ for rlib in "${rlib_paths[@]}"; do
167172 fi
168173done
169174
170- true
175+ # Test libm
176+
177+ mflags=()
178+
179+ # We enumerate features manually.
180+ mflags+=(--no-default-features)
181+
182+ # Enable arch-specific routines when available.
183+ mflags+=(--features arch)
184+
185+ # Always enable `unstable-float` since it expands available API but does not
186+ # change any implementations.
187+ mflags+=(--features unstable-float)
188+
189+ # We need to specifically skip tests for musl-math-sys on systems that can't
190+ # build musl since otherwise `--all` will activate it.
191+ case " $target " in
192+ # Can't build at all on MSVC, WASM, or thumb
193+ * windows-msvc* ) mflags+=(--exclude musl-math-sys) ;;
194+ * wasm* ) mflags+=(--exclude musl-math-sys) ;;
195+ * thumb* ) mflags+=(--exclude musl-math-sys) ;;
196+
197+ # We can build musl on MinGW but running tests gets a stack overflow
198+ * windows-gnu* ) ;;
199+ # FIXME(#309): LE PPC crashes calling the musl version of some functions. It
200+ # seems like a qemu bug but should be investigated further at some point.
201+ # See <https://github.com/rust-lang/libm/issues/309>.
202+ * powerpc64le* ) ;;
203+
204+ # Everything else gets musl enabled
205+ * ) mflags+=(--features libm-test/build-musl) ;;
206+ esac
207+
208+
209+ # Configure which targets test against MPFR
210+ case " $target " in
211+ # MSVC cannot link MPFR
212+ * windows-msvc* ) ;;
213+ # FIXME: MinGW should be able to build MPFR, but setup in CI is nontrivial.
214+ * windows-gnu* ) ;;
215+ # Targets that aren't cross compiled in CI work fine
216+ aarch64* apple* ) mflags+=(--features libm-test/build-mpfr) ;;
217+ aarch64* linux* ) mflags+=(--features libm-test/build-mpfr) ;;
218+ i586* ) mflags+=(--features libm-test/build-mpfr --features gmp-mpfr-sys/force-cross) ;;
219+ i686* ) mflags+=(--features libm-test/build-mpfr) ;;
220+ x86_64* ) mflags+=(--features libm-test/build-mpfr) ;;
221+ esac
222+
223+ # FIXME: `STATUS_DLL_NOT_FOUND` testing macros on CI.
224+ # <https://github.com/rust-lang/rust/issues/128944>
225+ case " $target " in
226+ * windows-gnu) mflags+=(--exclude libm-macros) ;;
227+ esac
228+
229+ # Make sure a simple build works
230+ cargo check -p libm --no-default-features --target " $target "
231+
232+
233+ if [ " ${BUILD_ONLY:- } " = " 1" ]; then
234+ # If we are on targets that can't run tests, verify that we can build.
235+ cmd=(cargo build --target " $target " --package libm)
236+ " ${cmd[@]} "
237+ " ${cmd[@]} " --features unstable-intrinsics
238+
239+ echo " can't run tests on $target ; skipping"
240+ else
241+ mflags+=(--workspace --target " $target " )
242+ cmd=(cargo test " ${mflags[@]} " )
243+ profile_flag=" --profile"
244+
245+ # If nextest is available, use that
246+ command -v cargo-nextest && nextest=1 || nextest=0
247+ if [ " $nextest " = " 1" ]; then
248+ cmd=(cargo nextest run --max-fail=10)
249+
250+ # Workaround for https://github.com/nextest-rs/nextest/issues/2066
251+ if [ -f /.dockerenv ]; then
252+ cfg_file=" /tmp/nextest-config.toml"
253+ echo " [store]" >> " $cfg_file "
254+ echo " dir = \" $CARGO_TARGET_DIR /nextest\" " >> " $cfg_file "
255+ cmd+=(--config-file " $cfg_file " )
256+ fi
257+
258+ cmd+=(" ${mflags[@]} " )
259+ profile_flag=" --cargo-profile"
260+ fi
261+
262+ # Test once without intrinsics
263+ " ${cmd[@]} "
264+
265+ # Run doctests if they were excluded by nextest
266+ [ " $nextest " = " 1" ] && cargo test --doc --exclude compiler_builtins " ${mflags[@]} "
267+
268+ # Exclude the macros and utile crates from the rest of the tests to save CI
269+ # runtime, they shouldn't have anything feature- or opt-level-dependent.
270+ cmd+=(--exclude util --exclude libm-macros)
271+
272+ # Test once with intrinsics enabled
273+ " ${cmd[@]} " --features unstable-intrinsics
274+ " ${cmd[@]} " --features unstable-intrinsics --benches
275+
276+ # Test the same in release mode, which also increases coverage. Also ensure
277+ # the soft float routines are checked.
278+ " ${cmd[@]} " " $profile_flag " release-checked
279+ " ${cmd[@]} " " $profile_flag " release-checked --features force-soft-floats
280+ " ${cmd[@]} " " $profile_flag " release-checked --features unstable-intrinsics
281+ " ${cmd[@]} " " $profile_flag " release-checked --features unstable-intrinsics --benches
282+
283+ # Ensure that the routines do not panic.
284+ #
285+ # `--tests` must be passed because no-panic is only enabled as a dev
286+ # dependency. The `release-opt` profile must be used to enable LTO and a
287+ # single CGU.
288+ ENSURE_NO_PANIC=1 cargo build \
289+ -p libm \
290+ --target " $target " \
291+ --no-default-features \
292+ --features unstable-float \
293+ --tests \
294+ --profile release-opt
295+ fi
0 commit comments