Skip to content

Enforce in bootstrap that check must have stage at least 1 #143048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/bootstrap/defaults/bootstrap.library.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# These defaults are meant for contributors to the standard library and documentation.
[build]
bench-stage = 1
check-stage = 1
test-stage = 1

[rust]
Expand Down
389 changes: 191 additions & 198 deletions src/bootstrap/src/core/build_steps/check.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl Step for Rustc {
builder.std(compiler, compiler.host);
builder.std(compiler, target);
} else {
builder.ensure(check::Std::new(target));
builder.ensure(check::Std::new(compiler, target));
}
}

Expand Down Expand Up @@ -287,7 +287,7 @@ macro_rules! lint_any {
let target = self.target;

if !builder.download_rustc() {
builder.ensure(check::Rustc::new(target, builder));
builder.ensure(check::Rustc::new(builder, compiler, target));
};

let cargo = prepare_tool_cargo(
Expand Down
43 changes: 32 additions & 11 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1742,17 +1742,19 @@ fn copy_codegen_backends_to_sysroot(
}

let stamp = build_stamp::codegen_backend_stamp(builder, compiler, target, backend);
let dylib = t!(fs::read_to_string(stamp.path()));
let file = Path::new(&dylib);
let filename = file.file_name().unwrap().to_str().unwrap();
// change `librustc_codegen_cranelift-xxxxxx.so` to
// `librustc_codegen_cranelift-release.so`
let target_filename = {
let dash = filename.find('-').unwrap();
let dot = filename.find('.').unwrap();
format!("{}-{}{}", &filename[..dash], builder.rust_release(), &filename[dot..])
};
builder.copy_link(file, &dst.join(target_filename), FileType::NativeLibrary);
if stamp.path().exists() {
let dylib = t!(fs::read_to_string(stamp.path()));
let file = Path::new(&dylib);
let filename = file.file_name().unwrap().to_str().unwrap();
// change `librustc_codegen_cranelift-xxxxxx.so` to
// `librustc_codegen_cranelift-release.so`
let target_filename = {
let dash = filename.find('-').unwrap();
let dot = filename.find('.').unwrap();
format!("{}-{}{}", &filename[..dash], builder.rust_release(), &filename[dot..])
};
builder.copy_link(file, &dst.join(target_filename), FileType::NativeLibrary);
}
}
}

Expand Down Expand Up @@ -2163,6 +2165,25 @@ impl Step for Assemble {
continue; // Already built as part of rustc
}

