Skip to content

Commit e4a28e4

Browse files
kixelatedclaude
andauthored
ci: persistent cargo target dir + trim redundant compiles (#1852)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 6ca39c4 commit e4a28e4

3 files changed

Lines changed: 24 additions & 41 deletions

File tree

.github/workflows/check.yml

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,43 +56,17 @@ jobs:
5656
uses: DeterminateSystems/flake-checker-action@9ee1c5473f1abdfb299f6c4f0fab813147c97fe3 # main
5757

5858
# GitHub-hosted fallback caches Rust via the Actions cache. The self-hosted
59-
# box runs the heavy Rust CI (clippy/doc/test) as crane derivations via
60-
# `nix flake check`, so deps cache in /nix/store and there's no persistent
61-
# CARGO_TARGET_DIR to manage -- the residual `cargo check`s use the
62-
# workspace ./target, which the runner wipes per job.
59+
# box runs the heavy Rust CI (clippy/doc/test) as plain cargo, reusing a
60+
# persistent CARGO_TARGET_DIR set in the runner environment (not here), so
61+
# unchanged crates are reused across jobs; the checkout's ./target is unused.
6362
- name: Rust Cache
6463
if: runner.environment == 'github-hosted'
6564
uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
6665
with:
6766
cache-on-failure: true
6867

69-
# Mark a baseline so the post-run assertion can tell whether anything wrote
70-
# under the old persistent target dir (i.e. a CARGO_TARGET_DIR override
71-
# leaked back in and would re-grow an unbounded tree).
72-
- name: Target-dir baseline
73-
if: runner.environment == 'self-hosted'
74-
run: touch "$RUNNER_TEMP/target-baseline"
75-
7668
# `just ci` calls `just changed` internally to skip unchanged scopes.
7769
# Login shell so /etc/profile.d puts Nix on PATH; Actions shells don't by
7870
# default. Harmless on the hosted fallback.
7971
- run: nix develop --command just ci
8072
shell: bash -leo pipefail {0}
81-
82-
# Invariant: nothing should write to the old persistent target dir anymore.
83-
# Fails loudly if a CARGO_TARGET_DIR override sneaks back in. Scope it to
84-
# *this* repo's old per-runner dir (moq-$RUNNER_NAME) -- the box's
85-
# $HOME/cargo-target is shared with other repos (e.g. moq-pro) and runners,
86-
# whose jobs may run concurrently and legitimately still write there.
87-
- name: Assert the persistent target dir stayed unused
88-
if: runner.environment == 'self-hosted'
89-
run: |
90-
target="$HOME/cargo-target/moq-$RUNNER_NAME"
91-
mkdir -p "$target"
92-
leaked=$(find "$target" -type f -newer "$RUNNER_TEMP/target-baseline" 2>/dev/null | head)
93-
if [ -n "$leaked" ]; then
94-
echo "::error::cargo wrote to $target; a CARGO_TARGET_DIR override leaked back in"
95-
echo "$leaked"
96-
exit 1
97-
fi
98-
echo "OK: $target untouched this run"

flake.nix

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
cargo-edit
9393
cargo-semver-checks
9494
cargo-deny
95+
cargo-nextest
9596
]
9697
++ gstreamerDeps
9798
++ pkgs.lib.optionals (!pkgs.stdenv.isDarwin) [
@@ -238,10 +239,10 @@
238239
# build via crane `buildPackage` (see `packages` above / release-*.yml).
239240
#
240241
# On the self-hosted runner those cargo checks transparently reuse a
241-
# per-crate compiler cache (rustc is wrapped by sccache via the runner
242-
# environment), so a Cargo.lock change recompiles only the changed crate
243-
# + its reverse-deps. That's a runner-side concern -- nothing here or in
244-
# the workflows configures it.
242+
# persistent CARGO_TARGET_DIR (set in the runner environment), so a
243+
# Cargo.lock change recompiles only the changed crate + its reverse-deps
244+
# and unchanged crates are reused across jobs. That's a runner-side
245+
# concern -- nothing here or in the workflows configures it.
245246
checks = { };
246247
}
247248
);

rs/justfile

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,25 @@ ci FILES="":
4444
4545
# Compiles. The all-features clippy / doc / test were crane derivations built
4646
# by `nix flake check`; they now run here as plain cargo (flake.nix `checks`
47-
# is unwired). The default / no-default-feature `cargo check`s cover feature
48-
# edges the all-features run doesn't. Everything builds into the in-workspace
49-
# ./target, which the runner wipes per job; on the self-hosted runner the
50-
# heavy compilation is transparently cached per-crate by sccache (wired into
51-
# the runner environment, not here), so there's no persistent target dir to
52-
# bound. (Local devs still get the full cargo loop via `just rs check`.)
53-
cargo check --workspace --all-targets
47+
# is unwired). Each full-workspace compile below is expensive on the 4-core A1
48+
# runner, so we run the minimum set that still covers every feature edge:
49+
# - clippy --all-targets --all-features is the gate and a superset of a plain
50+
# `cargo check --all-targets` (default features), so that redundant check
51+
# pass is intentionally omitted -- one fewer full workspace compile.
52+
# - --no-default-features stays: it's the only pass that exercises code behind
53+
# `#[cfg(not(feature = ...))]`, which the all-features run never compiles.
54+
# The self-hosted runner sets a persistent CARGO_TARGET_DIR (in its env, not
55+
# here), so unchanged crates are reused across jobs and a Cargo.lock change
56+
# recompiles only the changed crate + its reverse-deps. (Local devs still get
57+
# the full cargo loop via `just rs check`.)
5458
cargo check --workspace --no-default-features
5559
cargo clippy --workspace --all-targets --all-features -- -D warnings
5660
RUSTDOCFLAGS="-D warnings" cargo doc --workspace --all-features --no-deps
57-
cargo test --workspace --all-targets --all-features
61+
# nextest compiles + runs the test binaries with real parallelism (faster than
62+
# `cargo test`'s serial harness on the 4-core box). It does not build or run
63+
# doctests, so the `/// ```` examples are no longer compile-checked in CI -- an
64+
# accepted trade for speed (they still render in `cargo doc` output).
65+
cargo nextest run --workspace --all-targets --all-features
5866
5967
# Auto-fix clippy/format/shear/sort.
6068
fix:

0 commit comments

Comments
 (0)