diff options
| author | bors <bors@rust-lang.org> | 2025-08-26 15:11:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-08-26 15:11:20 +0000 |
| commit | 91ee6a4057ce4bf1ab6d2f932cae497488d67c81 (patch) | |
| tree | 581c0f5857586659aab7d8a6dcfa95f2affecf2b /src/bootstrap | |
| parent | 5ab69249f36678c0a770a08d3d1b28a8103349ff (diff) | |
| parent | 0f30dcc271f61156240a782059010b77eb28ee6d (diff) | |
| download | rust-91ee6a4057ce4bf1ab6d2f932cae497488d67c81.tar.gz rust-91ee6a4057ce4bf1ab6d2f932cae497488d67c81.zip | |
Auto merge of #145886 - GuillaumeGomez:rollup-9qv7jhv, r=GuillaumeGomez
Rollup of 11 pull requests Successful merges: - rust-lang/rust#144373 (remove deprecated Error::description in impls) - rust-lang/rust#144551 (Add aarch64_be-unknown-linux-musl target) - rust-lang/rust#145076 (Add new Tier-3 target: riscv64a23-unknown-linux-gnu) - rust-lang/rust#145481 (Add parentheses for closure when suggesting calling closure) - rust-lang/rust#145596 (Losslessly optimize PNG files) - rust-lang/rust#145615 (Fix doc of `std::os::windows::io::BorrowedSocket::borrow_raw`) - rust-lang/rust#145841 (Always build miri for the host in `x run miri`) - rust-lang/rust#145861 (bootstrap: vendor `clippy_test_deps` too) - rust-lang/rust#145863 (formatting_options: Make all methods `const`) - rust-lang/rust#145867 (cg_llvm: Assert that LLVM range-attribute values don't exceed 128 bits) - rust-lang/rust#145875 (Make bootstrap command caching opt-in) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'src/bootstrap')
| -rw-r--r-- | src/bootstrap/src/core/build_steps/compile.rs | 1 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/dist.rs | 1 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/llvm.rs | 15 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/run.rs | 47 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/test.rs | 8 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/tool.rs | 4 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/vendor.rs | 1 | ||||
| -rw-r--r-- | src/bootstrap/src/core/builder/cargo.rs | 7 | ||||
| -rw-r--r-- | src/bootstrap/src/core/builder/mod.rs | 4 | ||||
| -rw-r--r-- | src/bootstrap/src/core/builder/tests.rs | 18 | ||||
| -rw-r--r-- | src/bootstrap/src/core/config/config.rs | 4 | ||||
| -rw-r--r-- | src/bootstrap/src/core/sanity.rs | 1 | ||||
| -rw-r--r-- | src/bootstrap/src/utils/exec.rs | 9 | ||||
| -rw-r--r-- | src/bootstrap/src/utils/helpers.rs | 2 |
14 files changed, 88 insertions, 34 deletions
diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index f7a2dc14218..a4976139fe9 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -2031,6 +2031,7 @@ impl Step for Assemble { let host_llvm_bin_dir = command(&host_llvm_config) .arg("--bindir") + .cached() .run_capture_stdout(builder) .stdout() .trim() diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index b01832708df..778c3beb50f 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -2281,6 +2281,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(); diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 70259f0d1d7..d47c1495838 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -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", @@ -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 { diff --git a/src/bootstrap/src/core/build_steps/run.rs b/src/bootstrap/src/core/build_steps/run.rs index c6288f63847..d9de6b7ef96 100644 --- a/src/bootstrap/src/core/build_steps/run.rs +++ b/src/bootstrap/src/core/build_steps/run.rs @@ -5,13 +5,14 @@ use std::path::PathBuf; +use build_helper::exit; use clap_complete::{Generator, shells}; use crate::core::build_steps::dist::distdir; use crate::core::build_steps::test; use crate::core::build_steps::tool::{self, RustcPrivateCompilers, SourceType, Tool}; use crate::core::build_steps::vendor::{Vendor, default_paths_to_vendor}; -use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step}; +use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step, StepMetadata}; use crate::core::config::TargetSelection; use crate::core::config::flags::get_completion; use crate::utils::exec::command; @@ -100,8 +101,17 @@ impl Step for ReplaceVersionPlaceholder { } } +/// Invoke the Miri tool on a specified file. +/// +/// Note that Miri always executed on the host, as it is an interpreter. +/// That means that `x run miri --target FOO` will build miri for the host, +/// prepare a miri sysroot for the target `FOO` and then execute miri with +/// the target `FOO`. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Miri { + /// The build compiler that will build miri and the target compiler to which miri links. + compilers: RustcPrivateCompilers, + /// The target which will miri interpret. target: TargetSelection, } @@ -113,14 +123,9 @@ impl Step for Miri { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Miri { target: run.target }); - } - - fn run(self, builder: &Builder<'_>) { - let host = builder.build.host_target; - let target = self.target; + let builder = run.builder; - // `x run` uses stage 0 by default but miri does not work well with stage 0. + // `x run` uses stage 0 by default, but miri does not work well with stage 0. // Change the stage to 1 if it's not set explicitly. let stage = if builder.config.is_explicit_stage() || builder.top_stage >= 1 { builder.top_stage @@ -129,14 +134,22 @@ impl Step for Miri { }; if stage == 0 { - eprintln!("miri cannot be run at stage 0"); - std::process::exit(1); + eprintln!("ERROR: miri cannot be run at stage 0"); + exit!(1); } - // This compiler runs on the host, we'll just use it for the target. - let compilers = RustcPrivateCompilers::new(builder, stage, target); - let miri_build = builder.ensure(tool::Miri::from_compilers(compilers)); - let host_compiler = miri_build.build_compiler; + // Miri always runs on the host, because it can interpret code for any target + let compilers = RustcPrivateCompilers::new(builder, stage, builder.host_target); + + run.builder.ensure(Miri { compilers, target: run.target }); + } + + fn run(self, builder: &Builder<'_>) { + let host = builder.build.host_target; + let compilers = self.compilers; + let target = self.target; + + builder.ensure(tool::Miri::from_compilers(compilers)); // Get a target sysroot for Miri. let miri_sysroot = @@ -147,7 +160,7 @@ impl Step for Miri { // add_rustc_lib_path does not add the path that contains librustc_driver-<...>.so. let mut miri = tool::prepare_tool_cargo( builder, - host_compiler, + compilers.build_compiler(), Mode::ToolRustc, host, Kind::Run, @@ -167,6 +180,10 @@ impl Step for Miri { miri.into_cmd().run(builder); } + + fn metadata(&self) -> Option<StepMetadata> { + Some(StepMetadata::run("miri", self.target).built_by(self.compilers.build_compiler())) + } } #[derive(Debug, Clone, Hash, PartialEq, Eq)] diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index b52707032ba..a6156cad6fc 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -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(); @@ -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 { diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index c10b8253646..b62c9a906b7 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -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. diff --git a/src/bootstrap/src/core/build_steps/vendor.rs b/src/bootstrap/src/core/build_steps/vendor.rs index 7b860ceb943..0e9d4e7e32b 100644 --- a/src/bootstrap/src/core/build_steps/vendor.rs +++ b/src/bootstrap/src/core/build_steps/vendor.rs @@ -19,6 +19,7 @@ pub const VENDOR_DIR: &str = "vendor"; pub fn default_paths_to_vendor(builder: &Builder<'_>) -> Vec<(PathBuf, Vec<&'static str>)> { [ ("src/tools/cargo/Cargo.toml", vec!["src/tools/cargo"]), + ("src/tools/clippy/clippy_test_deps/Cargo.toml", vec![]), ("src/tools/rust-analyzer/Cargo.toml", vec![]), ("compiler/rustc_codegen_cranelift/Cargo.toml", vec![]), ("compiler/rustc_codegen_gcc/Cargo.toml", vec![]), diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs index 72192403412..9c417952a5f 100644 --- a/src/bootstrap/src/core/builder/cargo.rs +++ b/src/bootstrap/src/core/builder/cargo.rs @@ -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 @@ -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 { diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index 76cade25a03..27e416359a9 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -181,6 +181,10 @@ impl StepMetadata { Self::new(name, target, Kind::Test) } + pub fn run(name: &str, target: TargetSelection) -> Self { + Self::new(name, target, Kind::Run) + } + fn new(name: &str, target: TargetSelection, kind: Kind) -> Self { Self { name: name.to_string(), kind, target, built_by: None, stage: None, metadata: None } } diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 4d47562c7ce..f7067d11450 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -2427,6 +2427,24 @@ mod snapshot { [dist] src <> "); } + + // Check that `x run miri --target FOO` actually builds miri for the host. + #[test] + fn run_miri() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("run") + .path("miri") + .stage(1) + .targets(&[TEST_TRIPLE_1]) + .render_steps(), @r" + [build] llvm <host> + [build] rustc 0 <host> -> rustc 1 <host> + [build] rustc 0 <host> -> miri 1 <host> + [build] rustc 0 <host> -> cargo-miri 1 <host> + [run] rustc 0 <host> -> miri 1 <target1> + "); + } } struct ExecutedSteps { diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index e5c2e3c64b8..3e9c8ccb4fa 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -960,8 +960,8 @@ impl Config { Subcommand::Dist => flags_stage.or(build_dist_stage).unwrap_or(2), Subcommand::Install => flags_stage.or(build_install_stage).unwrap_or(2), Subcommand::Perf { .. } => flags_stage.unwrap_or(1), - // These are all bootstrap tools, which don't depend on the compiler. - // The stage we pass shouldn't matter, but use 0 just in case. + // Most of the run commands execute bootstrap tools, which don't depend on the compiler. + // Other commands listed here should always use bootstrap tools. Subcommand::Clean { .. } | Subcommand::Run { .. } | Subcommand::Setup { .. } diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index 4916ebbd610..099ec488397 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -34,6 +34,7 @@ pub struct Finder { // Targets can be removed from this list once they are present in the stage0 compiler (usually by updating the beta compiler of the bootstrap). const STAGE0_MISSING_TARGETS: &[&str] = &[ "armv7a-vex-v5", + "riscv64a23-unknown-linux-gnu", // just a dummy comment so the list doesn't get onelined "aarch64_be-unknown-hermit", "aarch64_be-unknown-none-softfloat", diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs index 9a536f75ab7..e09f3086b77 100644 --- a/src/bootstrap/src/utils/exec.rs +++ b/src/bootstrap/src/utils/exec.rs @@ -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 } @@ -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, diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs index 451482717b6..e802c0214dd 100644 --- a/src/bootstrap/src/utils/helpers.rs +++ b/src/bootstrap/src/utils/helpers.rs @@ -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); |