// FIXME: this is a horrible hack used to make `x check` work when other codegen
// backends are enabled.
// `x check` will check stage 1 rustc, which copies its rmetas to the stage0 sysroot.
// Then it checks codegen backends, which correctly use these rmetas.
// Then it needs to check std, but for that it needs to build stage 1 rustc.
// This copies the build rmetas into the stage0 sysroot, effectively poisoning it,
// because we then have both check and build rmetas in the same sysroot.
// That would be fine on its own. However, when another codegen backend is enabled,
// then building stage 1 rustc implies also building stage 1 codegen backend (even if
// it isn't used for anything). And since that tries to use the poisoned
// rmetas, it fails to build.
// We don't actually need to build rustc-private codegen backends for checking std,
// so instead we skip that.
// Note: this would be also an issue for other rustc-private tools, but that is "solved"
// by check::Std being last in the list of checked things (see
// `Builder::get_step_descriptions`).
if builder.kind == Kind::Check && builder.top_stage == 1 {
continue;
}
builder.ensure(CodegenBackend {
compiler: build_compiler,
target: target_compiler.host,
Expand Down
9 changes: 9 additions & 0 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@ impl Step for Llvm {
}

/// Compile LLVM for `target`.
#[cfg_attr(
feature = "tracing",
instrument(
level = "debug",
name = "Llvm::run",
skip_all,
fields(target = ?self.target),
),
)]
fn run(self, builder: &Builder<'_>) -> LlvmResult {
let target = self.target;
let target_native = if self.target.starts_with("riscv") {
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Builder<'_> {
*target,
),
// doesn't depend on compiler, same as host compiler
_ => self.msg(Kind::Build, build_stage, format_args!("tool {tool}"), *host, *target),
_ => self.msg(kind, build_stage, format_args!("tool {tool}"), *host, *target),
}
}
}
Expand Down
109 changes: 45 additions & 64 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,24 +1240,23 @@ mod snapshot {
ctx.config("check")
.path("compiler")
.render_steps(), @r"
[check] std <host>
[build] llvm <host>
[check] rustc <host>
[check] cranelift <host>
[check] gcc <host>
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> cranelift 1 <host>
[check] rustc 0 <host> -> gcc 1 <host>
");

insta::assert_snapshot!(
ctx.config("check")
.path("rustc")
.render_steps(), @r"
[check] std <host>
[build] llvm <host>
[check] rustc <host>
[check] rustc 0 <host> -> rustc 1 <host>
");
}

#[test]
#[should_panic]
fn check_compiler_stage_0() {
let ctx = TestCtx::new();
ctx.config("check").path("compiler").stage(0).run();
Expand All @@ -1272,11 +1271,9 @@ mod snapshot {
.stage(1)
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[check] rustc <host>
[check] cranelift <host>
[check] gcc <host>
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> cranelift 1 <host>
[check] rustc 0 <host> -> gcc 1 <host>
");
}

Expand All @@ -1291,11 +1288,9 @@ mod snapshot {
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustc 2 <host> -> std 2 <host>
[check] rustc <host>
[check] cranelift <host>
[check] gcc <host>
[check] rustc 1 <host> -> rustc 2 <host>
[check] rustc 1 <host> -> cranelift 2 <host>
[check] rustc 1 <host> -> gcc 2 <host>
");
}

Expand All @@ -1304,30 +1299,26 @@ mod snapshot {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("check")
.stage(2)
.targets(&[TEST_TRIPLE_1])
.hosts(&[TEST_TRIPLE_1])
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustc 2 <host> -> std 2 <host>
[build] rustc 1 <host> -> std 1 <target1>
[build] rustc 2 <host> -> std 2 <target1>
[check] rustc <target1>
[check] Rustdoc <target1>
[check] cranelift <target1>
[check] gcc <target1>
[check] Clippy <target1>
[check] Miri <target1>
[check] CargoMiri <target1>
[check] MiroptTestTools <target1>
[check] Rustfmt <target1>
[check] rust-analyzer <target1>
[check] TestFloatParse <target1>
[check] FeaturesStatusDump <target1>
[check] std <target1>
[check] rustc 1 <host> -> rustc 2 <target1>
[check] rustc 1 <host> -> Rustdoc 2 <target1>
[check] rustc 1 <host> -> cranelift 2 <target1>
[check] rustc 1 <host> -> gcc 2 <target1>
[check] rustc 1 <host> -> Clippy 2 <target1>
[check] rustc 1 <host> -> Miri 2 <target1>
[check] rustc 1 <host> -> CargoMiri 2 <target1>
[check] rustc 0 <host> -> MiroptTestTools 1 <target1>
[check] rustc 1 <host> -> Rustfmt 2 <target1>
[check] rustc 1 <host> -> rust-analyzer 2 <target1>
[check] rustc 1 <host> -> TestFloatParse 2 <target1>
[check] rustc 0 <host> -> FeaturesStatusDump 1 <target1>
[check] rustc 1 <host> -> std 1 <target1>
");
}

Expand All @@ -1340,11 +1331,12 @@ mod snapshot {
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[check] std <host>
[check] rustc 1 <host> -> std 1 <host>
");
}

#[test]
#[should_panic]
fn check_library_stage_0() {
let ctx = TestCtx::new();
ctx.config("check").path("library").stage(0).run();
Expand All @@ -1360,7 +1352,7 @@ mod snapshot {
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[check] std <host>
[check] rustc 1 <host> -> std 1 <host>
");
}

Expand All @@ -1376,7 +1368,7 @@ mod snapshot {
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[check] std <host>
[check] rustc 2 <host> -> std 2 <host>
");
}

Expand All @@ -1390,8 +1382,8 @@ mod snapshot {
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[check] std <target1>
[check] std <target2>
[check] rustc 1 <host> -> std 1 <target1>
[check] rustc 1 <host> -> std 1 <target2>
");
}

Expand All @@ -1402,14 +1394,14 @@ mod snapshot {
ctx.config("check")
.path("miri")
.render_steps(), @r"
[check] std <host>
[build] llvm <host>
[check] rustc <host>
[check] Miri <host>
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> Miri 1 <host>
");
}

#[test]
#[should_panic]
fn check_miri_stage_0() {
let ctx = TestCtx::new();
ctx.config("check").path("miri").stage(0).run();
Expand All @@ -1424,10 +1416,8 @@ mod snapshot {
.stage(1)
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[check] rustc <host>
[check] Miri <host>
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> Miri 1 <host>
");
}

Expand All @@ -1442,10 +1432,8 @@ mod snapshot {
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustc 2 <host> -> std 2 <host>
[check] rustc <host>
[check] Miri <host>
[check] rustc 1 <host> -> rustc 2 <host>
[check] rustc 1 <host> -> Miri 2 <host>
");
}

Expand All @@ -1466,9 +1454,9 @@ mod snapshot {
.path("compiletest")
.args(&["--set", "build.compiletest-use-stage0-libtest=false"])
.render_steps(), @r"
[check] std <host>
[build] llvm <host>
[check] rustc <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[check] compiletest <host>
");
}
Expand All @@ -1480,11 +1468,10 @@ mod snapshot {
ctx.config("check")
.path("rustc_codegen_cranelift")
.render_steps(), @r"
[check] std <host>
[build] llvm <host>
[check] rustc <host>
[check] cranelift <host>
[check] gcc <host>
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> cranelift 1 <host>
[check] rustc 0 <host> -> gcc 1 <host>
");
}

Expand All @@ -1495,10 +1482,9 @@ mod snapshot {
ctx.config("check")
.path("rust-analyzer")
.render_steps(), @r"
[check] std <host>
[build] llvm <host>
[check] rustc <host>
[check] rust-analyzer <host>
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> rust-analyzer 1 <host>
");
}

Expand All @@ -1508,12 +1494,7 @@ mod snapshot {
insta::assert_snapshot!(
ctx.config("check")
.path("run-make-support")
.render_steps(), @r"
[check] std <host>
[build] llvm <host>
[check] rustc <host>
[check] RunMakeSupport <host>
");
.render_steps(), @"[check] rustc 0 <host> -> RunMakeSupport 1 <host>");
}

#[test]
Expand Down
15 changes: 11 additions & 4 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ impl Config {
|| bench_stage.is_some();

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

// Now check that the selected stage makes sense, and if not, print a warning and end
if let (0, Subcommand::Build) = (config.stage, &config.cmd) {
eprintln!("WARNING: cannot build anything on stage 0. Use at least stage 1.");
exit!(1);
match (config.stage, &config.cmd) {
(0, Subcommand::Build) => {
eprintln!("WARNING: cannot build anything on stage 0. Use at least stage 1.");
exit!(1);
}
(0, Subcommand::Check { .. }) => {
eprintln!("WARNING: cannot check anything on stage 0. Use at least stage 1.");
exit!(1);
}
_ => {}
}

// CI should always run stage 2 builds, unless it specifically states otherwise
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/src/utils/change_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Info,
summary: "Added new option `build.tidy-extra-checks` to specify a default value for the --extra-checks cli flag.",
},
ChangeInfo {
change_id: 143048,
severity: ChangeSeverity::Warning,
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+.",
},
];
Loading
Loading