Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit abf0a28

Browse files
committed
Use cargo-nextest for running tests in CI
The test suite for this repo has quite a lot of tests, and it is difficult to tell which contribute the most to the long CI runtime. libtest does have an unstable flag to report test times, but that is inconvenient to use because it needs to be passed only to libtest binaries. Switch to cargo-nextest [1] which provides time reporting and, overall, a better test UI. It may also improve test runtime, though this seems unlikely since we have larger test binaries with many small tests (nextest benefits the most when there are larger binaries that can be run in parallel). For anyone running locally without, `run.sh` should still fall back to `cargo test` if `cargo-nextest` is not available. This diff includes some cleanup and consistency changes to other CI-related files. [1]: https://nexte.st
1 parent 2b8045a commit abf0a28

File tree

5 files changed

+48
-24
lines changed

5 files changed

+48
-24
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
pull_request:
77

88
env:
9+
CARGO_TERM_COLOR: always
910
CARGO_TERM_VERBOSE: true
1011
RUSTDOCFLAGS: -Dwarnings
1112
RUSTFLAGS: -Dwarnings
@@ -88,6 +89,7 @@ jobs:
8889
rustup default "$channel"
8990
rustup target add "${{ matrix.target }}"
9091
rustup component add clippy llvm-tools-preview
92+
- uses: taiki-e/install-action@nextest
9193
- uses: Swatinem/rust-cache@v2
9294
with:
9395
key: ${{ matrix.target }}

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
jobs:
1313
release-plz:
1414
name: Release-plz
15-
runs-on: ubuntu-latest
15+
runs-on: ubuntu-24.04
1616
steps:
1717
- name: Checkout repository
1818
uses: actions/checkout@v4

ci/download-musl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fname=musl-1.2.5.tar.gz
77
sha=a9a118bbe84d8764da0ea0d28b3ab3fae8477fc7e4085d90102b8596fc7c75e4
88

99
mkdir musl
10-
curl "https://musl.libc.org/releases/$fname" -O
10+
curl -L "https://musl.libc.org/releases/$fname" -O
1111

1212
case "$(uname -s)" in
1313
MINGW*)

ci/run-docker.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ run() {
2424
# will be owned by root
2525
mkdir -p target
2626

27-
docker build -t "$target" "ci/docker/$target"
27+
set_env="HOME=/tmp PATH=\$PATH:/rust/bin:/cargo/bin"
28+
docker build -t "libm-$target" "ci/docker/$target"
2829
docker run \
2930
--rm \
3031
--user "$(id -u):$(id -g)" \
3132
-e CI \
3233
-e RUSTFLAGS \
34+
-e CARGO_TERM_COLOR \
3335
-e CARGO_HOME=/cargo \
3436
-e CARGO_TARGET_DIR=/target \
3537
-e "EMULATED=$emulated" \
@@ -39,8 +41,8 @@ run() {
3941
-v "$(rustc --print sysroot):/rust:ro" \
4042
--init \
4143
-w /checkout \
42-
"$target" \
43-
sh -c "HOME=/tmp PATH=\$PATH:/rust/bin exec ci/run.sh $target"
44+
"libm-$target" \
45+
sh -c "$set_env exec ci/run.sh $target"
4446
}
4547

4648
if [ -z "$1" ]; then

ci/run.sh

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
set -eux
44

55
export RUST_BACKTRACE="${RUST_BACKTRACE:-full}"
6+
export NEXTEST_STATUS_LEVEL=all
67

78
target="${1:-}"
9+
flags=""
810

911
if [ -z "$target" ]; then
1012
host_target=$(rustc -vV | awk '/^host/ { print $2 }')
@@ -13,22 +15,22 @@ if [ -z "$target" ]; then
1315
fi
1416

1517
# We enumerate features manually.
16-
extra_flags="--no-default-features"
18+
flags="$flags --no-default-features"
1719

1820
# Enable arch-specific routines when available.
19-
extra_flags="$extra_flags --features arch"
21+
flags="$flags --features arch"
2022

2123
# Always enable `unstable-float` since it expands available API but does not
2224
# change any implementations.
23-
extra_flags="$extra_flags --features unstable-float"
25+
flags="$flags --features unstable-float"
2426

2527
# We need to specifically skip tests for musl-math-sys on systems that can't
2628
# build musl since otherwise `--all` will activate it.
2729
case "$target" in
2830
# Can't build at all on MSVC, WASM, or thumb
29-
*windows-msvc*) extra_flags="$extra_flags --exclude musl-math-sys" ;;
30-
*wasm*) extra_flags="$extra_flags --exclude musl-math-sys" ;;
31-
*thumb*) extra_flags="$extra_flags --exclude musl-math-sys" ;;
31+
*windows-msvc*) flags="$flags --exclude musl-math-sys" ;;
32+
*wasm*) flags="$flags --exclude musl-math-sys" ;;
33+
*thumb*) flags="$flags --exclude musl-math-sys" ;;
3234

