#!/usr/bin/env bash # EVERY ACCOUNT'S SCCACHE HAS A SIZE CAP — A BUILDER'S TOO, NOT ONLY THE RUNNER'S. # # scripts/ensure-sccache-cap.sh [GB] (default 15, COTTON_SCCACHE_CAP_GB) # # The Mac runner's cache is capped at 15 GB (`scripts/ci/setup-sccache.sh`; 40 GB # until 14 Oct 2026, when a 40 GiB cache sat at its cap on the serving Mac while # every build there was refused at the disk floor — the architect's ruling), but # that cap is an environment variable the runner's steps set: a builder's # `cargo build` in a worktree (`worktree-new.sh` makes sccache its # rustc-wrapper) starts the server without it, and on 29 Sep 2026 builders' # caches had no cap at all. sccache also reads a per-account CONFIG FILE, which # every server it starts obeys whoever started it — so the cap goes there: # # Linux ~/.config/sccache/config # macOS ~/Library/Application Support/Mozilla.sccache/config # (SCCACHE_CONF names another, as sccache itself allows) # # `[cache.disk] size` is set to the cap when it is missing or larger; a smaller # cap someone chose is left alone, and every other line of the file is kept. # An environment `SCCACHE_CACHE_SIZE` still wins, as sccache decides. # `scripts/daily-sweep.sh` runs this for its account every day. # # Guard: `scripts/__tests__/ensure-sccache-cap.test.ts`. set -euo pipefail GB="${1:-${COTTON_SCCACHE_CAP_GB:-15}}" [[ "$GB" =~ ^[0-9]+$ ]] || { echo "ensure-sccache-cap: '$GB' is not a whole number of GB" >&2; exit 2; } BYTES=$(( GB * 1024 * 1024 * 1024 )) if [ -n "${SCCACHE_CONF:-}" ]; then CONF="$SCCACHE_CONF" elif [ "$(uname -s)" = Darwin ]; then CONF="$HOME/Library/Application Support/Mozilla.sccache/config" else CONF="${XDG_CONFIG_HOME:-$HOME/.config}/sccache/config" fi mkdir -p "$(dirname "$CONF")" touch "$CONF" # The current `size` under `[cache.disk]`, in bytes, or empty. current="$(awk ' /^[[:space:]]*\[/ { in_disk = ($0 ~ /^[[:space:]]*\[cache\.disk\][[:space:]]*$/) ; next } in_disk && /^[[:space:]]*size[[:space:]]*=/ { sub(/^[^=]*=[[:space:]]*/, ""); gsub(/[^0-9]/, ""); print; exit } ' "$CONF")" if [ -n "$current" ] && [ "$current" -le "$BYTES" ]; then echo "sccache cap: $CONF already caps the cache at $(( current / 1024 / 1024 / 1024 )) GB" exit 0 fi tmp="$(mktemp "$CONF.XXXXXX")" awk -v bytes="$BYTES" ' BEGIN { done = 0 } /^[[:space:]]*\[/ { if (in_disk && !done) { print "size = " bytes; done = 1 } in_disk = ($0 ~ /^[[:space:]]*\[cache\.disk\][[:space:]]*$/) print; next } in_disk && /^[[:space:]]*size[[:space:]]*=/ { if (!done) { print "size = " bytes; done = 1 }; next } { print } END { if (in_disk && !done) { print "size = " bytes; done = 1 } if (!done) { print ""; print "[cache.disk]"; print "size = " bytes } } ' "$CONF" >"$tmp" mv "$tmp" "$CONF" echo "sccache cap: $CONF now caps the cache at $GB GB$([ -n "$current" ] && echo " (was $(( current / 1024 / 1024 / 1024 )) GB)")"