Skip to content

Commit c720f49

Browse files
committed
Auto merge of #143048 - Kobzol:bootstrap-check-stage-1, r=jieyouxu
Enforce in bootstrap that check must have stage at least 1 This PR is another step towards https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Proposal.20to.20cleanup.20stages.20and.20steps.20after.20the.20redesign/with/523586917, this time dealing with `x check`. It enforces the invariant that: - We check std stage N with rustc stage N - We check everything else stage N with rustc stage N - 1 It creates a single function that prepares a proper build compiler for checking something, and also adds snapshot tests for various common check steps. Some obsolete code was also removed. The default check stage also becomes 1, for all profiles. I tested manually that `x check std` with `download-ci-rustc` still works and doesn't build rustc locally. Closes: #139170 r? `@ghost`
2 parents 0d11be5 + 5dc77ba commit c720f49

File tree

10 files changed

+304
-284
lines changed

10 files changed

+304
-284
lines changed

src/bootstrap/defaults/bootstrap.library.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# These defaults are meant for contributors to the standard library and documentation.
22
[build]
33
bench-stage = 1
4-
check-stage = 1
54
test-stage = 1
65

76
[rust]

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

Lines changed: 198 additions & 198 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl Step for Rustc {
215215
builder.std(compiler, compiler.host);
216216
builder.std(compiler, target);
217217
} else {
218-
builder.ensure(check::Std::new(target));
218+
builder.ensure(check::Std::new(compiler, target));
219219
}
220220
}
221221

@@ -287,7 +287,7 @@ macro_rules! lint_any {
287287
let target = self.target;
288288

289289
if !builder.download_rustc() {
290-
builder.ensure(check::Rustc::new(target, builder));
290+
builder.ensure(check::Rustc::new(builder, compiler, target));
291291
};
292292

293293
let cargo = prepare_tool_cargo(

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,17 +1741,19 @@ fn copy_codegen_backends_to_sysroot(
17411741
}
17421742

17431743
let stamp = build_stamp::codegen_backend_stamp(builder, compiler, target, backend);
1744-
let dylib = t!(fs::read_to_string(stamp.path()));
1745-
let file = Path::new(&dylib);
1746-
let filename = file.file_name().unwrap().to_str().unwrap();
1747-
// change `librustc_codegen_cranelift-xxxxxx.so` to
1748-
// `librustc_codegen_cranelift-release.so`
1749-
let target_filename = {
1750-
let dash = filename.find('-').unwrap();
1751-
let dot = filename.find('.').unwrap();
1752-
format!("{}-{}{}", &filename[..dash], builder.rust_release(), &filename[dot..])
1753-
};
1754-
builder.copy_link(file, &dst.join(target_filename), FileType::NativeLibrary);
1744+
if stamp.path().exists() {
1745+
let dylib = t!(fs::read_to_string(stamp.path()));
1746+
let file = Path::new(&dylib);
1747+
let filename = file.file_name().unwrap().to_str().unwrap();
1748+
// change `librustc_codegen_cranelift-xxxxxx.so` to
1749+
// `librustc_codegen_cranelift-release.so`
1750+
let target_filename = {
1751+
let dash = filename.find('-').unwrap();
1752+
let dot = filename.find('.').unwrap();
1753+
format!("{}-{}{}", &filename[..dash], builder.rust_release(), &filename[dot..])
1754+
};
1755+
builder.copy_link(file, &dst.join(target_filename), FileType::NativeLibrary);
1756+
}
17551757
}
17561758
}
17571759

@@ -2162,6 +2164,25 @@ impl Step for Assemble {
21622164
continue; // Already built as part of rustc
21632165
}
21642166

