Skip to content

Commit aae43c4

Browse files
committed
Auto merge of #136942 - Kobzol:stage0-sccache, r=jieyouxu
Use ccache for stage0 tool builds Now after the stage0 redesign, we can actually start ccaching the build of the compiler itself. We can also cache the bootstrap tools, since these are also built with the stage0 compiler. Stage0 compiler builds are now being cached: https://github.com/rust-lang/rust/actions/runs/15397246267#summary-43321151192 (`..bootstrap::core::build_steps::compile::Rustc 483.10s 40.41s -91.6%`). It's not a gigantic win everywhere, but it should help. It seems to make the Linux jobs ~10 minute faster. It should be especially useful on PR builds after #141948. r? `@jieyouxu` try-job: `x86_64-gnu-llvm-19*` try-job: `x86_64-msvc*` try-job: `x86_64-apple*` try-job: `dist-x86_64-linux`
2 parents 2f17612 + 0505ee5 commit aae43c4

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,17 @@ pub fn rustc_cargo(
12781278
));
12791279
}
12801280

1281+
// The stage0 compiler changes infrequently and does not directly depend on code
1282+
// in the current working directory. Therefore, caching it with sccache should be
1283+
// useful.
1284+
// This is only performed for non-incremental builds, as ccache cannot deal with these.
1285+
if let Some(ref ccache) = builder.config.ccache
1286+
&& compiler.stage == 0
1287+
&& !builder.config.incremental
1288+
{
1289+
cargo.env("RUSTC_WRAPPER", ccache);
1290+
}
1291+
12811292
rustc_cargo_env(builder, cargo, target, compiler.stage);
12821293
}
12831294

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ impl Step for ToolBuild {
148148
&self.extra_features,
149149
);
150150

151+
// The stage0 compiler changes infrequently and does not directly depend on code
152+
// in the current working directory. Therefore, caching it with sccache should be
153+
// useful.
154+
// This is only performed for non-incremental builds, as ccache cannot deal with these.
155+
if let Some(ref ccache) = builder.config.ccache
156+
&& matches!(self.mode, Mode::ToolBootstrap)
157+
&& !builder.config.incremental
158+
{
159+
cargo.env("RUSTC_WRAPPER", ccache);
160+
}
161+
151162
// Rustc tools (miri, clippy, cargo, rustfmt, rust-analyzer)
152163
// could use the additional optimizations.
153164
if self.mode == Mode::ToolRustc && is_lto_stage(&self.compiler) {

0 commit comments

Comments
 (0)