Skip to content

Fix rustc uplifting (take two) #145645

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

Merged
merged 2 commits into from
Aug 20, 2025
Merged
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
14 changes: 5 additions & 9 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,22 +1047,18 @@ impl Step for Rustc {

// If we are building a stage3+ compiler, and full bootstrap is disabled, and we have a
// previous rustc available, we will uplift a compiler from a previous stage.
// We do not allow cross-compilation uplifting here, because there it can be quite tricky
// to figure out which stage actually built the rustc that should be uplifted.
if build_compiler.stage >= 2
&& !builder.config.full_bootstrap
&& (target == builder.host_target || builder.hosts.contains(&target))
&& target == builder.host_target
{
// Here we need to determine the **build compiler** that built the stage that we will
// be uplifting. We cannot uplift stage 1, as it has a different ABI than stage 2+,
// so we always uplift the stage2 compiler (compiled with stage 1).
let uplift_build_compiler = builder.compiler(1, build_compiler.host);
let msg = if uplift_build_compiler.host == target {
format!("Uplifting rustc (stage2 -> stage{stage})")
} else {
format!(
"Uplifting rustc (stage2:{} -> stage{stage}:{target})",
uplift_build_compiler.host
)
};

let msg = format!("Uplifting rustc from stage2 to stage{stage})");
builder.info(&msg);

// Here the compiler that built the rlibs (`uplift_build_compiler`) can be different
Expand Down
77 changes: 77 additions & 0 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,83 @@ mod snapshot {
");
}

#[test]
fn build_compiler_stage_3() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("build")
.path("compiler")
.stage(3)
.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 2 <host> -> rustc 3 <host>
");
}

#[test]
fn build_compiler_stage_3_cross() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("build")
.path("compiler")
.hosts(&[TEST_TRIPLE_1])
.stage(3)
.render_steps(), @r"
[build] llvm <host>
[build] llvm <target1>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustc 1 <host> -> std 1 <target1>
[build] rustc 2 <host> -> std 2 <target1>
[build] rustc 2 <host> -> std 2 <host>
[build] rustc 2 <host> -> rustc 3 <target1>
");
}

#[test]
fn build_compiler_stage_3_full_bootstrap() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("build")
.path("compiler")
.stage(3)
.args(&["--set", "build.full-bootstrap=true"])
.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 2 <host> -> rustc 3 <host>
");
}

#[test]
fn build_compiler_stage_3_cross_full_bootstrap() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("build")
.path("compiler")
.stage(3)
.hosts(&[TEST_TRIPLE_1])
.args(&["--set", "build.full-bootstrap=true"])
.render_steps(), @r"
[build] llvm <host>
[build] llvm <target1>
[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 <target1>
[build] rustc 2 <host> -> std 2 <host>
[build] rustc 2 <host> -> rustc 3 <target1>
");
}

#[test]
fn build_compiler_codegen_backend() {
let ctx = TestCtx::new();
Expand Down
Loading