Skip to content

Commit 6d1f14e

Browse files
committed
Fix staging for x clippy std
1 parent 9c46947 commit 6d1f14e

File tree

3 files changed

+69
-58
lines changed

3 files changed

+69
-58
lines changed

src/bootstrap/src/core/build_steps/clippy.rs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,29 @@ impl LintConfig {
134134

135135
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
136136
pub struct Std {
137-
pub target: TargetSelection,
137+
build_compiler: Compiler,
138+
target: TargetSelection,
138139
config: LintConfig,
139140
/// Whether to lint only a subset of crates.
140141
crates: Vec<String>,
141142
}
142143

144+
impl Std {
145+
fn new(
146+
builder: &Builder<'_>,
147+
target: TargetSelection,
148+
config: LintConfig,
149+
crates: Vec<String>,
150+
) -> Self {
151+
Self {
152+
build_compiler: builder.compiler(builder.top_stage, builder.host_target),
153+
target,
154+
config,
155+
crates,
156+
}
157+
}
158+
}
159+
143160
impl Step for Std {
144161
type Output = ();
145162
const DEFAULT: bool = true;
@@ -151,16 +168,16 @@ impl Step for Std {
151168
fn make_run(run: RunConfig<'_>) {
152169
let crates = std_crates_for_run_make(&run);
153170
let config = LintConfig::new(run.builder);
154-
run.builder.ensure(Std { target: run.target, config, crates });
171+
run.builder.ensure(Std::new(run.builder, run.target, config, crates));
155172
}
156173

157174
fn run(self, builder: &Builder<'_>) {
158175
let target = self.target;
159-
let compiler = builder.compiler(builder.top_stage, builder.config.host_target);
176+
let build_compiler = self.build_compiler;
160177

161178
let mut cargo = builder::Cargo::new(
162179
builder,
163-
compiler,
180+
build_compiler,
164181
Mode::Std,
165182
SourceType::InTree,
166183
target,
@@ -180,15 +197,15 @@ impl Step for Std {
180197
builder,
181198
cargo,
182199
lint_args(builder, &self.config, IGNORED_RULES_FOR_STD_AND_RUSTC),
183-
&build_stamp::libstd_stamp(builder, compiler, target),
200+
&build_stamp::libstd_stamp(builder, build_compiler, target),
184201
vec![],
185202
true,
186203
false,
187204
);
188205
}
189206

190207
fn metadata(&self) -> Option<StepMetadata> {
191-
Some(StepMetadata::clippy("std", self.target))
208+
Some(StepMetadata::clippy("std", self.target).built_by(self.build_compiler))
192209
}
193210
}
194211

@@ -507,11 +524,12 @@ impl Step for CI {
507524
],
508525
forbid: vec![],
509526
};
510-
builder.ensure(Std {
511-
target: self.target,
512-
config: self.config.merge(&library_clippy_cfg),
513-
crates: vec![],
514-
});
527+
builder.ensure(Std::new(
528+
builder,
529+
self.target,
530+
self.config.merge(&library_clippy_cfg),
531+
vec![],
532+
));
515533

516534
let compiler_clippy_cfg = LintConfig {
517535
allow: vec!["clippy::all".into()],

src/bootstrap/src/core/builder/mod.rs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,32 @@ You have to build a stage1 compiler for `{}` first, and then use it to build a s
15561556
self.ensure(tool::Rustdoc { target_compiler })
15571557
}
15581558

1559+
pub fn cargo_miri_cmd(&self, run_compiler: Compiler) -> BootstrapCommand {
1560+
assert!(run_compiler.stage > 0, "miri can not be invoked at stage 0");
1561+
1562+
let compilers =
1563+
RustcPrivateCompilers::new(self, run_compiler.stage, self.build.host_target);
1564+
assert_eq!(run_compiler, compilers.target_compiler());
1565+
1566+
// Prepare the tools
1567+
let miri = self.ensure(tool::Miri::from_compilers(compilers));
1568+
let cargo_miri = self.ensure(tool::CargoMiri::from_compilers(compilers));
1569+
// Invoke cargo-miri, make sure it can find miri and cargo.
1570+
let mut cmd = command(cargo_miri.tool_path);
1571+
cmd.env("MIRI", &miri.tool_path);
1572+
cmd.env("CARGO", &self.initial_cargo);
1573+
// Need to add the `run_compiler` libs. Those are the libs produces *by* `build_compiler`
1574+
// in `tool::ToolBuild` step, so they match the Miri we just built. However this means they
1575+
// are actually living one stage up, i.e. we are running `stage0-tools-bin/miri` with the
1576+
// libraries in `stage1/lib`. This is an unfortunate off-by-1 caused (possibly) by the fact
1577+
// that Miri doesn't have an "assemble" step like rustc does that would cross the stage boundary.
1578+
// We can't use `add_rustc_lib_path` as that's a NOP on Windows but we do need these libraries
1579+
// added to the PATH due to the stage mismatch.
1580+
// Also see https://github.com/rust-lang/rust/pull/123192#issuecomment-2028901503.
1581+
add_dylib_path(self.rustc_lib_paths(run_compiler), &mut cmd);
1582+
cmd
1583+
}
1584+
15591585
/// Create a Cargo command for running Clippy.
15601586
/// The used Clippy is (or in the case of stage 0, already was) built using `build_compiler`.
15611587
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
15711597
return cmd;
15721598
}
15731599

1574-
let compilers = RustcPrivateCompilers::from_build_compiler(
1575-
self,
1576-
build_compiler,
1577-
self.build.host_target,
1578-
);
1600+
// If we're linting something with build_compiler stage N, we want to build Clippy stage N
1601+
// and use that to lint it. That is why we use the `build_compiler` as the target compiler
1602+
// for RustcPrivateCompilers. We will use build compiler stage N-1 to build Clippy stage N.
1603+
let compilers = RustcPrivateCompilers::from_target_compiler(self, build_compiler);
15791604

15801605
let _ = self.ensure(tool::Clippy::from_compilers(compilers));
15811606
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
15881613
cmd
15891614
}
15901615

