Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,7 @@ impl Step for Assemble {

let host_llvm_bin_dir = command(&host_llvm_config)
.arg("--bindir")
.cached()
.run_capture_stdout(builder)
.stdout()
.trim()
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,7 @@ fn maybe_install_llvm(
{
trace!("LLVM already built, installing LLVM files");
let mut cmd = command(host_llvm_config);
cmd.cached();
cmd.arg("--libfiles");
builder.verbose(|| println!("running {cmd:?}"));
let files = cmd.run_capture_stdout(builder).stdout();
Expand Down
15 changes: 12 additions & 3 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,11 @@ impl Step for Llvm {
let LlvmResult { host_llvm_config, .. } =
builder.ensure(Llvm { target: builder.config.host_target });
if !builder.config.dry_run() {
let llvm_bindir =
command(&host_llvm_config).arg("--bindir").run_capture_stdout(builder).stdout();
let llvm_bindir = command(&host_llvm_config)
.arg("--bindir")
.cached()
.run_capture_stdout(builder)
.stdout();
let host_bin = Path::new(llvm_bindir.trim());
cfg.define(
"LLVM_TABLEGEN",
Expand Down Expand Up @@ -593,7 +596,13 @@ impl Step for Llvm {
}

pub fn get_llvm_version(builder: &Builder<'_>, llvm_config: &Path) -> String {
command(llvm_config).arg("--version").run_capture_stdout(builder).stdout().trim().to_owned()
command(llvm_config)
.arg("--version")
.cached()
.run_capture_stdout(builder)
.stdout()
.trim()
.to_owned()
}

pub fn get_llvm_version_major(builder: &Builder<'_>, llvm_config: &Path) -> u8 {
Expand Down
8 changes: 6 additions & 2 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,7 @@ HELP: You can add it into `bootstrap.toml` in `rust.codegen-backends = [{name:?}
if !builder.config.dry_run() {
let llvm_version = get_llvm_version(builder, &host_llvm_config);
let llvm_components = command(&host_llvm_config)
.cached()
.arg("--components")
.run_capture_stdout(builder)
.stdout();
Expand All @@ -2062,8 +2063,11 @@ HELP: You can add it into `bootstrap.toml` in `rust.codegen-backends = [{name:?}
// separate compilations. We can add LLVM's library path to the
// rustc args as a workaround.
if !builder.config.dry_run() && suite.ends_with("fulldeps") {
let llvm_libdir =
command(&host_llvm_config).arg("--libdir").run_capture_stdout(builder).stdout();
let llvm_libdir = command(&host_llvm_config)
.cached()
.arg("--libdir")
.run_capture_stdout(builder)
.stdout();
let link_llvm = if target.is_msvc() {
format!("-Clink-arg=-LIBPATH:{llvm_libdir}")
} else {
Expand Down
4 changes: 0 additions & 4 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1581,10 +1581,6 @@ impl Builder<'_> {
/// `host`.
pub fn tool_cmd(&self, tool: Tool) -> BootstrapCommand {
let mut cmd = command(self.tool_exe(tool));

// Do not cache tool invocations, as they can have side effects
cmd.do_not_cache();

let compiler = self.compiler(0, self.config.host_target);
let host = &compiler.host;
// Prepares the `cmd` provided to be able to run the `compiler` provided.
Expand Down
7 changes: 2 additions & 5 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ impl Cargo {
}

pub fn into_cmd(self) -> BootstrapCommand {
let mut cmd: BootstrapCommand = self.into();
// Disable caching for commands originating from Cargo-related operations.
cmd.do_not_cache();
cmd
self.into()
}

/// Same as [`Cargo::new`] except this one doesn't configure the linker with
Expand Down Expand Up @@ -1085,7 +1082,7 @@ impl Builder<'_> {
&& let Some(llvm_config) = self.llvm_config(target)
{
let llvm_libdir =
command(llvm_config).arg("--libdir").run_capture_stdout(self).stdout();
command(llvm_config).cached().arg("--libdir").run_capture_stdout(self).stdout();
if target.is_msvc() {
rustflags.arg(&format!("-Clink-arg=-LIBPATH:{llvm_libdir}"));
} else {
Expand Down
9 changes: 6 additions & 3 deletions src/bootstrap/src/utils/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,11 @@ impl<'a> BootstrapCommand {
self
}

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

Expand Down Expand Up @@ -425,7 +428,7 @@ impl From<Command> for BootstrapCommand {
fn from(command: Command) -> Self {
let program = command.get_program().to_owned();
Self {
should_cache: true,
should_cache: false,
command,
failure_behavior: BehaviorOnFailure::Exit,
run_in_dry_run: false,
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ pub fn check_cfg_arg(name: &str, values: Option<&[&str]>) -> String {
#[track_caller]
pub fn git(source_dir: Option<&Path>) -> BootstrapCommand {
let mut git = command("git");
// git commands are almost always read-only, so cache them by default
git.cached();

if let Some(source_dir) = source_dir {
git.current_dir(source_dir);
Expand Down
Loading