Skip to content

Commit 11c45be

Browse files
committed
perf(rust): share one cargo target directory across checkouts
Each checkout builds its own complete target directory. Anyone keeping several worktrees open pays it in full every time, roughly 1.8G each after the dev profile change. Move compiler output beside the checkout instead of inside it, so sibling worktrees share one directory. Cargo resolves a relative target-dir against the config file's parent, so a checkout at <path>/BrowserOS now builds into <path>/shared-target. Measured locally: a first build takes 53.54s and produces a 1.8G shared directory; a second worktree then builds in 20.07s and grows it only to 2.3G, reusing every dependency artifact rather than adding another full copy. Single-checkout clones are unaffected in practice, building one directory higher than before. CI is pinned back to the in-repo path with CARGO_TARGET_DIR, which takes precedence over the config file. A workflow run has exactly one checkout and gains nothing from sharing, and the BrowserClaw release locates its compiled binary at packages/browseros-agent/target in three places: the PostHog key check, the stamped version check, and packaging. Swatinem rust-cache also resolves its cache path as workspace plus target and never reads CARGO_TARGET_DIR, so an unpinned redirect would silently stop caching. Both workflows that run cargo set it at the workflow level. Anything added later that runs cargo in CI must set CARGO_TARGET_DIR too.
1 parent e1bff79 commit 11c45be

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

.cargo/config.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[build]
2+
# Put compiler output beside the checkout rather than inside it, so sibling
3+
# git worktrees of this repo share one target directory instead of each
4+
# building a full private copy. Resolved relative to this file's parent, so a
5+
# checkout at <path>/BrowserOS builds into <path>/shared-target.
6+
#
7+
# Single-checkout clones are unaffected in practice: they simply build one
8+
# directory higher than before.
9+
#
10+
# CI pins CARGO_TARGET_DIR back to the in-repo path, because a workflow run has
11+
# exactly one checkout and gains nothing from sharing, while several release
12+
# steps locate the compiled binary at packages/browseros-agent/target. An env
13+
# var overrides this file, so anything running cargo in CI must set it.
14+
target-dir = "../shared-target"

.github/workflows/release-claw-server.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ on:
7575
permissions:
7676
contents: write
7777

78+
env:
79+
# A committed .cargo/config.toml moves compiler output beside the checkout so
80+
# sibling worktrees can share it. A workflow run has a single checkout and gains
81+
# nothing from that, and several steps locate build output at the in-repo path,
82+
# so pin it back here. An env var takes precedence over the config file.
83+
CARGO_TARGET_DIR: ${{ github.workspace }}/packages/browseros-agent/target
84+
7885
concurrency:
7986
# The legacy key keeps in-flight revisions of the renamed workflow serialized.
8087
group: release-claw-server-rust

.github/workflows/test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ permissions:
2525
contents: read
2626

2727
env:
28+
# A committed .cargo/config.toml moves compiler output beside the checkout so
29+
# sibling worktrees can share it. A workflow run has a single checkout and gains
30+
# nothing from that, and several steps locate build output at the in-repo path,
31+
# so pin it back here. An env var takes precedence over the config file.
32+
CARGO_TARGET_DIR: ${{ github.workspace }}/packages/browseros-agent/target
2833
BROWSEROS_APPIMAGE_URL: https://files.browseros.com/download/BrowserOS.AppImage
2934

3035
concurrency:

0 commit comments

Comments
 (0)