From 6f00cc35560bf9d4a12ee428743b655dfb9c9ce2 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Mon, 16 Mar 2026 20:06:33 -0700 Subject: [PATCH] Add sccache as Rust build cache in container environment Speeds up repeated cargo builds across sessions by caching compilation artifacts on the persistent mount. Co-Authored-By: Claude Opus 4.6 --- src/vm.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/vm.ts b/src/vm.ts index 5a4bb29..dedf38c 100644 --- a/src/vm.ts +++ b/src/vm.ts @@ -15,6 +15,8 @@ const CONTAINER_ENV = { CARGO_HOME: "/sandlot/.cargo", GOROOT: "/sandlot/.go", GOPATH: "/sandlot/.gopath", + RUSTC_WRAPPER: "/sandlot/.cargo/bin/sccache", + SCCACHE_DIR: "/sandlot/.sccache", } /** Translate a host path to its corresponding container path. */ @@ -174,6 +176,16 @@ async function installPersistentTooling(log?: (msg: string) => void): Promise /sandlot/.cargo/config.toml`}`.quiet() } + // sccache — skip if already installed on the persistent mount + const hasSccache = await $`container exec --user ${USER} ${CONTAINER_NAME} test -x /sandlot/.cargo/bin/sccache`.nothrow().quiet() + if (hasSccache.exitCode !== 0) { + log?.("Installing sccache") + await run( + $`container exec --user ${USER} ${CONTAINER_NAME} env ${`RUSTUP_HOME=${CONTAINER_ENV.RUSTUP_HOME}`} ${`CARGO_HOME=${CONTAINER_ENV.CARGO_HOME}`} ${`PATH=${CONTAINER_ENV.CARGO_HOME}/bin:$PATH`} cargo install sccache --locked`, + "sccache installation") + await $`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"mkdir -p /sandlot/.sccache"}`.nothrow().quiet() + } + // Go — skip if already installed on the persistent mount const hasGo = await $`container exec --user ${USER} ${CONTAINER_NAME} test -x /sandlot/.go/bin/go`.nothrow().quiet() if (hasGo.exitCode !== 0) { @@ -314,7 +326,7 @@ export async function claude(workdir: string, opts?: { prompt?: string; print?: systemPromptLines.push( "The host's ~/.sandlot is mounted at /sandlot.", "Bun is installed at ~/.local/bin/bun. Use bun instead of node/npm.", - "Rust (cargo/rustc) is installed at /sandlot/.cargo/. Go is installed at /sandlot/.go/.", + "Rust (cargo/rustc) is installed at /sandlot/.cargo/. Go is installed at /sandlot/.go/. sccache is configured as RUSTC_WRAPPER for build caching.", ) if (opts?.print) { systemPromptLines.push("IMPORTANT: Do not use plan mode. Do not call the EnterPlanMode tool. Proceed directly with the task.")