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 <noreply@anthropic.com>
This commit is contained in:
Chris Wanstrath 2026-03-16 20:06:33 -07:00
parent 26c5c3c7b0
commit 6f00cc3556

View File

@ -15,6 +15,8 @@ const CONTAINER_ENV = {
CARGO_HOME: "/sandlot/.cargo", CARGO_HOME: "/sandlot/.cargo",
GOROOT: "/sandlot/.go", GOROOT: "/sandlot/.go",
GOPATH: "/sandlot/.gopath", GOPATH: "/sandlot/.gopath",
RUSTC_WRAPPER: "/sandlot/.cargo/bin/sccache",
SCCACHE_DIR: "/sandlot/.sccache",
} }
/** Translate a host path to its corresponding container path. */ /** Translate a host path to its corresponding container path. */
@ -174,6 +176,16 @@ async function installPersistentTooling(log?: (msg: string) => void): Promise<vo
await $`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${`echo -e '${cargoConfig}' > /sandlot/.cargo/config.toml`}`.quiet() await $`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${`echo -e '${cargoConfig}' > /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 // 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() const hasGo = await $`container exec --user ${USER} ${CONTAINER_NAME} test -x /sandlot/.go/bin/go`.nothrow().quiet()
if (hasGo.exitCode !== 0) { if (hasGo.exitCode !== 0) {
@ -314,7 +326,7 @@ export async function claude(workdir: string, opts?: { prompt?: string; print?:
systemPromptLines.push( systemPromptLines.push(
"The host's ~/.sandlot is mounted at /sandlot.", "The host's ~/.sandlot is mounted at /sandlot.",
"Bun is installed at ~/.local/bin/bun. Use bun instead of node/npm.", "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) { if (opts?.print) {
systemPromptLines.push("IMPORTANT: Do not use plan mode. Do not call the EnterPlanMode tool. Proceed directly with the task.") systemPromptLines.push("IMPORTANT: Do not use plan mode. Do not call the EnterPlanMode tool. Proceed directly with the task.")