2167+
// FIXME: this is a horrible hack used to make `x check` work when other codegen
2168+
// backends are enabled.
2169+
// `x check` will check stage 1 rustc, which copies its rmetas to the stage0 sysroot.
2170+
// Then it checks codegen backends, which correctly use these rmetas.
2171+
// Then it needs to check std, but for that it needs to build stage 1 rustc.
2172+
// This copies the build rmetas into the stage0 sysroot, effectively poisoning it,
2173+
// because we then have both check and build rmetas in the same sysroot.
2174+
// That would be fine on its own. However, when another codegen backend is enabled,
2175+
// then building stage 1 rustc implies also building stage 1 codegen backend (even if
2176+
// it isn't used for anything). And since that tries to use the poisoned
2177+
// rmetas, it fails to build.
2178+
// We don't actually need to build rustc-private codegen backends for checking std,
2179+
// so instead we skip that.
2180+
// Note: this would be also an issue for other rustc-private tools, but that is "solved"
2181+
// by check::Std being last in the list of checked things (see
2182+
// `Builder::get_step_descriptions`).
2183+
if builder.kind == Kind::Check && builder.top_stage == 1 {
2184+
continue;
2185+
}
21652186
builder.ensure(CodegenBackend {
21662187
compiler: build_compiler,
21672188
target: target_compiler.host,

src/bootstrap/src/core/build_steps/llvm.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,15 @@ impl Step for Llvm {
263263
}
264264

265265
/// Compile LLVM for `target`.
266+
#[cfg_attr(
267+
feature = "tracing",
268+
instrument(
269+
level = "debug",
270+
name = "Llvm::run",
271+
skip_all,
272+
fields(target = ?self.target),
273+
),
274+
)]
266275
fn run(self, builder: &Builder<'_>) -> LlvmResult {
267276
let target = self.target;
268277
let target_native = if self.target.starts_with("riscv") {

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl Builder<'_> {
7777
*target,
7878
),
7979
// doesn't depend on compiler, same as host compiler
80-
_ => self.msg(Kind::Build, build_stage, format_args!("tool {tool}"), *host, *target),
80+
_ => self.msg(kind, build_stage, format_args!("tool {tool}"), *host, *target),
8181
}
8282
}
8383
}

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

