Skip to content

Commit 0f30dcc

Browse files
Rollup merge of #145875 - Kobzol:bootstrap-caching, r=jieyouxu
Make bootstrap command caching opt-in It was opt-out before, which was causing some really hard to debug issues. CC `@Shourya742` r? `@jieyouxu`
2 parents 6047243 + 2fd6057 commit 0f30dcc

File tree

8 files changed

+30
-17
lines changed

8 files changed

+30
-17
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,7 @@ impl Step for Assemble {
20312031

20322032
let host_llvm_bin_dir = command(&host_llvm_config)
20332033
.arg("--bindir")
2034+
.cached()
20342035
.run_capture_stdout(builder)
20352036
.stdout()
20362037
.trim()

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,6 +2269,7 @@ fn maybe_install_llvm(
22692269
{
22702270
trace!("LLVM already built, installing LLVM files");
22712271
let mut cmd = command(host_llvm_config);
2272+
cmd.cached();
22722273
cmd.arg("--libfiles");
22732274
builder.verbose(|| println!("running {cmd:?}"));
22742275
let files = cmd.run_capture_stdout(builder).stdout();

src/bootstrap/src/core/build_steps/llvm.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,11 @@ impl Step for Llvm {
486486
let LlvmResult { host_llvm_config, .. } =
487487
builder.ensure(Llvm { target: builder.config.host_target });
488488
if !builder.config.dry_run() {
489-
let llvm_bindir =
490-
command(&host_llvm_config).arg("--bindir").run_capture_stdout(builder).stdout();
489+
let llvm_bindir = command(&host_llvm_config)
490+
.arg("--bindir")
491+
.cached()
492+
.run_capture_stdout(builder)
493+
.stdout();
491494
let host_bin = Path::new(llvm_bindir.trim());
492495
cfg.define(
493496
"LLVM_TABLEGEN",
@@ -593,7 +596,13 @@ impl Step for Llvm {
593596
}
594597

595598
pub fn get_llvm_version(builder: &Builder<'_>, llvm_config: &Path) -> String {
596-
command(llvm_config).arg("--version").run_capture_stdout(builder).stdout().trim().to_owned()
599+
command(llvm_config)
600+
.arg("--version")
601+
.cached()
602+
.run_capture_stdout(builder)
603+
.stdout()
604+
.trim()
605+
.to_owned()
597606
}
598607

599608
pub fn get_llvm_version_major(builder: &Builder<'_>, llvm_config: &Path) -> u8 {

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,7 @@ HELP: You can add it into `bootstrap.toml` in `rust.codegen-backends = [{name:?}
20432043
if !builder.config.dry_run() {
20442044
let llvm_version = get_llvm_version(builder, &host_llvm_config);
20452045
let llvm_components = command(&host_llvm_config)
2046+
.cached()
20462047
.arg("--components")
20472048
.run_capture_stdout(builder)
20482049
.stdout();
@@ -2062,8 +2063,11 @@ HELP: You can add it into `bootstrap.toml` in `rust.codegen-backends = [{name:?}
20622063
// separate compilations. We can add LLVM's library path to the
20632064
// rustc args as a workaround.
20642065
if !builder.config.dry_run() && suite.ends_with("fulldeps") {
2065-
let llvm_libdir =
2066-
command(&host_llvm_config).arg("--libdir").run_capture_stdout(builder).stdout();
2066+
let llvm_libdir = command(&host_llvm_config)
2067+
.cached()
2068+
.arg("--libdir")
2069+
.run_capture_stdout(builder)
2070+
.stdout();
20672071
let link_llvm = if target.is_msvc() {
20682072
format!("-Clink-arg=-LIBPATH:{llvm_libdir}")
20692073
} else {

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,10 +1581,6 @@ impl Builder<'_> {
15811581
/// `host`.
15821582
pub fn tool_cmd(&self, tool: Tool) -> BootstrapCommand {
15831583
let mut cmd = command(self.tool_exe(tool));
1584-
1585-
// Do not cache tool invocations, as they can have side effects
1586-
cmd.do_not_cache();
1587-
15881584
let compiler = self.compiler(0, self.config.host_target);
15891585
let host = &compiler.host;
15901586
// Prepares the `cmd` provided to be able to run the `compiler` provided.

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@ impl Cargo {
132132
}
133133

134134
pub fn into_cmd(self) -> BootstrapCommand {
135-
let mut cmd: BootstrapCommand = self.into();
136-
// Disable caching for commands originating from Cargo-related operations.
137-
cmd.do_not_cache();
138-
cmd
135+
self.into()
139136
}
140137

141138
/// Same as [`Cargo::new`] except this one doesn't configure the linker with
@@ -1085,7 +1082,7 @@ impl Builder<'_> {
10851082
&& let Some(llvm_config) = self.llvm_config(target)
10861083
{
10871084
let llvm_libdir =
1088-
command(llvm_config).arg("--libdir").run_capture_stdout(self).stdout();
1085+
command(llvm_config).cached().arg("--libdir").run_capture_stdout(self).stdout();
10891086
if target.is_msvc() {
10901087
rustflags.arg(&format!("-Clink-arg=-LIBPATH:{llvm_libdir}"));
10911088
} else {

src/bootstrap/src/utils/exec.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,11 @@ impl<'a> BootstrapCommand {
264264
self
265265
}
266266

267-
pub fn do_not_cache(&mut self) -> &mut Self {
268-
self.should_cache = false;
267+
/// Cache the command. If it will be executed multiple times with the exact same arguments
268+
/// and environment variables in the same bootstrap invocation, the previous result will be
269+
/// loaded from memory.
270+
pub fn cached(&mut self) -> &mut Self {
271+
self.should_cache = true;
269272
self
270273
}
271274

@@ -425,7 +428,7 @@ impl From<Command> for BootstrapCommand {
425428
fn from(command: Command) -> Self {
426429
let program = command.get_program().to_owned();
427430
Self {
428-
should_cache: true,
431+
should_cache: false,
429432
command,
430433
failure_behavior: BehaviorOnFailure::Exit,
431434
run_in_dry_run: false,

src/bootstrap/src/utils/helpers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ pub fn check_cfg_arg(name: &str, values: Option<&[&str]>) -> String {
510510
#[track_caller]
511511
pub fn git(source_dir: Option<&Path>) -> BootstrapCommand {
512512
let mut git = command("git");
513+
// git commands are almost always read-only, so cache them by default
514+
git.cached();
513515

514516
if let Some(source_dir) = source_dir {
515517
git.current_dir(source_dir);

0 commit comments

Comments
 (0)