Skip to content

collect: route instrumented builds to target/affected/build/ - #12

Merged
max-sixty merged 1 commit into
mainfrom
profraw-isolation
May 3, 2026
Merged

max-sixty merged 1 commit into
mainfrom
profraw-isolation

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

cargo affected collect was running cargo nextest list/run with RUSTFLAGS=-C instrument-coverage but no isolated --target-dir, so cargo compiled every workspace package — including helper binaries pulled in by default-members — into target/debug/ as instrumented artifacts. Those binaries lingered after collect exited, and any later non-coverage cargo test that spawned them wrote default_*.profraw files to its CWD (LLVM's fallback when LLVM_PROFILE_FILE isn't set).

Pass --target-dir target/affected/build/ to all three cargo invocations (initial list, pre-run list, run) so coverage builds stay out of target/debug/. The build dir is persistent — sharing it across collects preserves cargo's incremental cache. Sweep stale build-script profraws on each collect since they aren't useful between runs.

Move the build-script LLVM_PROFILE_FILE pattern to the target-dir root (target/affected/build/build-%p-%m.profraw) to mirror cargo-llvm-cov's convention. Setup-scripts that recover the target-dir via dirname(LLVM_PROFILE_FILE) — e.g. worktrunk's helper-binary builder — now resolve to the right place without having to know cargo-affected's specific layout.

cargo affected run/status are unchanged: they don't pass --target-dir and don't set RUSTFLAGS, so they keep sharing the user's normal target/debug/ cache.

This was written by Claude Code on behalf of [user]

`cargo affected collect` was running `cargo nextest list/run` with
RUSTFLAGS=-C instrument-coverage but no isolated --target-dir, so cargo
compiled every workspace package — including helper binaries pulled in
by `default-members` — into target/debug/ as instrumented artifacts.
Those binaries lingered after collect exited, and any later non-coverage
`cargo test` that spawned them wrote `default_*.profraw` files to its
CWD (LLVM's fallback when LLVM_PROFILE_FILE isn't set).

Pass --target-dir target/affected/build/ to all three cargo invocations
(initial list, pre-run list, run) so coverage builds stay out of
target/debug/. The build dir is persistent — sharing it across collects
preserves cargo's incremental cache. Sweep stale build-script profraws
on each collect since their bundles aren't useful between runs.

Move the build-script LLVM_PROFILE_FILE pattern to the target-dir root
(target/affected/build/build-%p-%m.profraw) to mirror cargo-llvm-cov's
convention. Setup-scripts that recover the target-dir via
dirname(LLVM_PROFILE_FILE) — e.g. worktrunk's helper-binary builder —
now resolve to the right place without having to know cargo-affected's
specific layout.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 7f6c4c7 into main May 3, 2026
3 checks passed
@max-sixty
max-sixty deleted the profraw-isolation branch May 3, 2026 23:13
@max-sixty max-sixty mentioned this pull request May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant