Skip to content

Commit ff781c7

Browse files
committed
chore(cargo): share target-dir across repo worktrees
1 parent 6ee3a29 commit ff781c7

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎.cargo/config.toml‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# Share one target/ dir across the main checkout and every git worktree
2+
# (including .claude/worktrees/* used by background agents), instead of each
3+
# worktree accumulating its own multi-GB target/. This relative path resolves
4+
# against the parent of *this* .cargo directory, i.e. the main checkout root
5+
# — so it's just the conventional $repo_root/target. Because
6+
# .claude/worktrees/* are nested inside the main checkout on disk, Cargo's
7+
# ancestor-directory config search finds this file (and thus this path, still
8+
# resolved relative to the main checkout) from any worktree too, even though
9+
# each worktree has its own (older) checked-out copy of .cargo/config.toml —
10+
# no propagation needed.
11+
# Cargo already mutexes concurrent builds against the same target dir via
12+
# target/.cargo-lock (shared lock for reads, exclusive for writes), so this
13+
# is safe: it just serializes builds across worktrees instead of
14+
# parallelizing them, in exchange for not multiplying multi-GB target/ dirs
15+
# per worktree. Override by setting the CARGO_TARGET_DIR env var, which
16+
# always takes precedence over this config file.
17+
[build]
18+
target-dir = "target"
119
# Reduce target/ directory bloat
220
[profile.dev]
321
debug = 1 # 0=none, 1=line tables, 2=full
@@ -11,4 +29,4 @@ opt-level = 2 # Optimize deps even in dev builds
1129
# For faster builds with mold linker (local only), uncomment:
1230
# [target.x86_64-unknown-linux-gnu]
1331
# linker = "clang"
14-
# rustflags = ["-C", "link-arg=-fuse-ld=mold"]
32+
# rustflags = ["-C", "link-arg=-fuse-ld=mold"]

0 commit comments

Comments
 (0)