3335
# We can build musl on MinGW but running tests gets a stack overflow
3436
*windows-gnu*) ;;
@@ -38,7 +40,7 @@ case "$target" in
3840
*powerpc64le*) ;;
3941

4042
# Everything else gets musl enabled
41-
*) extra_flags="$extra_flags --features libm-test/build-musl" ;;
43+
*) flags="$flags --features libm-test/build-musl" ;;
4244
esac
4345

4446
# Configure which targets test against MPFR
@@ -50,17 +52,17 @@ case "$target" in
5052
# Targets that aren't cross compiled work fine
5153
# FIXME(ci): we should be able to enable aarch64 Linux here once GHA
5254
# support rolls out.
53-
x86_64*) extra_flags="$extra_flags --features libm-test/build-mpfr" ;;
54-
i686*) extra_flags="$extra_flags --features libm-test/build-mpfr" ;;
55-
i586*) extra_flags="$extra_flags --features libm-test/build-mpfr --features gmp-mpfr-sys/force-cross" ;;
55+
x86_64*) flags="$flags --features libm-test/build-mpfr" ;;
56+
i686*) flags="$flags --features libm-test/build-mpfr" ;;
57+
i586*) flags="$flags --features libm-test/build-mpfr --features gmp-mpfr-sys/force-cross" ;;
5658
# Apple aarch64 is native
57-
aarch64*apple*) extra_flags="$extra_flags --features libm-test/build-mpfr" ;;
59+
aarch64*apple*) flags="$flags --features libm-test/build-mpfr" ;;
5860
esac
5961

6062
# FIXME: `STATUS_DLL_NOT_FOUND` testing macros on CI.
6163
# <https://github.com/rust-lang/rust/issues/128944>
6264
case "$target" in
63-
*windows-gnu) extra_flags="$extra_flags --exclude libm-macros" ;;
65+
*windows-gnu) flags="$flags --exclude libm-macros" ;;
6466
esac
6567

6668
# Make sure we can build with overriding features.
@@ -76,13 +78,31 @@ if [ "${BUILD_ONLY:-}" = "1" ]; then
7678
exit
7779
fi
7880

79-
# Otherwise, run the test suite.
80-
81-
cmd="cargo test --all --target $target $extra_flags"
81+
flags="$flags --all --target $target"
82+
cmd="cargo test $flags"
83+
profile="--profile"
84+
85+
# If nextest is available, use that
86+
command -v cargo-nextest && nextest=1 || nextest=0
87+
if [ "$nextest" = "1" ]; then
88+
# Workaround for https://github.com/nextest-rs/nextest/issues/2066
89+
if [ -f /.dockerenv ]; then
90+
cfg_file="/tmp/nextest-config.toml"
91+
echo "[store]" >> "$cfg_file"
92+
echo "dir = \"$CARGO_TARGET_DIR/nextest\"" >> "$cfg_file"
93+
cfg_flag="--config-file $cfg_file"
94+
fi
95+
96+
cmd="cargo nextest run ${cfg_flag:-} $flags"
97+
profile="--cargo-profile"
98+
fi
8299

83100
# Test once without intrinsics
84101
$cmd
85102

103+
# Run doctests if they were excluded by nextest
104+
[ "$nextest" = "1" ] && cargo test --doc $flags
105+
86106
# Exclude the macros and utile crates from the rest of the tests to save CI
87107
# runtime, they shouldn't have anything feature- or opt-level-dependent.
88108
cmd="$cmd --exclude util --exclude libm-macros"
@@ -93,10 +113,10 @@ $cmd --features unstable-intrinsics --benches
93113

94114
# Test the same in release mode, which also increases coverage. Also ensure
95115
# the soft float routines are checked.
96-
$cmd --profile release-checked
97-
$cmd --profile release-checked --features force-soft-floats
98-
$cmd --profile release-checked --features unstable-intrinsics
99-
$cmd --profile release-checked --features unstable-intrinsics --benches
116+
$cmd "$profile" release-checked
117+
$cmd "$profile" release-checked --features force-soft-floats
118+
$cmd "$profile" release-checked --features unstable-intrinsics
119+
$cmd "$profile" release-checked --features unstable-intrinsics --benches
100120

101121
# Ensure that the routines do not panic.
102122
ENSURE_NO_PANIC=1 cargo build -p libm --target "$target" --no-default-features --release

0 commit comments

Comments
 (0)