diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index a782d0f6b1ab7..37d53ce476aee 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -1278,6 +1278,17 @@ pub fn rustc_cargo( )); } + // The stage0 compiler changes infrequently and does not directly depend on code + // in the current working directory. Therefore, caching it with sccache should be + // useful. + // This is only performed for non-incremental builds, as ccache cannot deal with these. + if let Some(ref ccache) = builder.config.ccache + && compiler.stage == 0 + && !builder.config.incremental + { + cargo.env("RUSTC_WRAPPER", ccache); + } + rustc_cargo_env(builder, cargo, target, compiler.stage); } diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index 173b3ff08162d..acab02e09028e 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -148,6 +148,17 @@ impl Step for ToolBuild { &self.extra_features, ); + // The stage0 compiler changes infrequently and does not directly depend on code + // in the current working directory. Therefore, caching it with sccache should be + // useful. + // This is only performed for non-incremental builds, as ccache cannot deal with these. + if let Some(ref ccache) = builder.config.ccache + && matches!(self.mode, Mode::ToolBootstrap) + && !builder.config.incremental + { + cargo.env("RUSTC_WRAPPER", ccache); + } + // Rustc tools (miri, clippy, cargo, rustfmt, rust-analyzer) // could use the additional optimizations. if self.mode == Mode::ToolRustc && is_lto_stage(&self.compiler) {