From e1c60a6de83f3ea2adff5bd2b4f436537502bfaf Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 9 Feb 2026 21:09:38 +0000 Subject: [PATCH] Run Miri tests in parallel in CI Refactors the Miri test execution in `.github/workflows/ci.yml` to run Stacked Borrows and Tree Borrows tests in parallel. This is achieved by: 1. Launching both `cargo miri nextest` commands as background jobs. 2. Assigning a unique `CARGO_TARGET_DIR` to each job (`target/by-toolchain/$TOOLCHAIN/miri-stacked` and `...-tree`) to prevent build directory lock contention. 3. Redirecting stdout/stderr to log files to avoid interleaved output. 4. Waiting for both jobs to complete, printing their logs, and propagating exit codes. This change significantly reduces the wall-clock time for the Miri CI step. Co-authored-by: joshlf <1046063+joshlf@users.noreply.github.com> --- .github/workflows/ci.yml | 56 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ed8893ea6..e851f2f1f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -468,16 +468,64 @@ jobs: # Run under both the stacked borrows model (default) and under the tree # borrows model to ensure we're compliant with both. - for EXTRA_FLAGS in "" "-Zmiri-tree-borrows"; do - MIRIFLAGS="$MIRIFLAGS $EXTRA_FLAGS" ./cargo.sh +$TOOLCHAIN \ + # + # We run these in the background to allow them to run in parallel. + # + # We need to manually set `CARGO_TARGET_DIR` for each job to avoid + # conflicts since they will be running at the same time. + BASE_TARGET_DIR="target/by-toolchain/${TOOLCHAIN}/miri" + + ( + MIRIFLAGS="$MIRIFLAGS" \ + CARGO_TARGET_DIR="${BASE_TARGET_DIR}-stacked" \ + ./cargo.sh +$TOOLCHAIN \ miri nextest run \ --test-threads "$THREADS" \ --package $CRATE \ --target $TARGET \ - $FEATURES - done + $FEATURES \ + > miri-stacked.log 2>&1 + ) & + PID_STACKED=$! + + ( + MIRIFLAGS="$MIRIFLAGS -Zmiri-tree-borrows" \ + CARGO_TARGET_DIR="${BASE_TARGET_DIR}-tree" \ + ./cargo.sh +$TOOLCHAIN \ + miri nextest run \ + --test-threads "$THREADS" \ + --package $CRATE \ + --target $TARGET \ + $FEATURES \ + > miri-tree.log 2>&1 + ) & + PID_TREE=$! + + # Wait for both jobs to finish. + # We turn off `set -e` so that `wait` doesn't cause the script to exit + # if one of the jobs fails. + set +e + wait $PID_STACKED + CODE_STACKED=$? + wait $PID_TREE + CODE_TREE=$? + set -e + + echo "Output from Stacked Borrows Miri tests:" + cat miri-stacked.log + echo "Output from Tree Borrows Miri tests:" + cat miri-tree.log mv .cargo/config.toml.bak .cargo/config.toml + + if [ $CODE_STACKED -ne 0 ]; then + echo "Stacked Borrows Miri tests failed with exit code $CODE_STACKED" + exit $CODE_STACKED + fi + if [ $CODE_TREE -ne 0 ]; then + echo "Tree Borrows Miri tests failed with exit code $CODE_TREE" + exit $CODE_TREE + fi # Only nightly has a working Miri, so we skip installing on all other # toolchains. #