@@ -167,4 +167,119 @@ for rlib in "${rlib_paths[@]}"; do
167167 fi
168168done
169169
170- true
170+ # Libm tests
171+ flags=()
172+ # We enumerate features manually.
173+ flags+=(--no-default-features)
174+
175+ # Enable arch-specific routines when available.
176+ flags+=(--features arch)
177+
178+ # Always enable `unstable-float` since it expands available API but does not
179+ # change any implementations.
180+ flags+=(--features unstable-float)
181+
182+ # We need to specifically skip tests for musl-math-sys on systems that can't
183+ # build musl since otherwise `--all` will activate it.
184+ case " $target " in
185+ # Can't build at all on MSVC, WASM, or thumb
186+ * windows-msvc* ) flags+=(--exclude musl-math-sys) ;;
187+ * wasm* ) flags+=(--exclude musl-math-sys) ;;
188+ * thumb* ) flags+=(--exclude musl-math-sys) ;;
189+
190+ # We can build musl on MinGW but running tests gets a stack overflow
191+ * windows-gnu* ) ;;
192+ # FIXME(#309): LE PPC crashes calling the musl version of some functions. It
193+ # seems like a qemu bug but should be investigated further at some point.
194+ # See <https://github.com/rust-lang/libm/issues/309>.
195+ * powerpc64le* ) ;;
196+
197+ # Everything else gets musl enabled
198+ * ) flags+=(--features libm-test/build-musl) ;;
199+ esac
200+
201+ # Configure which targets test against MPFR
202+ case " $target " in
203+ # MSVC cannot link MPFR
204+ * windows-msvc* ) ;;
205+ # FIXME: MinGW should be able to build MPFR, but setup in CI is nontrivial.
206+ * windows-gnu* ) ;;
207+ # Targets that aren't cross compiled in CI work fine
208+ aarch64* apple* ) flags+=(--features libm-test/build-mpfr) ;;
209+ aarch64* linux* ) flags+=(--features libm-test/build-mpfr) ;;
210+ i586* ) flags+=(--features libm-test/build-mpfr --features gmp-mpfr-sys/force-cross) ;;
211+ i686* ) flags+=(--features libm-test/build-mpfr) ;;
212+ x86_64* ) flags+=(--features libm-test/build-mpfr) ;;
213+ esac
214+
215+ # FIXME: `STATUS_DLL_NOT_FOUND` testing macros on CI.
216+ # <https://github.com/rust-lang/rust/issues/128944>
217+ case " $target " in
218+ * windows-gnu) flags+=(--exclude libm-macros) ;;
219+ esac
220+
221+ # Make sure we can build with overriding features.
222+ cargo check -p libm --no-default-features
223+
224+ if [ " ${BUILD_ONLY:- } " = " 1" ]; then
225+ # If we are on targets that can't run tests, verify that we can build.
226+ cmd=(cargo build --target $target --package libm)
227+ " ${cmd[@]} "
228+ " ${cmd[@]} " --features unstable-intrinsics
229+
230+ echo " can't run tests on $target ; skipping"
231+ exit
232+ fi
233+
234+ flags+=($flags --all --target " $target " )
235+ cmd=(cargo test " ${flags[@]} " )
236+ profile=" --profile"
237+
238+ # If nextest is available, use that
239+ command -v cargo-nextest && nextest=1 || nextest=0
240+ if [ " $nextest " = " 1" ]; then
241+ # Workaround for https://github.com/nextest-rs/nextest/issues/2066
242+ if [ -f /.dockerenv ]; then
243+ cfg_file=(/tmp/nextest-config.toml)
244+ echo " [store]" >> " $cfg_file "
245+ echo " dir = \" $CARGO_TARGET_DIR /nextest\" " >> " $cfg_file "
246+ cfg_flag=(--config-file $cfg_file )
247+ fi
248+
249+ cmd=(cargo nextest run ${cfg_flag:- } --max-fail=10 $flags )
250+ profile=" --cargo-profile"
251+ fi
252+
253+ # Test once without intrinsics
254+ " ${cmd[@]} "
255+
256+ # Run doctests if they were excluded by nextest
257+ [ " $nextest " = " 1" ] && cargo test --doc $flags
258+
259+ # Exclude the macros and utile crates from the rest of the tests to save CI
260+ # runtime, they shouldn't have anything feature- or opt-level-dependent.
261+ cmd+=(--exclude util --exclude libm-macros)
262+
263+ # Test once with intrinsics enabled
264+ " ${cmd[@]} " --features unstable-intrinsics
265+ " ${cmd[@]} " --features unstable-intrinsics --benches
266+
267+ # Test the same in release mode, which also increases coverage. Also ensure
268+ # the soft float routines are checked.
269+ " ${cmd[@]} " " $profile " release-checked
270+ " ${cmd[@]} " " $profile " release-checked --features force-soft-floats
271+ " ${cmd[@]} " " $profile " release-checked --features unstable-intrinsics
272+ " ${cmd[@]} " " $profile " release-checked --features unstable-intrinsics --benches
273+
274+ # Ensure that the routines do not panic.
275+ #
276+ # `--tests` must be passed because no-panic is only enabled as a dev
277+ # dependency. The `release-opt` profile must be used to enable LTO and a
278+ # single CGU.
279+ ENSURE_NO_PANIC=1 cargo build \
280+ -p libm \
281+ --target " $target " \
282+ --no-default-features \
283+ --features unstable-float \
284+ --tests \
285+ --profile release-opt
0 commit comments