From e3b56cb213bd6a6151ba76cdff04120f953cedcf Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sat, 28 Nov 2026 18:32:20 -0700 Subject: [PATCH] Never start sccache unless asked; compact reasons panel A server started from the dashboard has the dashboard's environment, not the builds'. It came up with the 10 GB default beside a 250 GB cache and sccache trimmed the cache. Starting is now opt-in (SCCACHE_DASH_START_SCCACHE=1) and the README says why. Co-Authored-By: Claude Fable 5.2 --- README.md | 10 ++++++++-- crates/server/src/app.rs | 14 ++++++++++++-- crates/server/tests/http.rs | 25 +++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7e3ef7b..124ef24 100644 --- a/README.md +++ b/README.md @@ -74,8 +74,14 @@ reading ever is a baseline and counts for nothing. ## Notes on sccache -When no sccache server is running, sccache-dash starts one (`sccache --start-server`); if that -fails it shows "not running" with the error and tries again a minute later. +sccache-dash never starts or stops sccache's server by itself. When none is running it shows +"not running"; sccache starts its own server on your next build, with your build's settings. + +To have sccache-dash start the server when none is running, set `SCCACHE_DASH_START_SCCACHE=1` +in its environment. Be careful with this: a server started that way gets sccache-dash's +environment, not your build's. If your cache size or folder is set only in your build's +environment, the server comes up with sccache's defaults, and sccache deletes cache entries +until the cache fits the 10 GB default. While sccache-dash runs, sccache's server stays up: being asked for its stats every 10 seconds keeps it from shutting itself down after 10 idle minutes. diff --git a/crates/server/src/app.rs b/crates/server/src/app.rs index 6ad0fed..ec1c8f3 100644 --- a/crates/server/src/app.rs +++ b/crates/server/src/app.rs @@ -34,10 +34,16 @@ pub struct Config { pub sccache: OsString, /// The SQLite file the history is saved in. pub history: PathBuf, + /// Whether to start sccache's server when none is listening. Off unless asked for: a + /// server started from here has this program's environment, not the builds', so it can + /// come up with another cache size or folder, and sccache trims the cache to the size + /// it is started with. + pub start_sccache: bool, } impl Config { - /// `SCCACHE_DASH_SCCACHE` names the sccache command (`sccache` when unset); the history + /// `SCCACHE_DASH_SCCACHE` names the sccache command (`sccache` when unset); + /// `SCCACHE_DASH_START_SCCACHE=1` lets it start sccache's server; the history /// lives in `$XDG_DATA_HOME/sccache-dash/history.db`. pub fn from_env() -> Result { let sccache = std::env::var_os("SCCACHE_DASH_SCCACHE").unwrap_or_else(|| "sccache".into()); @@ -46,6 +52,7 @@ impl Config { Ok(Config { sccache, history: dir.join("sccache-dash").join("history.db"), + start_sccache: std::env::var_os("SCCACHE_DASH_START_SCCACHE").is_some_and(|v| v == "1"), }) } } @@ -299,9 +306,12 @@ impl Task { } } - /// Starts sccache's server when none is listening, at most once a minute. `Err` says why + /// Starts sccache's server when none is listening and that was asked for, at most once a minute. `Err` says why /// there is none, including when an earlier attempt is still being waited out. fn start_server(&mut self, app: &App, now: i64) -> Result<(), String> { + if !app.cfg.start_sccache { + return Err("no sccache server is running; your next build starts it".to_owned()); + } if let Some(when) = self.started_at { if now - when < START_EVERY { return Err(self diff --git a/crates/server/tests/http.rs b/crates/server/tests/http.rs index 8839e11..77f6c69 100644 --- a/crates/server/tests/http.rs +++ b/crates/server/tests/http.rs @@ -91,6 +91,7 @@ esac Config { sccache: self.script.clone().into(), history: self.history.clone(), + start_sccache: true, } } } @@ -444,6 +445,30 @@ fn old_rows_are_deleted_at_startup() { ); } +#[test] +fn a_missing_sccache_server_is_left_alone_unless_starting_was_asked_for() { + let fake = Fake::new(); + fake.down(); + let app = App::with_probe( + Config { + start_sccache: false, + ..fake.config() + }, + fake.probe(), + ); + let mut task = Task::memory(); + + task.poll(&app, NOW); + task.poll(&app, NOW + 120); + let calls = fake.calls(); + assert!(!calls.iter().any(|c| c == "--start-server"), "{calls:?}"); + assert!(app + .lock() + .error + .as_deref() + .is_some_and(|e| e.contains("your next build starts it"))); +} + #[test] fn a_missing_sccache_server_is_started_once_then_read() { let fake = Fake::new();