Lines changed: 43 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,24 +1240,23 @@ mod snapshot {
12401240
ctx.config("check")
12411241
.path("compiler")
12421242
.render_steps(), @r"
1243-
[check] std <host>
12441243
[build] llvm <host>
1245-
[check] rustc <host>
1246-
[check] cranelift <host>
1247-
[check] gcc <host>
1244+
[check] rustc 0 <host> -> rustc 1 <host>
1245+
[check] rustc 0 <host> -> cranelift 1 <host>
1246+
[check] rustc 0 <host> -> gcc 1 <host>
12481247
");
12491248

12501249
insta::assert_snapshot!(
12511250
ctx.config("check")
12521251
.path("rustc")
12531252
.render_steps(), @r"
1254-
[check] std <host>
12551253
[build] llvm <host>
1256-
[check] rustc <host>
1254+
[check] rustc 0 <host> -> rustc 1 <host>
12571255
");
12581256
}
12591257

12601258
#[test]
1259+
#[should_panic]
12611260
fn check_compiler_stage_0() {
12621261
let ctx = TestCtx::new();
12631262
ctx.config("check").path("compiler").stage(0).run();
@@ -1272,11 +1271,9 @@ mod snapshot {
12721271
.stage(1)
12731272
.render_steps(), @r"
12741273
[build] llvm <host>
1275-
[build] rustc 0 <host> -> rustc 1 <host>
1276-
[build] rustc 1 <host> -> std 1 <host>
1277-
[check] rustc <host>
1278-
[check] cranelift <host>
1279-
[check] gcc <host>
1274+
[check] rustc 0 <host> -> rustc 1 <host>
1275+
[check] rustc 0 <host> -> cranelift 1 <host>
1276+
[check] rustc 0 <host> -> gcc 1 <host>
12801277
");
12811278
}
12821279

@@ -1291,11 +1288,9 @@ mod snapshot {
12911288
[build] llvm <host>
12921289
[build] rustc 0 <host> -> rustc 1 <host>
12931290
[build] rustc 1 <host> -> std 1 <host>
1294-
[build] rustc 1 <host> -> rustc 2 <host>
1295-
[build] rustc 2 <host> -> std 2 <host>
1296-
[check] rustc <host>
1297-
[check] cranelift <host>
1298-
[check] gcc <host>
1291+
[check] rustc 1 <host> -> rustc 2 <host>
1292+
[check] rustc 1 <host> -> cranelift 2 <host>
1293+
[check] rustc 1 <host> -> gcc 2 <host>
12991294
");
13001295
}
13011296

@@ -1304,30 +1299,24 @@ mod snapshot {
13041299
let ctx = TestCtx::new();
13051300
insta::assert_snapshot!(
13061301
ctx.config("check")
1307-
.stage(2)
13081302
.targets(&[TEST_TRIPLE_1])
13091303
.hosts(&[TEST_TRIPLE_1])
13101304
.render_steps(), @r"
13111305
[build] llvm <host>
13121306
[build] rustc 0 <host> -> rustc 1 <host>
13131307
[build] rustc 1 <host> -> std 1 <host>
1314-
[build] rustc 1 <host> -> rustc 2 <host>
1315-
[build] rustc 2 <host> -> std 2 <host>
13161308
[build] rustc 1 <host> -> std 1 <target1>
1317-
[build] rustc 2 <host> -> std 2 <target1>
1318-
[check] rustc <target1>
1319-
[check] Rustdoc <target1>
1320-
[check] cranelift <target1>
1321-
[check] gcc <target1>
1322-
[check] Clippy <target1>
1323-
[check] Miri <target1>
1324-
[check] CargoMiri <target1>
1325-
[check] MiroptTestTools <target1>
1326-
[check] Rustfmt <target1>
1327-
[check] rust-analyzer <target1>
1328-
[check] TestFloatParse <target1>
1329-
[check] FeaturesStatusDump <target1>
1330-
[check] std <target1>
1309+
[check] rustc 1 <host> -> rustc 2 <target1>
1310+
[check] rustc 1 <host> -> Rustdoc 2 <target1>
1311+
[check] rustc 1 <host> -> cranelift 2 <target1>
1312+
[check] rustc 1 <host> -> gcc 2 <target1>
1313+
[check] rustc 1 <host> -> Clippy 2 <target1>
1314+
[check] rustc 1 <host> -> Miri 2 <target1>
1315+
[check] rustc 1 <host> -> CargoMiri 2 <target1>
1316+
[check] rustc 1 <host> -> Rustfmt 2 <target1>
1317+
[check] rustc 1 <host> -> rust-analyzer 2 <target1>
1318+
[check] rustc 1 <host> -> TestFloatParse 2 <target1>
1319+
[check] rustc 1 <host> -> std 1 <target1>
13311320
");
13321321
}
13331322

@@ -1340,11 +1329,12 @@ mod snapshot {
13401329
.render_steps(), @r"
13411330
[build] llvm <host>
13421331
[build] rustc 0 <host> -> rustc 1 <host>
1343-
[check] std <host>
1332+
[check] rustc 1 <host> -> std 1 <host>
13441333
");
13451334
}
13461335

13471336
#[test]
1337+
#[should_panic]
13481338
fn check_library_stage_0() {
13491339
let ctx = TestCtx::new();
13501340
ctx.config("check").path("library").stage(0).run();
@@ -1360,7 +1350,7 @@ mod snapshot {
13601350
.render_steps(), @r"
13611351
[build] llvm <host>
13621352
[build] rustc 0 <host> -> rustc 1 <host>
1363-
[check] std <host>
1353+
[check] rustc 1 <host> -> std 1 <host>
13641354
");
13651355
}
13661356

@@ -1376,7 +1366,7 @@ mod snapshot {
13761366
[build] rustc 0 <host> -> rustc 1 <host>
13771367
[build] rustc 1 <host> -> std 1 <host>
13781368
[build] rustc 1 <host> -> rustc 2 <host>
1379-
[check] std <host>
1369+
[check] rustc 2 <host> -> std 2 <host>
13801370
");
13811371
}
13821372

@@ -1390,8 +1380,8 @@ mod snapshot {
13901380
.render_steps(), @r"
13911381
[build] llvm <host>
13921382
[build] rustc 0 <host> -> rustc 1 <host>
1393-
[check] std <target1>
1394-
[check] std <target2>
1383+
[check] rustc 1 <host> -> std 1 <target1>
1384+
[check] rustc 1 <host> -> std 1 <target2>
13951385
");
13961386
}
13971387

@@ -1402,14 +1392,14 @@ mod snapshot {
14021392
ctx.config("check")
14031393
.path("miri")
14041394
.render_steps(), @r"
1405-
[check] std <host>
14061395
[build] llvm <host>
1407-
[check] rustc <host>
1408-
[check] Miri <host>
1396+
[check] rustc 0 <host> -> rustc 1 <host>
1397+
[check] rustc 0 <host> -> Miri 1 <host>
14091398
");
14101399
}
14111400

14121401
#[test]
1402+
#[should_panic]
14131403
fn check_miri_stage_0() {
14141404
let ctx = TestCtx::new();
14151405
ctx.config("check").path("miri").stage(0).run();
@@ -1424,10 +1414,8 @@ mod snapshot {
14241414
.stage(1)
14251415
.render_steps(), @r"
14261416
[build] llvm <host>
1427-
[build] rustc 0 <host> -> rustc 1 <host>
1428-
[build] rustc 1 <host> -> std 1 <host>
1429-
[check] rustc <host>
1430-
[check] Miri <host>
1417+
[check] rustc 0 <host> -> rustc 1 <host>
1418+
[check] rustc 0 <host> -> Miri 1 <host>
14311419
");
14321420
}
14331421

@@ -1442,10 +1430,8 @@ mod snapshot {
14421430
[build] llvm <host>
14431431
[build] rustc 0 <host> -> rustc 1 <host>
14441432
[build] rustc 1 <host> -> std 1 <host>
1445-
[build] rustc 1 <host> -> rustc 2 <host>
1446-
[build] rustc 2 <host> -> std 2 <host>
1447-
[check] rustc <host>
1448-
[check] Miri <host>
1433+
[check] rustc 1 <host> -> rustc 2 <host>
1434+
[check] rustc 1 <host> -> Miri 2 <host>
14491435
");
14501436
}
14511437

@@ -1466,9 +1452,9 @@ mod snapshot {
14661452
.path("compiletest")
14671453
.args(&["--set", "build.compiletest-use-stage0-libtest=false"])
14681454
.render_steps(), @r"
1469-
[check] std <host>
14701455
[build] llvm <host>
1471-
[check] rustc <host>
1456+
[build] rustc 0 <host> -> rustc 1 <host>
1457+
[build] rustc 1 <host> -> std 1 <host>
14721458
[check] compiletest <host>
14731459
");
14741460
}
@@ -1480,11 +1466,10 @@ mod snapshot {
14801466
ctx.config("check")
14811467
.path("rustc_codegen_cranelift")
14821468
.render_steps(), @r"
1483-
[check] std <host>
14841469
[build] llvm <host>
1485-
[check] rustc <host>
1486-
[check] cranelift <host>
1487-
[check] gcc <host>
1470+
[check] rustc 0 <host> -> rustc 1 <host>
1471+
[check] rustc 0 <host> -> cranelift 1 <host>
1472+
[check] rustc 0 <host> -> gcc 1 <host>
14881473
");
14891474
}
14901475

@@ -1495,10 +1480,9 @@ mod snapshot {
14951480
ctx.config("check")
14961481
.path("rust-analyzer")
14971482
.render_steps(), @r"
1498-
[check] std <host>
14991483
[build] llvm <host>
1500-
[check] rustc <host>
1501-
[check] rust-analyzer <host>
1484+
[check] rustc 0 <host> -> rustc 1 <host>
1485+
[check] rustc 0 <host> -> rust-analyzer 1 <host>
15021486
");
15031487
}
15041488

@@ -1508,12 +1492,7 @@ mod snapshot {
15081492
insta::assert_snapshot!(
15091493
ctx.config("check")
15101494
.path("run-make-support")
1511-
.render_steps(), @r"
1512-
[check] std <host>
1513-
[build] llvm <host>
1514-
[check] rustc <host>
1515-
[check] RunMakeSupport <host>
1516-
");
1495+
.render_steps(), @"[check] rustc 0 <host> -> RunMakeSupport 1 <host>");
15171496
}
15181497

15191498
#[test]

src/bootstrap/src/core/config/config.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ impl Config {
10251025
|| bench_stage.is_some();
10261026

10271027
config.stage = match config.cmd {
1028-
Subcommand::Check { .. } => flags_stage.or(check_stage).unwrap_or(0),
1028+
Subcommand::Check { .. } => flags_stage.or(check_stage).unwrap_or(1),
10291029
Subcommand::Clippy { .. } | Subcommand::Fix => flags_stage.or(check_stage).unwrap_or(1),
10301030
// `download-rustc` only has a speed-up for stage2 builds. Default to stage2 unless explicitly overridden.
10311031
Subcommand::Doc { .. } => {
@@ -1052,9 +1052,16 @@ impl Config {
10521052
};
10531053

10541054
// Now check that the selected stage makes sense, and if not, print a warning and end
1055-
if let (0, Subcommand::Build) = (config.stage, &config.cmd) {
1056-
eprintln!("WARNING: cannot build anything on stage 0. Use at least stage 1.");
1057-
exit!(1);
1055+
match (config.stage, &config.cmd) {
1056+
(0, Subcommand::Build) => {
1057+
eprintln!("WARNING: cannot build anything on stage 0. Use at least stage 1.");
1058+
exit!(1);
1059+
}
1060+
(0, Subcommand::Check { .. }) => {
1061+
eprintln!("WARNING: cannot check anything on stage 0. Use at least stage 1.");
1062+
exit!(1);
1063+
}
1064+
_ => {}
10581065
}
10591066

10601067
// CI should always run stage 2 builds, unless it specifically states otherwise

src/bootstrap/src/utils/change_tracker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,4 +451,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
451451
severity: ChangeSeverity::Warning,
452452
summary: "The `spellcheck:fix` tidy extra check argument has been removed, use `--bless` instead",
453453
},
454+
ChangeInfo {
455+
change_id: 143048,
456+
severity: ChangeSeverity::Warning,
457+
summary: "The default check stage has been changed to 1. It is no longer possible to `x check` with stage 0. All check commands have to be on stage 1+. Bootstrap tools can now also only be checked for the host target.",
458+
},
454459
];

0 commit comments

Comments
 (0)