Shared CARGO_TARGET_DIR: a worktree can run another worktree's stale xtask/test binaries #33

Open
opened 2026-11-11 08:46:44 +00:00 by charles · 1 comment
Owner

Seen on task/16-ui-theme-fonts-icons at 320a63b (base foundation 6a1dd09), while other task worktrees were building into the same CARGO_TARGET_DIR=~/src/fluxer-native-target.

Steps

  1. Worktree A (fluxer-native-wt/task-16): edit xtask/src/main.rs (I added --fork to gen-theme), build once (cargo test -p xtask).
  2. Worktree B (any other task worktree, unchanged xtask): run any cargo xtask ... / cargo test, which rebuilds xtask from B's sources.
  3. Back in A: cargo run -v -p xtask -- gen-theme --help.

Observed

Fresh xtask v0.1.0 (/home/.../fluxer-native-wt/task-16/xtask)
Running `.../fluxer-native-target/debug/xtask gen-theme --help`
Usage: xtask gen-theme          <- B's binary, without A's --fork option

Cargo reports A's xtask as fresh and runs the binary B built. Both worktrees' xtask units map to the same file in debug/deps/ (same hash), and freshness is decided by mtime: B's build is newer than A's last edit, so A's sources look up to date. touching A's sources forces a rebuild and gives the right binary until the next build from another worktree.

Expected

A worktree always builds and runs its own sources.

Why it matters

The same applies to every workspace crate, not just xtask: cargo xtask ci in one worktree can link or run artifacts built from another worktree's sources if that worktree built more recently, so a local "ci green" can be about someone else's code, or fail for reasons that are not in the branch. The remote runners are not affected (one checkout each).

Possible fixes

  • One target dir per worktree, with a shared compiler cache (sccache) for third-party crates instead of a shared target dir.
  • Or keep the shared dir for dependencies only and give workspace members a per-worktree dir (build-dir/target-dir split), if the pinned cargo supports it.

Workaround used for Task 16: find xtask crates apps -name '*.rs' -exec touch {} + right before cargo xtask ci.

Seen on `task/16-ui-theme-fonts-icons` at 320a63b (base `foundation` 6a1dd09), while other task worktrees were building into the same `CARGO_TARGET_DIR=~/src/fluxer-native-target`. **Steps** 1. Worktree A (`fluxer-native-wt/task-16`): edit `xtask/src/main.rs` (I added `--fork` to `gen-theme`), build once (`cargo test -p xtask`). 2. Worktree B (any other task worktree, unchanged xtask): run any `cargo xtask ...` / `cargo test`, which rebuilds `xtask` from B's sources. 3. Back in A: `cargo run -v -p xtask -- gen-theme --help`. **Observed** ``` Fresh xtask v0.1.0 (/home/.../fluxer-native-wt/task-16/xtask) Running `.../fluxer-native-target/debug/xtask gen-theme --help` Usage: xtask gen-theme <- B's binary, without A's --fork option ``` Cargo reports A's `xtask` as fresh and runs the binary B built. Both worktrees' `xtask` units map to the same file in `debug/deps/` (same hash), and freshness is decided by mtime: B's build is newer than A's last edit, so A's sources look up to date. `touch`ing A's sources forces a rebuild and gives the right binary until the next build from another worktree. **Expected** A worktree always builds and runs its own sources. **Why it matters** The same applies to every workspace crate, not just `xtask`: `cargo xtask ci` in one worktree can link or run artifacts built from another worktree's sources if that worktree built more recently, so a local "ci green" can be about someone else's code, or fail for reasons that are not in the branch. The remote runners are not affected (one checkout each). **Possible fixes** - One target dir per worktree, with a shared compiler cache (`sccache`) for third-party crates instead of a shared target dir. - Or keep the shared dir for dependencies only and give workspace members a per-worktree dir (`build-dir`/`target-dir` split), if the pinned cargo supports it. Workaround used for Task 16: `find xtask crates apps -name '*.rs' -exec touch {} +` right before `cargo xtask ci`.
Author
Owner

Seen again while implementing Task 4 (commit 425f13c), this time with a library artifact rather than a binary: with the Task 3 and Task 4 worktrees building fluxer-proto into the shared target dir at the same time, cargo xtask ci in the task-4 worktree failed twice in the clippy step with could not find gateway in fluxer_proto although src/lib.rs declared the module. The fluxer-proto lib metadata was treated as fresh but had been written from the other worktree. touch crates/fluxer-proto/src/lib.rs and a rerun passed. Same root cause as above: workspace members in different worktrees map to the same artifact names in a shared CARGO_TARGET_DIR.

Seen again while implementing Task 4 (commit `425f13c`), this time with a library artifact rather than a binary: with the Task 3 and Task 4 worktrees building `fluxer-proto` into the shared target dir at the same time, `cargo xtask ci` in the task-4 worktree failed twice in the clippy step with `could not find gateway in fluxer_proto` although `src/lib.rs` declared the module. The `fluxer-proto` lib metadata was treated as fresh but had been written from the other worktree. `touch crates/fluxer-proto/src/lib.rs` and a rerun passed. Same root cause as above: workspace members in different worktrees map to the same artifact names in a shared `CARGO_TARGET_DIR`.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
charles/fluxer-native#33
No description provided.