1591-
pub fn cargo_miri_cmd(&self, run_compiler: Compiler) -> BootstrapCommand {
1592-
assert!(run_compiler.stage > 0, "miri can not be invoked at stage 0");
1593-
1594-
let compilers =
1595-
RustcPrivateCompilers::new(self, run_compiler.stage, self.build.host_target);
1596-
assert_eq!(run_compiler, compilers.target_compiler());
1597-
1598-
// Prepare the tools
1599-
let miri = self.ensure(tool::Miri::from_compilers(compilers));
1600-
let cargo_miri = self.ensure(tool::CargoMiri::from_compilers(compilers));
1601-
// Invoke cargo-miri, make sure it can find miri and cargo.
1602-
let mut cmd = command(cargo_miri.tool_path);
1603-
cmd.env("MIRI", &miri.tool_path);
1604-
cmd.env("CARGO", &self.initial_cargo);
1605-
// Need to add the `run_compiler` libs. Those are the libs produces *by* `build_compiler`
1606-
// in `tool::ToolBuild` step, so they match the Miri we just built. However this means they
1607-
// are actually living one stage up, i.e. we are running `stage0-tools-bin/miri` with the
1608-
// libraries in `stage1/lib`. This is an unfortunate off-by-1 caused (possibly) by the fact
1609-
// that Miri doesn't have an "assemble" step like rustc does that would cross the stage boundary.
1610-
// We can't use `add_rustc_lib_path` as that's a NOP on Windows but we do need these libraries
1611-
// added to the PATH due to the stage mismatch.
1612-
// Also see https://github.com/rust-lang/rust/pull/123192#issuecomment-2028901503.
1613-
add_dylib_path(self.rustc_lib_paths(run_compiler), &mut cmd);
1614-
cmd
1615-
}
1616-
16171616
pub fn rustdoc_cmd(&self, compiler: Compiler) -> BootstrapCommand {
16181617
let mut cmd = command(self.bootstrap_out.join("rustdoc"));
16191618
cmd.env("RUSTC_STAGE", compiler.stage.to_string())

src/bootstrap/src/core/builder/tests.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,12 +2076,10 @@ mod snapshot {
20762076
[build] llvm <host>
20772077
[build] rustc 0 <host> -> rustc 1 <host>
20782078
[check] rustc 1 <host> -> rustc 2 <host>
2079-
[build] rustc 1 <host> -> std 1 <host>
2080-
[build] rustc 1 <host> -> rustc 2 <host>
2081-
[build] rustc 1 <host> -> clippy-driver 2 <host>
2082-
[build] rustc 1 <host> -> cargo-clippy 2 <host>
2079+
[build] rustc 0 <host> -> clippy-driver 1 <host>
2080+
[build] rustc 0 <host> -> cargo-clippy 1 <host>
20832081
[clippy] bootstrap <host>
2084-
[clippy] std <host>
2082+
[clippy] rustc 1 <host> -> std 1 <host>
20852083
[clippy] rustc 0 <host> -> rustc 1 <host>
20862084
[clippy] rustc 0 <host> -> rustc_codegen_gcc 1 <host>
20872085
");
@@ -2100,14 +2098,12 @@ mod snapshot {
21002098
[build] rustc 1 <host> -> std 1 <host>
21012099
[build] rustc 1 <host> -> rustc 2 <host>
21022100
[check] rustc 2 <host> -> rustc 3 <host>
2103-
[build] rustc 2 <host> -> std 2 <host>
2104-
[build] rustc 2 <host> -> rustc 3 <host>
2105-
[build] rustc 2 <host> -> clippy-driver 3 <host>
2106-
[build] rustc 2 <host> -> cargo-clippy 3 <host>
2107-
[clippy] bootstrap <host>
2108-
[clippy] std <host>
21092101
[build] rustc 1 <host> -> clippy-driver 2 <host>
21102102
[build] rustc 1 <host> -> cargo-clippy 2 <host>
2103+
[clippy] bootstrap <host>
2104+
[clippy] rustc 2 <host> -> std 2 <host>
2105+
[build] rustc 0 <host> -> clippy-driver 1 <host>
2106+
[build] rustc 0 <host> -> cargo-clippy 1 <host>
21112107
[clippy] rustc 1 <host> -> rustc 2 <host>
21122108
[clippy] rustc 1 <host> -> rustc_codegen_gcc 2 <host>
21132109
");
@@ -2134,11 +2130,9 @@ mod snapshot {
21342130
.render_steps(), @r"
21352131
[build] llvm <host>
21362132
[build] rustc 0 <host> -> rustc 1 <host>
2137-
[build] rustc 1 <host> -> std 1 <host>
2138-
[build] rustc 1 <host> -> rustc 2 <host>
2139-
[build] rustc 1 <host> -> clippy-driver 2 <host>
2140-
[build] rustc 1 <host> -> cargo-clippy 2 <host>
2141-
[clippy] std <host>
2133+
[build] rustc 0 <host> -> clippy-driver 1 <host>
2134+
[build] rustc 0 <host> -> cargo-clippy 1 <host>
2135+
[clippy] rustc 1 <host> -> std 1 <host>
21422136
");
21432137
}
21442138
}

0 commit comments

Comments
 (0)