Skip to content

bootstrap: Don't trigger an unnecessary LLVM build from check builds #144011

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 2 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
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl Step for CodegenBackend {
cargo
.arg("--manifest-path")
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));
rustc_cargo_env(builder, &mut cargo, target, build_compiler.stage);
rustc_cargo_env(builder, &mut cargo, target);

let _guard = builder.msg_check(format!("rustc_codegen_{backend}"), target, None);

Expand Down
20 changes: 7 additions & 13 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,15 +1316,10 @@ pub fn rustc_cargo(
cargo.env("RUSTC_WRAPPER", ccache);
}

rustc_cargo_env(builder, cargo, target, build_compiler.stage);
rustc_cargo_env(builder, cargo, target);
}

pub fn rustc_cargo_env(
builder: &Builder<'_>,
cargo: &mut Cargo,
target: TargetSelection,
build_stage: u32,
) {
pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelection) {
// Set some configuration variables picked up by build scripts and
// the compiler alike
cargo
Expand Down Expand Up @@ -1384,13 +1379,12 @@ pub fn rustc_cargo_env(
// detected that LLVM is already built and good to go which helps prevent
// busting caches (e.g. like #71152).
if builder.config.llvm_enabled(target) {
let building_is_expensive =
let building_llvm_is_expensive =
crate::core::build_steps::llvm::prebuilt_llvm_config(builder, target, false)
.should_build();
// `top_stage == stage` might be false for `check --stage 1`, if we are building the stage 1 compiler
let can_skip_build = builder.kind == Kind::Check && builder.top_stage == build_stage;
let should_skip_build = building_is_expensive && can_skip_build;
if !should_skip_build {

let skip_llvm = (builder.kind == Kind::Check) && building_llvm_is_expensive;
if !skip_llvm {
rustc_llvm_env(builder, cargo, target)
}
}
Expand Down Expand Up @@ -1665,7 +1659,7 @@ impl Step for CodegenBackend {
cargo
.arg("--manifest-path")
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));
rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
rustc_cargo_env(builder, &mut cargo, target);

// Ideally, we'd have a separate step for the individual codegen backends,
// like we have in tests (test::CodegenGCC) but that would require a lot of restructuring.
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3386,7 +3386,7 @@ impl Step for CodegenCranelift {
cargo
.arg("--manifest-path")
.arg(builder.src.join("compiler/rustc_codegen_cranelift/build_system/Cargo.toml"));
compile::rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
compile::rustc_cargo_env(builder, &mut cargo, target);

// Avoid incremental cache issues when changing rustc
cargo.env("CARGO_BUILD_INCREMENTAL", "false");
Expand Down Expand Up @@ -3518,7 +3518,7 @@ impl Step for CodegenGCC {
cargo
.arg("--manifest-path")
.arg(builder.src.join("compiler/rustc_codegen_gcc/build_system/Cargo.toml"));
compile::rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
compile::rustc_cargo_env(builder, &mut cargo, target);
add_cg_gcc_cargo_flags(&mut cargo, &gcc);

// Avoid incremental cache issues when changing rustc
Expand Down
48 changes: 40 additions & 8 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,46 @@ fn any_debug() {
assert_eq!(x.downcast_ref::<MyStruct>(), Some(&MyStruct { x: 7 }));
}

#[test]
fn test_check_compiler_doesnt_build_llvm() {
// Checking the stage 1 compiler uses the bootstrap compiler, and therefore
// should not need to build LLVM.
{
let config = configure_with_args(
&["check", "compiler", "--stage=1"],
&[TEST_TRIPLE_1],
&[TEST_TRIPLE_1],
);
let mut cache = run_build(&config.paths.clone(), config);

assert!(!cache.contains::<llvm::Llvm>());
}

// Checking the stage 1 library uses the stage 1 compiler, so it will need LLVM.
{
let config = configure_with_args(
&["check", "library", "--stage=1"],
&[TEST_TRIPLE_1],
&[TEST_TRIPLE_1],
);
let mut cache = run_build(&config.paths.clone(), config);

assert!(cache.contains::<llvm::Llvm>());
}

// Checking the stage 2 compiler uses the stage 1 compiler, so it will need LLVM.
{
let config = configure_with_args(
&["check", "compiler", "--stage=2"],
&[TEST_TRIPLE_1],
&[TEST_TRIPLE_1],
);
let mut cache = run_build(&config.paths.clone(), config);

assert!(cache.contains::<llvm::Llvm>());
}
}

/// These tests use insta for snapshot testing.
/// See bootstrap's README on how to bless the snapshots.
mod snapshot {
Expand Down Expand Up @@ -1294,7 +1334,6 @@ mod snapshot {
ctx.config("check")
.path("compiler")
.render_steps(), @r"
[build] llvm <host>
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> cranelift 1 <host>
[check] rustc 0 <host> -> gcc 1 <host>
Expand All @@ -1304,7 +1343,6 @@ mod snapshot {
ctx.config("check")
.path("rustc")
.render_steps(), @r"
[build] llvm <host>
[check] rustc 0 <host> -> rustc 1 <host>
");
}
Expand All @@ -1324,7 +1362,6 @@ mod snapshot {
.path("compiler")
.stage(1)
.render_steps(), @r"
[build] llvm <host>
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> cranelift 1 <host>
[check] rustc 0 <host> -> gcc 1 <host>
Expand Down Expand Up @@ -1456,7 +1493,6 @@ mod snapshot {
.paths(&["library", "compiler"])
.args(&args)
.render_steps(), @r"
[build] llvm <host>
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> cranelift 1 <host>
[check] rustc 0 <host> -> gcc 1 <host>
Expand All @@ -1470,7 +1506,6 @@ mod snapshot {
ctx.config("check")
.path("miri")
.render_steps(), @r"
[build] llvm <host>
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> Miri 1 <host>
");
Expand All @@ -1491,7 +1526,6 @@ mod snapshot {
.path("miri")
.stage(1)
.render_steps(), @r"
[build] llvm <host>
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> Miri 1 <host>
");
Expand Down Expand Up @@ -1544,7 +1578,6 @@ mod snapshot {
ctx.config("check")
.path("rustc_codegen_cranelift")
.render_steps(), @r"
[build] llvm <host>
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> cranelift 1 <host>
[check] rustc 0 <host> -> gcc 1 <host>
Expand All @@ -1558,7 +1591,6 @@ mod snapshot {
ctx.config("check")
.path("rust-analyzer")
.render_steps(), @r"
[build] llvm <host>
[check] rustc 0 <host> -> rustc 1 <host>
[check] rustc 0 <host> -> rust-analyzer 1 <host>
");
Expand Down
Loading