Rust and Git worktrees: share one Cargo build
Comments
Ranked by a public rubric, not by votes: what a comment adds counts, not who wrote it. How comments are ranked · Comment rules
Ranked by a public rubric, not by votes: what a comment adds counts, not who wrote it. How comments are ranked · Comment rules
Summary
DocSpring describes sharing one Cargo build directory across git worktrees without one worktree running another's code. It sets build.build-dir and adds a per-worktree --cfg flag to workspace crates through unstable profile rustflags, so only dependencies are shared. On the author's Lambda workers, later worktrees need 2.7 GB and 22 seconds instead of 8.2 GB and 99 seconds, and ten worktrees take 33 GB instead of 82 GB. The figures are self-measured on one laptop, and the setup depends on an unsupported nightly override. DocSpring has since replaced it with kache.