Skip to content

Commit f4a4e93

Browse files
committed
ci: Enable testing of libm crates
Update `run.sh` to start testing `libm`. Currently this is somewhat inefficient because `builtins-test` gets run more than once on some targets; this can be cleaned up later.
1 parent 4fa8a68 commit f4a4e93

File tree

6 files changed

+176
-227
lines changed

6 files changed

+176
-227
lines changed

.github/workflows/main.yaml

+11-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ jobs:
9797
rustup default "$channel"
9898
rustup target add "${{ matrix.target }}"
9999
rustup component add llvm-tools-preview
100+
- uses: taiki-e/install-action@nextest
100101
- uses: Swatinem/rust-cache@v2
101102
with:
102103
key: ${{ matrix.target }}
@@ -107,7 +108,7 @@ jobs:
107108
path: /tmp/.buildx-cache
108109
key: ${{ matrix.target }}-buildx-${{ github.sha }}
109110
restore-keys: ${{ matrix.target }}-buildx-
110-
111+
111112
- name: Cache compiler-rt
112113
id: cache-compiler-rt
113114
uses: actions/cache@v4
@@ -121,6 +122,10 @@ jobs:
121122
- run: echo "RUST_COMPILER_RT_ROOT=$(realpath ./compiler-rt)" >> "$GITHUB_ENV"
122123
shell: bash
123124

125+
- name: Verify API list
126+
if: matrix.os == 'ubuntu-24.04'
127+
run: python3 etc/update-api-list.py --check
128+
124129
# Non-linux tests just use our raw script
125130
- name: Run locally
126131
if: matrix.os != 'ubuntu-24.04'
@@ -136,6 +141,11 @@ jobs:
136141
if: matrix.os == 'ubuntu-24.04'
137142
run: cargo generate-lockfile && ./ci/run-docker.sh ${{ matrix.target }}
138143

144+
- name: Print test logs if available
145+
if: always()
146+
run: if [ -f "target/test-log.txt" ]; then cat target/test-log.txt; fi
147+
shell: bash
148+
139149
# Workaround to keep Docker cache smaller
140150
# https://github.com/docker/build-push-action/issues/252
141151
# https://github.com/moby/buildkit/issues/1896

Cargo.toml

+16-19
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,19 @@ panic = "abort"
3131
[profile.dev]
3232
panic = "abort"
3333

34-
# FIXME(libm): these profiles are needed for testing
35-
# # The default release profile is unchanged.
36-
37-
# # Release mode with debug assertions
38-
# [profile.release-checked]
39-
# inherits = "release"
40-
# debug-assertions = true
41-
# overflow-checks = true
42-
43-
# # Release with maximum optimizations, which is very slow to build. This is also
44-
# # what is needed to check `no-panic`.
45-
# [profile.release-opt]
46-
# inherits = "release"
47-
# codegen-units = 1
48-
# lto = "fat"
49-
50-
# [profile.bench]
51-
# # Required for iai-callgrind
52-
# debug = true
34+
# Release mode with debug assertions
35+
[profile.release-checked]
36+
inherits = "release"
37+
debug-assertions = true
38+
overflow-checks = true
39+
40+
# Release with maximum optimizations, which is very slow to build. This is also
41+
# what is needed to check `no-panic`.
42+
[profile.release-opt]
43+
inherits = "release"
44+
codegen-units = 1
45+
lto = "fat"
46+
47+
[profile.bench]
48+
# Required for iai-callgrind
49+
debug = true

ci/run.sh

+146-21
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ if [ -z "$target" ]; then
1313
target="$host_target"
1414
fi
1515

16+
if [[ "$target" = *"wasm"* ]]; then
17+
# Enable the random backend
18+
export RUSTFLAGS="${RUSTFLAGS:-} --cfg getrandom_backend=\"wasm_js\""
19+
fi
20+
1621
if [ "${USING_CONTAINER_RUSTC:-}" = 1 ]; then
1722
# Install nonstandard components if we have control of the environment
1823
rustup target list --installed |
@@ -22,27 +27,27 @@ fi
2227

2328
# Test our implementation
2429
if [ "${BUILD_ONLY:-}" = "1" ]; then
25-
echo "nothing to do for no_std"
30+
echo "no tests to run for build-only targets"
2631
else
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
4448
fi
4549

50+
4651
declare -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[@]}"
6166
cargo build -p compiler_builtins --target "$target"
6267
cargo build -p compiler_builtins --target "$target" --release
6368
cargo 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
6570
cargo 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
6772
cargo 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

7075
PREFIX=${target//unknown-/}-
7176
case "$target" in
@@ -167,4 +172,124 @@ for rlib in "${rlib_paths[@]}"; do
167172
fi
168173
done
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

etc/libm/ci/run-docker.sh

-56
This file was deleted.

0 commit comments

Comments
 (0)