Skip to content

Commit e805ea4

Browse files
committed
perf(rust): share intermediates via build-dir instead of moving target
target-dir has no path templating and cargo expands neither ~ nor $HOME, so a committed value could only ever be relative to the checkout. That limited sharing to sibling worktrees and, because it moved the final artifacts too, required CARGO_TARGET_DIR pinned in two workflows to keep the release steps able to locate a built binary. build-dir does support templating. {cargo-cache-home} resolves to CARGO_HOME, so one shared location covers every clone and worktree on a machine rather than only siblings, and it stays portable with no absolute path committed. It also only moves intermediates. Final artifacts still land in <checkout>/target, so the release steps keep working and both workflow pins are gone: release-claw-server has none at all now, and test.yml names the shared directory to rust-cache instead, which caches only workspace target dirs plus the registry and git caches by default. Measured across two checkouts of the same branch: cold build 38.35s target 227M shared 1.6G second checkout 16.14s target 227M shared 2.1G and a release build against a warm shared directory still produces target/release/browseros-claw-server-rs, which is the path the release workflow reads. The tradeoff against the previous form is ~227M left per checkout rather than nothing, bought in exchange for machine-wide sharing and no release-path coupling.
1 parent e43ac4b commit e805ea4

3 files changed

Lines changed: 14 additions & 23 deletions

File tree

.cargo/config.toml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
[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.
2+
# Keep intermediate artifacts outside the checkout so every clone and worktree
3+
# on a machine shares one copy instead of each rebuilding the dependency graph.
4+
# {cargo-cache-home} expands to CARGO_HOME, so this is portable: no absolute
5+
# path, no assumption about where the repo lives. Cargo does not expand ~ or
6+
# $HOME, and target-dir does not support templating, so build-dir is the only
7+
# form that gets this.
68
#
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"
9+
# Final artifacts still land in <checkout>/target, so anything locating a built
10+
# binary by path keeps working.
11+
build-dir = "{cargo-cache-home}/build/browseros"

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ 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
8478

8579
concurrency:
8680
# The legacy key keeps in-flight revisions of the renamed workflow serialized.

.github/workflows/test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ 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
3328
BROWSEROS_APPIMAGE_URL: https://files.browseros.com/download/BrowserOS.AppImage
3429

3530
concurrency:
@@ -105,6 +100,11 @@ jobs:
105100
uses: Swatinem/rust-cache@v2
106101
with:
107102
workspaces: packages/browseros-agent
103+
# Intermediate artifacts live outside the checkout so worktrees can
104+
# share them, and rust-cache only saves workspace target dirs plus the
105+
# registry and git caches by default. Name the build dir explicitly or
106+
# every run would recompile the dependency graph from scratch.
107+
cache-directories: ~/.cargo/build/browseros
108108

109109
- name: Install dependencies
110110
run: bun ci

0 commit comments

Comments
 (0)