Skip to content

Commit 1a4230b

Browse files
committed
Optimize Rust builds across worktrees
1 parent c76a71d commit 1a4230b

5 files changed

Lines changed: 79 additions & 0 deletions

File tree

.cargo/config.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[build]
2+
rustc-wrapper = "scripts/sccache-rustc-wrapper.sh"
3+
incremental = false
4+
5+
[profile.dev]
6+
debug = "line-tables-only"
7+
8+
[profile.test]
9+
debug = "line-tables-only"
10+
11+
[env]
12+
SCCACHE_CACHE_SIZE = { value = "20G", force = false }
13+
SCCACHE_IGNORE_SERVER_IO_ERROR = { value = "1", force = false }

AGENTS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ Detailed runtime and SDK rules:
141141
Use the narrowest reliable validation for the touched area. Common commands and
142142
fallbacks live in @docs/agents/validation.md.
143143

144+
Keep a separate Cargo `target` directory in every concurrent Rust worktree.
145+
The checked-in `.cargo/config.toml` disables incremental/full dev-test debug
146+
artifacts and uses the worktree-aware sccache wrapper; do not replace it with a
147+
single shared `CARGO_TARGET_DIR`.
148+
144149
For Rust changes, prefer the fast local loop before any full workspace run:
145150
`scripts/test/rust_tier1_fast.sh --changed`. For focused work, run the touched
146151
crate or exact test directly, for example `cargo test -p garyx-gateway --lib`,

CLAUDE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ Detailed runtime and SDK rules:
141141
Use the narrowest reliable validation for the touched area. Common commands and
142142
fallbacks live in @docs/agents/validation.md.
143143

144+
Keep a separate Cargo `target` directory in every concurrent Rust worktree.
145+
The checked-in `.cargo/config.toml` disables incremental/full dev-test debug
146+
artifacts and uses the worktree-aware sccache wrapper; do not replace it with a
147+
single shared `CARGO_TARGET_DIR`.
148+
144149
For Rust changes, prefer the fast local loop before any full workspace run:
145150
`scripts/test/rust_tier1_fast.sh --changed`. For focused work, run the touched
146151
crate or exact test directly, for example `cargo test -p garyx-gateway --lib`,

docs/agents/validation.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,22 @@ cargo test -p garyx-gateway --lib
5454
cargo test -p garyx-router --all-targets
5555
cargo test -p garyx-channels --lib
5656
```
57+
58+
## Rust Worktree Cache
59+
60+
Garyx disables Cargo incremental output and full debugger symbols for dev/test
61+
profiles, then uses `scripts/sccache-rustc-wrapper.sh` to share compiler output
62+
across concurrent Git worktrees. The wrapper normalizes the current checkout
63+
root before invoking `sccache`; if `sccache` is unavailable it invokes `rustc`
64+
directly, so CI and fresh machines keep working.
65+
66+
Install the local cache on macOS and inspect its effectiveness with:
67+
68+
```bash
69+
brew install sccache
70+
sccache --show-stats
71+
```
72+
73+
The repository config caps the local cache at 20 GiB. Keep each active
74+
worktree's own `target` directory so Cargo builds do not serialize on one build
75+
directory, and remove the whole worktree after its task is approved.

scripts/sccache-rustc-wrapper.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if [[ $# -eq 0 ]]; then
5+
echo "usage: sccache-rustc-wrapper.sh <rustc> [args...]" >&2
6+
exit 2
7+
fi
8+
9+
if [[ -n "${SCCACHE_BIN:-}" ]]; then
10+
sccache_bin="$SCCACHE_BIN"
11+
elif sccache_bin="$(command -v sccache 2>/dev/null)" && [[ -n "$sccache_bin" ]]; then
12+
:
13+
else
14+
exec "$@"
15+
fi
16+
17+
manifest_dir="${CARGO_MANIFEST_DIR:-$PWD}"
18+
candidate="$manifest_dir"
19+
while [[ "$candidate" != "/" && -n "$candidate" ]]; do
20+
if [[ -e "$candidate/.git" ]]; then
21+
case ":${SCCACHE_BASEDIRS:-}:" in
22+
*":$candidate:"*) ;;
23+
*) export SCCACHE_BASEDIRS="$candidate${SCCACHE_BASEDIRS:+:$SCCACHE_BASEDIRS}" ;;
24+
esac
25+
break
26+
fi
27+
candidate="${candidate%/*}"
28+
[[ -n "$candidate" ]] || candidate="/"
29+
done
30+
31+
if [[ "${GARYX_SCCACHE_PRINT_CONFIG:-0}" == "1" ]]; then
32+
echo "SCCACHE_BIN=$sccache_bin"
33+
echo "SCCACHE_BASEDIRS=${SCCACHE_BASEDIRS:-}"
34+
exit 0
35+
fi
36+
37+
exec "$sccache_bin" "$@"

0 commit comments

Comments
 (0)