Skip to content

Commit ed10e8f

Browse files
authored
Rollup merge of rust-lang#81064 - Mark-Simulacrum:support-stage1-check, r=jyn514
Support non-stage0 check Seems to work locally - a full stage 1 check succeeds, building std (because we can't get away with checking it), and then checking the compiler and other tools. This ran into the problem that a unconditional x.py check in stage 1 *both* checks and builds stage 1 std, and then has to clean up because for some reason the rmeta and rlib artifacts conflict (though I'm not actually entirely sure why, but it doesn't seem worth digging in in too much detail). Ideally we wouldn't be building and checking like that but it's a minor worry as checking std is pretty fast and you can avoid it if you're aiming for speed by passing the compiler (e.g., compiler/rustc) explicitly. r? ``@jyn514``
2 parents 0686e85 + 53989e4 commit ed10e8f

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

src/bootstrap/check.rs

+36-15
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Step for Std {
7373

7474
fn run(self, builder: &Builder<'_>) {
7575
let target = self.target;
76-
let compiler = builder.compiler(0, builder.config.build);
76+
let compiler = builder.compiler(builder.top_stage, builder.config.build);
7777

7878
let mut cargo = builder.cargo(
7979
compiler,
@@ -84,7 +84,10 @@ impl Step for Std {
8484
);
8585
std_cargo(builder, target, compiler.stage, &mut cargo);
8686

87-
builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
87+
builder.info(&format!(
88+
"Checking stage{} std artifacts ({} -> {})",
89+
builder.top_stage, &compiler.host, target
90+
));
8891
run_cargo(
8992
builder,
9093
cargo,
@@ -94,9 +97,13 @@ impl Step for Std {
9497
true,
9598
);
9699

97-
let libdir = builder.sysroot_libdir(compiler, target);
98-
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
99-
add_to_sysroot(&builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
100+
// We skip populating the sysroot in non-zero stage because that'll lead
101+
// to rlib/rmeta conflicts if std gets built during this session.
102+
if compiler.stage == 0 {
103+
let libdir = builder.sysroot_libdir(compiler, target);
104+
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
105+
add_to_sysroot(&builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
106+
}
100107

101108
// Then run cargo again, once we've put the rmeta files for the library
102109
// crates into the sysroot. This is needed because e.g., core's tests
@@ -124,8 +131,8 @@ impl Step for Std {
124131
}
125132

126133
builder.info(&format!(
127-
"Checking std test/bench/example targets ({} -> {})",
128-
&compiler.host, target
134+
"Checking stage{} std test/bench/example targets ({} -> {})",
135+
builder.top_stage, &compiler.host, target
129136
));
130137
run_cargo(
131138
builder,
@@ -163,10 +170,20 @@ impl Step for Rustc {
163170
/// the `compiler` targeting the `target` architecture. The artifacts
164171
/// created will also be linked into the sysroot directory.
165172
fn run(self, builder: &Builder<'_>) {
166-
let compiler = builder.compiler(0, builder.config.build);
173+
let compiler = builder.compiler(builder.top_stage, builder.config.build);
167174
let target = self.target;
168175

169-
builder.ensure(Std { target });
176+
if compiler.stage != 0 {
177+
// If we're not in stage 0, then we won't have a std from the beta
178+
// compiler around. That means we need to make sure there's one in
179+
// the sysroot for the compiler to find. Otherwise, we're going to
180+
// fail when building crates that need to generate code (e.g., build
181+
// scripts and their dependencies).
182+
builder.ensure(crate::compile::Std { target: compiler.host, compiler });
183+
builder.ensure(crate::compile::Std { target, compiler });
184+
} else {
185+
builder.ensure(Std { target });
186+
}
170187

171188
let mut cargo = builder.cargo(
172189
compiler,
@@ -187,7 +204,10 @@ impl Step for Rustc {
187204
cargo.arg("-p").arg(krate.name);
188205
}
189206

190-
builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
207+
builder.info(&format!(
208+
"Checking stage{} compiler artifacts ({} -> {})",
209+
builder.top_stage, &compiler.host, target
210+
));
191211
run_cargo(
192212
builder,
193213
cargo,
@@ -225,7 +245,7 @@ impl Step for CodegenBackend {
225245
}
226246

227247
fn run(self, builder: &Builder<'_>) {
228-
let compiler = builder.compiler(0, builder.config.build);
248+
let compiler = builder.compiler(builder.top_stage, builder.config.build);
229249
let target = self.target;
230250
let backend = self.backend;
231251

@@ -244,8 +264,8 @@ impl Step for CodegenBackend {
244264
rustc_cargo_env(builder, &mut cargo, target);
245265

246266
builder.info(&format!(
247-
"Checking {} artifacts ({} -> {})",
248-
backend, &compiler.host.triple, target.triple
267+
"Checking stage{} {} artifacts ({} -> {})",
268+
builder.top_stage, backend, &compiler.host.triple, target.triple
249269
));
250270

251271
run_cargo(
@@ -280,7 +300,7 @@ macro_rules! tool_check_step {
280300
}
281301

282302
fn run(self, builder: &Builder<'_>) {
283-
let compiler = builder.compiler(0, builder.config.build);
303+
let compiler = builder.compiler(builder.top_stage, builder.config.build);
284304
let target = self.target;
285305

286306
builder.ensure(Rustc { target });
@@ -301,7 +321,8 @@ macro_rules! tool_check_step {
301321
}
302322

303323
builder.info(&format!(
304-
"Checking {} artifacts ({} -> {})",
324+
"Checking stage{} {} artifacts ({} -> {})",
325+
builder.top_stage,
305326
stringify!($name).to_lowercase(),
306327
&compiler.host.triple,
307328
target.triple

src/bootstrap/config.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ struct Build {
377377
configure_args: Option<Vec<String>>,
378378
local_rebuild: Option<bool>,
379379
print_step_timings: Option<bool>,
380+
check_stage: Option<u32>,
380381
doc_stage: Option<u32>,
381382
build_stage: Option<u32>,
382383
test_stage: Option<u32>,
@@ -676,6 +677,7 @@ impl Config {
676677

677678
// See https://github.com/rust-lang/compiler-team/issues/326
678679
config.stage = match config.cmd {
680+
Subcommand::Check { .. } => flags.stage.or(build.check_stage).unwrap_or(0),
679681
Subcommand::Doc { .. } => flags.stage.or(build.doc_stage).unwrap_or(0),
680682
Subcommand::Build { .. } => flags.stage.or(build.build_stage).unwrap_or(1),
681683
Subcommand::Test { .. } => flags.stage.or(build.test_stage).unwrap_or(1),
@@ -685,7 +687,6 @@ impl Config {
685687
// These are all bootstrap tools, which don't depend on the compiler.
686688
// The stage we pass shouldn't matter, but use 0 just in case.
687689
Subcommand::Clean { .. }
688-
| Subcommand::Check { .. }
689690
| Subcommand::Clippy { .. }
690691
| Subcommand::Fix { .. }
691692
| Subcommand::Run { .. }

src/bootstrap/flags.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -614,14 +614,10 @@ Arguments:
614614
};
615615

616616
if let Subcommand::Check { .. } = &cmd {
617-
if matches.opt_str("stage").is_some() {
618-
println!("--stage not supported for x.py check, always treated as stage 0");
619-
process::exit(1);
620-
}
621617
if matches.opt_str("keep-stage").is_some()
622618
|| matches.opt_str("keep-stage-std").is_some()
623619
{
624-
println!("--keep-stage not supported for x.py check, only one stage available");
620+
println!("--keep-stage not yet supported for x.py check");
625621
process::exit(1);
626622
}
627623
}

0 commit comments

Comments
 (0)