diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index 364d9bed883b..f67cf0edf02f 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, } +impl Std { + fn new( + builder: &Builder<'_>, + target: TargetSelection, + config: LintConfig, + crates: Vec, + ) -> 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 { - 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 9719bcbc5632..54bf1842ab31 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -1556,38 +1556,6 @@ You have to build a stage1 compiler for `{}` first, and then use it to build a s self.ensure(tool::Rustdoc { target_compiler }) } - /// 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 { - if build_compiler.stage == 0 { - let cargo_clippy = self - .config - .initial_cargo_clippy - .clone() - .unwrap_or_else(|| self.build.config.download_clippy()); - - let mut cmd = command(cargo_clippy); - cmd.env("CARGO", &self.initial_cargo); - return cmd; - } - - let compilers = RustcPrivateCompilers::from_build_compiler( - self, - build_compiler, - self.build.host_target, - ); - - let _ = self.ensure(tool::Clippy::from_compilers(compilers)); - let cargo_clippy = self.ensure(tool::CargoClippy::from_compilers(compilers)); - let mut dylib_path = helpers::dylib_path(); - dylib_path.insert(0, self.sysroot(build_compiler).join("lib")); - - let mut cmd = command(cargo_clippy.tool_path); - cmd.env(helpers::dylib_path_var(), env::join_paths(&dylib_path).unwrap()); - cmd.env("CARGO", &self.initial_cargo); - cmd - } - pub fn cargo_miri_cmd(&self, run_compiler: Compiler) -> BootstrapCommand { assert!(run_compiler.stage > 0, "miri can not be invoked at stage 0"); @@ -1614,6 +1582,37 @@ You have to build a stage1 compiler for `{}` first, and then use it to build a s 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 { + if build_compiler.stage == 0 { + let cargo_clippy = self + .config + .initial_cargo_clippy + .clone() + .unwrap_or_else(|| self.build.config.download_clippy()); + + let mut cmd = command(cargo_clippy); + cmd.env("CARGO", &self.initial_cargo); + return cmd; + } + + // 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)); + let mut dylib_path = helpers::dylib_path(); + dylib_path.insert(0, self.sysroot(build_compiler).join("lib")); + + let mut cmd = command(cargo_clippy.tool_path); + cmd.env(helpers::dylib_path_var(), env::join_paths(&dylib_path).unwrap()); + cmd.env("CARGO", &self.initial_cargo); + 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 c521b7f5d074..28bec10f0619 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 [build] rustc 0 -> rustc 1 [check] rustc 1 -> rustc 2 - [build] rustc 1 -> std 1 - [build] rustc 1 -> rustc 2 - [build] rustc 1 -> clippy-driver 2 - [build] rustc 1 -> cargo-clippy 2 + [build] rustc 0 -> clippy-driver 1 + [build] rustc 0 -> cargo-clippy 1 [clippy] bootstrap - [clippy] std + [clippy] rustc 1 -> std 1 [clippy] rustc 0 -> rustc 1 [clippy] rustc 0 -> rustc_codegen_gcc 1 "); @@ -2100,14 +2098,12 @@ mod snapshot { [build] rustc 1 -> std 1 [build] rustc 1 -> rustc 2 [check] rustc 2 -> rustc 3 - [build] rustc 2 -> std 2 - [build] rustc 2 -> rustc 3 - [build] rustc 2 -> clippy-driver 3 - [build] rustc 2 -> cargo-clippy 3 - [clippy] bootstrap - [clippy] std [build] rustc 1 -> clippy-driver 2 [build] rustc 1 -> cargo-clippy 2 + [clippy] bootstrap + [clippy] rustc 2 -> std 2 + [build] rustc 0 -> clippy-driver 1 + [build] rustc 0 -> cargo-clippy 1 [clippy] rustc 1 -> rustc 2 [clippy] rustc 1 -> rustc_codegen_gcc 2 "); @@ -2134,11 +2130,9 @@ mod snapshot { .render_steps(), @r" [build] llvm [build] rustc 0 -> rustc 1 - [build] rustc 1 -> std 1 - [build] rustc 1 -> rustc 2 - [build] rustc 1 -> clippy-driver 2 - [build] rustc 1 -> cargo-clippy 2 - [clippy] std + [build] rustc 0 -> clippy-driver 1 + [build] rustc 0 -> cargo-clippy 1 + [clippy] rustc 1 -> std 1 "); } }