Skip to content

Commit 6e7e243

Browse files
committed
Prepare standard library for checking rustc in prepare_compiler_for_check
1 parent 1553adf commit 6e7e243

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

src/bootstrap/src/core/build_steps/check.rs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,8 @@ pub struct Rustc {
168168
}
169169

170170
impl Rustc {
171-
pub fn new(builder: &Builder<'_>, build_compiler: Compiler, target: TargetSelection) -> Self {
172-
let crates = builder
173-
.in_tree_crates("rustc-main", Some(target))
174-
.into_iter()
175-
.map(|krate| krate.name.to_string())
176-
.collect();
171+
pub fn new(builder: &Builder<'_>, target: TargetSelection, crates: Vec<String>) -> Self {
172+
let build_compiler = prepare_compiler_for_check(builder, target, Mode::Rustc);
177173
Self { build_compiler, target, crates }
178174
}
179175
}
@@ -189,11 +185,7 @@ impl Step for Rustc {
189185

190186
fn make_run(run: RunConfig<'_>) {
191187
let crates = run.make_run_crates(Alias::Compiler);
192-
run.builder.ensure(Rustc {
193-
target: run.target,
194-
build_compiler: prepare_compiler_for_check(run.builder, run.target, Mode::Rustc),
195-
crates,
196-
});
188+
run.builder.ensure(Rustc::new(run.builder, run.target, crates));
197189
}
198190

199191
/// Check the compiler.
@@ -207,15 +199,6 @@ impl Step for Rustc {
207199
let build_compiler = self.build_compiler;
208200
let target = self.target;
209201

210-
// Build host std for compiling build scripts
211-
builder.std(build_compiler, build_compiler.host);
212-
213-
// Build target std so that the checked rustc can link to it during the check
214-
// FIXME: maybe we can a way to only do a check of std here?
215-
// But for that we would have to copy the stdlib rmetas to the sysroot of the build
216-
// compiler, which conflicts with std rlibs, if we also build std.
217-
builder.std(build_compiler, target);
218-
219202
let mut cargo = builder::Cargo::new(
220203
builder,
221204
build_compiler,
@@ -289,11 +272,13 @@ fn prepare_compiler_for_check(
289272
build_compiler
290273
}
291274
Mode::ToolRustc | Mode::Codegen => {
292-
// FIXME: this is a hack, see description of Mode::Rustc below
293-
let stage = if host == target { builder.top_stage - 1 } else { builder.top_stage };
294-
// When checking tool stage N, we check it with compiler stage N-1
295-
let build_compiler = builder.compiler(stage, host);
296-
builder.ensure(Rustc::new(builder, build_compiler, target));
275+
// Check Rustc to produce the required rmeta artifacts for rustc_private, and then
276+
// return the build compiler that was used to check rustc.
277+
// We do not need to check examples/tests/etc. of Rustc for rustc_private, so we pass
278+
// an empty set of crates, which will avoid using `cargo -p`.
279+
let check = Rustc::new(builder, target, vec![]);
280+
let build_compiler = check.build_compiler;
281+
builder.ensure(check);
297282
build_compiler
298283
}
299284
Mode::Rustc => {
@@ -305,7 +290,18 @@ fn prepare_compiler_for_check(
305290
// FIXME: remove this and either fix cross-compilation check on stage 2 (which has a
306291
// myriad of other problems) or disable cross-checking on stage 1.
307292
let stage = if host == target { builder.top_stage - 1 } else { builder.top_stage };
308-
builder.compiler(stage, host)
293+
let build_compiler = builder.compiler(stage, host);
294+
295+
// Build host std for compiling build scripts
296+
builder.std(build_compiler, build_compiler.host);
297+
298+
// Build target std so that the checked rustc can link to it during the check
299+
// FIXME: maybe we can a way to only do a check of std here?
300+
// But for that we would have to copy the stdlib rmetas to the sysroot of the build
301+
// compiler, which conflicts with std rlibs, if we also build std.
302+
builder.std(build_compiler, target);
303+
304+
build_compiler
309305
}
310306
Mode::Std => {
311307
// When checking std stage N, we want to do it with the stage N compiler

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ macro_rules! lint_any {
298298
let target = self.target;
299299

300300
if !builder.download_rustc() {
301-
builder.ensure(check::Rustc::new(builder, build_compiler, target));
301+
builder.ensure(check::Rustc::new(builder, target, vec![]));
302302
};
303303

304304
let cargo = prepare_tool_cargo(

0 commit comments

Comments
 (0)