about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJakub Beránek <berykubik@gmail.com>2025-08-08 17:23:34 +0200
committerJakub Beránek <berykubik@gmail.com>2025-08-13 08:11:00 +0200
commitc5dac1aa2a48ac014c8a33a5c8c8334ed48afafa (patch)
treeb972eae847f73bfbdd386726db5b6ea6b050fc20
parent2071a68bd6e81a8e6779ee247048d37cd865a8c9 (diff)
downloadrust-c5dac1aa2a48ac014c8a33a5c8c8334ed48afafa.tar.gz
rust-c5dac1aa2a48ac014c8a33a5c8c8334ed48afafa.zip
Fix staging for `x clippy std`
-rw-r--r--src/bootstrap/src/core/build_steps/clippy.rs36
-rw-r--r--src/bootstrap/src/core/builder/mod.rs61
-rw-r--r--src/bootstrap/src/core/builder/tests.rs26
3 files changed, 67 insertions, 56 deletions
diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs
index 364d9bed883..f67cf0edf02 100644
--- a/src/bootstrap/src/core/build_steps/clippy.rs
+++ b/src/bootstrap/src/core/build_steps/clippy.rs
@@ -134,12 +134,29 @@ impl LintConfig {
 
 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
 pub struct Std {
-    pub target: TargetSelection,
+    build_compiler: Compiler,
+    target: TargetSelection,
     config: LintConfig,
     /// Whether to lint only a subset of crates.
     crates: Vec<String>,
 }
 
+impl Std {
+    fn new(
+        builder: &Builder<'_>,
+        target: TargetSelection,
+        config: LintConfig,
+        crates: Vec<String>,
+    ) -> Self {
+        Self {
+            build_compiler: builder.compiler(builder.top_stage, builder.host_target),
+            target,
+            config,
+            crates,
+        }
+    }
+}
+
 impl Step for Std {
     type Output = ();
     const DEFAULT: bool = true;
@@ -151,12 +168,12 @@ impl Step for Std {
     fn make_run(run: RunConfig<'_>) {
         let crates = std_crates_for_run_make(&run);
         let config = LintConfig::new(run.builder);
-        run.builder.ensure(Std { target: run.target, config, crates });
+        run.builder.ensure(Std::new(run.builder, run.target, config, crates));
     }
 
     fn run(self, builder: &Builder<'_>) {
         let target = self.target;
-        let build_compiler = builder.compiler(builder.top_stage, builder.config.host_target);
+        let build_compiler = self.build_compiler;
 
         let mut cargo = builder::Cargo::new(
             builder,
@@ -193,7 +210,7 @@ impl Step for Std {
     }
 
     fn metadata(&self) -> Option<StepMetadata> {
-        Some(StepMetadata::clippy("std", self.target))
+        Some(StepMetadata::clippy("std", self.target).built_by(self.build_compiler))
     }
 }
 
@@ -510,11 +527,12 @@ impl Step for CI {
             ],
             forbid: vec![],
         };
-        builder.ensure(Std {
-            target: self.target,
-            config: self.config.merge(&library_clippy_cfg),
-            crates: vec![],
-        });
+        builder.ensure(Std::new(
+            builder,
+            self.target,
+            self.config.merge(&library_clippy_cfg),
+            vec![],
+        ));
 
         let compiler_clippy_cfg = LintConfig {
             allow: vec!["clippy::all".into()],
diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs
index 9719bcbc563..54bf1842ab3 100644
--- a/src/bootstrap/src/core/builder/mod.rs
+++ b/src/bootstrap/src/core/builder/mod.rs
@@ -1556,6 +1556,32 @@ You have to build a stage1 compiler for `{}` first, and then use it to build a s
         self.ensure(tool::Rustdoc { target_compiler })
     }
 
+    pub fn cargo_miri_cmd(&self, run_compiler: Compiler) -> BootstrapCommand {
+        assert!(run_compiler.stage > 0, "miri can not be invoked at stage 0");
+
+        let compilers =
+            RustcPrivateCompilers::new(self, run_compiler.stage, self.build.host_target);
+        assert_eq!(run_compiler, compilers.target_compiler());
+
+        // Prepare the tools
+        let miri = self.ensure(tool::Miri::from_compilers(compilers));
+        let cargo_miri = self.ensure(tool::CargoMiri::from_compilers(compilers));
+        // Invoke cargo-miri, make sure it can find miri and cargo.
+        let mut cmd = command(cargo_miri.tool_path);
+        cmd.env("MIRI", &miri.tool_path);
+        cmd.env("CARGO", &self.initial_cargo);
+        // Need to add the `run_compiler` libs. Those are the libs produces *by* `build_compiler`
+        // in `tool::ToolBuild` step, so they match the Miri we just built. However this means they
+        // are actually living one stage up, i.e. we are running `stage1-tools-bin/miri` with the
+        // libraries in `stage1/lib`. This is an unfortunate off-by-1 caused (possibly) by the fact
+        // that Miri doesn't have an "assemble" step like rustc does that would cross the stage boundary.
+        // We can't use `add_rustc_lib_path` as that's a NOP on Windows but we do need these libraries
+        // added to the PATH due to the stage mismatch.
+        // Also see https://github.com/rust-lang/rust/pull/123192#issuecomment-2028901503.
+        add_dylib_path(self.rustc_lib_paths(run_compiler), &mut cmd);
+        cmd
+    }
+
     /// Create a Cargo command for running Clippy.
     /// The used Clippy is (or in the case of stage 0, already was) built using `build_compiler`.
     pub fn cargo_clippy_cmd(&self, build_compiler: Compiler) -> BootstrapCommand {
@@ -1571,11 +1597,10 @@ You have to build a stage1 compiler for `{}` first, and then use it to build a s
             return cmd;
         }
 
-        let compilers = RustcPrivateCompilers::from_build_compiler(
-            self,
-            build_compiler,
-            self.build.host_target,
-        );
+        // If we're linting something with build_compiler stage N, we want to build Clippy stage N
+        // and use that to lint it. That is why we use the `build_compiler` as the target compiler
+        // for RustcPrivateCompilers. We will use build compiler stage N-1 to build Clippy stage N.
+        let compilers = RustcPrivateCompilers::from_target_compiler(self, build_compiler);
 
         let _ = self.ensure(tool::Clippy::from_compilers(compilers));
         let cargo_clippy = self.ensure(tool::CargoClippy::from_compilers(compilers));
@@ -1588,32 +1613,6 @@ You have to build a stage1 compiler for `{}` first, and then use it to build a s
         cmd
     }
 
-    pub fn cargo_miri_cmd(&self, run_compiler: Compiler) -> BootstrapCommand {
-        assert!(run_compiler.stage > 0, "miri can not be invoked at stage 0");
-
-        let compilers =
-            RustcPrivateCompilers::new(self, run_compiler.stage, self.build.host_target);
-        assert_eq!(run_compiler, compilers.target_compiler());
-
-        // Prepare the tools
-        let miri = self.ensure(tool::Miri::from_compilers(compilers));
-        let cargo_miri = self.ensure(tool::CargoMiri::from_compilers(compilers));
-        // Invoke cargo-miri, make sure it can find miri and cargo.
-        let mut cmd = command(cargo_miri.tool_path);
-        cmd.env("MIRI", &miri.tool_path);
-        cmd.env("CARGO", &self.initial_cargo);
-        // Need to add the `run_compiler` libs. Those are the libs produces *by* `build_compiler`
-        // in `tool::ToolBuild` step, so they match the Miri we just built. However this means they
-        // are actually living one stage up, i.e. we are running `stage1-tools-bin/miri` with the
-        // libraries in `stage1/lib`. This is an unfortunate off-by-1 caused (possibly) by the fact
-        // that Miri doesn't have an "assemble" step like rustc does that would cross the stage boundary.
-        // We can't use `add_rustc_lib_path` as that's a NOP on Windows but we do need these libraries
-        // added to the PATH due to the stage mismatch.
-        // Also see https://github.com/rust-lang/rust/pull/123192#issuecomment-2028901503.
-        add_dylib_path(self.rustc_lib_paths(run_compiler), &mut cmd);
-        cmd
-    }
-
     pub fn rustdoc_cmd(&self, compiler: Compiler) -> BootstrapCommand {
         let mut cmd = command(self.bootstrap_out.join("rustdoc"));
         cmd.env("RUSTC_STAGE", compiler.stage.to_string())
diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs
index c521b7f5d07..28bec10f061 100644
--- a/src/bootstrap/src/core/builder/tests.rs
+++ b/src/bootstrap/src/core/builder/tests.rs
@@ -2076,12 +2076,10 @@ mod snapshot {
         [build] llvm <host>
         [build] rustc 0 <host> -> rustc 1 <host>
         [check] rustc 1 <host> -> rustc 2 <host>
-        [build] rustc 1 <host> -> std 1 <host>
-        [build] rustc 1 <host> -> rustc 2 <host>
-        [build] rustc 1 <host> -> clippy-driver 2 <host>
-        [build] rustc 1 <host> -> cargo-clippy 2 <host>
+        [build] rustc 0 <host> -> clippy-driver 1 <host>
+        [build] rustc 0 <host> -> cargo-clippy 1 <host>
         [clippy] bootstrap <host>
-        [clippy] std <host>
+        [clippy] rustc 1 <host> -> std 1 <host>
         [clippy] rustc 0 <host> -> rustc 1 <host>
         [clippy] rustc 0 <host> -> rustc_codegen_gcc 1 <host>
         ");
@@ -2100,14 +2098,12 @@ mod snapshot {
         [build] rustc 1 <host> -> std 1 <host>
         [build] rustc 1 <host> -> rustc 2 <host>
         [check] rustc 2 <host> -> rustc 3 <host>
-        [build] rustc 2 <host> -> std 2 <host>
-        [build] rustc 2 <host> -> rustc 3 <host>
-        [build] rustc 2 <host> -> clippy-driver 3 <host>
-        [build] rustc 2 <host> -> cargo-clippy 3 <host>
-        [clippy] bootstrap <host>
-        [clippy] std <host>
         [build] rustc 1 <host> -> clippy-driver 2 <host>
         [build] rustc 1 <host> -> cargo-clippy 2 <host>
+        [clippy] bootstrap <host>
+        [clippy] rustc 2 <host> -> std 2 <host>
+        [build] rustc 0 <host> -> clippy-driver 1 <host>
+        [build] rustc 0 <host> -> cargo-clippy 1 <host>
         [clippy] rustc 1 <host> -> rustc 2 <host>
         [clippy] rustc 1 <host> -> rustc_codegen_gcc 2 <host>
         ");
@@ -2134,11 +2130,9 @@ mod snapshot {
                 .render_steps(), @r"
         [build] llvm <host>
         [build] rustc 0 <host> -> rustc 1 <host>
-        [build] rustc 1 <host> -> std 1 <host>
-        [build] rustc 1 <host> -> rustc 2 <host>
-        [build] rustc 1 <host> -> clippy-driver 2 <host>
-        [build] rustc 1 <host> -> cargo-clippy 2 <host>
-        [clippy] std <host>
+        [build] rustc 0 <host> -> clippy-driver 1 <host>
+        [build] rustc 0 <host> -> cargo-clippy 1 <host>
+        [clippy] rustc 1 <host> -> std 1 <host>
         ");
     }
 }