Skip to content

Commit e8a792d

Browse files
committed
Auto merge of #145645 - Kobzol:uplift-fix, r=jieyouxu
Fix rustc uplifting (take two) The rustc uplifting logic is really annoying.. #145557 was not enough to fix it. Consider #145534 (comment): in this situation, we do a stage3 build of a cross-compiled rustc (it happens because we run `x test --stage 2`, which mistakenly builds a stage3 rustc, but it doesn't matter what casuses it, what matters is that the stage3 build isn't working). Currently, a stage3 cross-compiled build of rustc works like this: 1) stage0 (host) -> stage1 (host) 2) stage1 (host) -> stage2 (host) 3) stage2 (host) -> stage3 (target) The problem is that in the uplifting logic, I assumed that we will have a stage2 (target) rustc available, which we can uplift. And that would indeed be an ideal solution. But currently, we will actually build a stage2 (*host*) rustc, and only then start the cross-compilation. So the uplifting is broken. I spend a couple of hours trying to fix this, and do the uplifting "from the other direction", so that already when we assemble a stage3 rustc, we notice that an uplift should happen, and we only build stage1 (host) rustc, which also helps avoid one needless rustc build. However, this was relatively complicated and would require larger changes that I was not confident landing at this time. So instead I decided to do a much simpler fix, and just disable rustc uplifting when cross-compiling. Since we currently do the `stage2 (host) -> stage3 (target)` step, it should not actually affect stage3 cross-compiled builds in any way (I hope..), and should only affect stage4+ builds, about which I don't really care (the only change there should be more rustc builds). For normal builds, the stage2 host rustc should (hopefully) always be present, so we shouldn't run into this issue. Eventually, I would like to remove rustc uplifting completely. However, `x test --stage 2` on CI still currently builds a stage3 rustc for some reason, and if we removed uplifting completely, even for non-cross-compiled builds, that would cause an additional rustc build, and that's not great. So for now let's just allow uplifting for non-cross-compiled builds. Fixes #145534. r? `@jieyouxu`
2 parents bec7474 + f254075 commit e8a792d

File tree

2 files changed

+82
-9
lines changed

2 files changed

+82
-9
lines changed

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,22 +1048,18 @@ impl Step for Rustc {
10481048

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

10691065
// Here the compiler that built the rlibs (`uplift_build_compiler`) can be different

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,83 @@ mod snapshot {
672672
");
673673
}
674674

675+
#[test]
676+
fn build_compiler_stage_3() {
677+
let ctx = TestCtx::new();
678+
insta::assert_snapshot!(
679+
ctx.config("build")
680+
.path("compiler")
681+
.stage(3)
682+
.render_steps(), @r"
683+
[build] llvm <host>
684+
[build] rustc 0 <host> -> rustc 1 <host>
685+
[build] rustc 1 <host> -> std 1 <host>
686+
[build] rustc 1 <host> -> rustc 2 <host>
687+
[build] rustc 2 <host> -> std 2 <host>
688+
[build] rustc 2 <host> -> rustc 3 <host>
689+
");
690+
}
691+
692+
#[test]
693+
fn build_compiler_stage_3_cross() {
694+
let ctx = TestCtx::new();
695+
insta::assert_snapshot!(
696+
ctx.config("build")
697+
.path("compiler")
698+
.hosts(&[TEST_TRIPLE_1])
699+
.stage(3)
700+
.render_steps(), @r"
701+
[build] llvm <host>
702+
[build] llvm <target1>
703+
[build] rustc 0 <host> -> rustc 1 <host>
704+
[build] rustc 1 <host> -> std 1 <host>
705+
[build] rustc 1 <host> -> rustc 2 <host>
706+
[build] rustc 1 <host> -> std 1 <target1>
707+
[build] rustc 2 <host> -> std 2 <target1>
708+
[build] rustc 2 <host> -> std 2 <host>
709+
[build] rustc 2 <host> -> rustc 3 <target1>
710+
");
711+
}
712+
713+
#[test]
714+
fn build_compiler_stage_3_full_bootstrap() {
715+
let ctx = TestCtx::new();
716+
insta::assert_snapshot!(
717+
ctx.config("build")
718+
.path("compiler")
719+
.stage(3)
720+
.args(&["--set", "build.full-bootstrap=true"])
721+
.render_steps(), @r"
722+
[build] llvm <host>
723+
[build] rustc 0 <host> -> rustc 1 <host>
724+
[build] rustc 1 <host> -> std 1 <host>
725+
[build] rustc 1 <host> -> rustc 2 <host>
726+
[build] rustc 2 <host> -> std 2 <host>
727+
[build] rustc 2 <host> -> rustc 3 <host>
728+
");
729+
}
730+
731+
#[test]
732+
fn build_compiler_stage_3_cross_full_bootstrap() {
733+
let ctx = TestCtx::new();
734+
insta::assert_snapshot!(
735+
ctx.config("build")
736+
.path("compiler")
737+
.stage(3)
738+
.hosts(&[TEST_TRIPLE_1])
739+
.args(&["--set", "build.full-bootstrap=true"])
740+
.render_steps(), @r"
741+
[build] llvm <host>
742+
[build] llvm <target1>
743+
[build] rustc 0 <host> -> rustc 1 <host>
744+
[build] rustc 1 <host> -> std 1 <host>
745+
[build] rustc 1 <host> -> rustc 2 <host>
746+
[build] rustc 2 <host> -> std 2 <target1>
747+
[build] rustc 2 <host> -> std 2 <host>
748+
[build] rustc 2 <host> -> rustc 3 <target1>
749+
");
750+
}
751+
675752
#[test]
676753
fn build_compiler_codegen_backend() {
677754
let ctx = TestCtx::new();

0 commit comments

Comments
 (0)