Skip to content

Commit 5f8988b

Browse files
authored
Rollup merge of rust-lang#120058 - onur-ozkan:compiler-assemble, r=Mark-Simulacrum
bootstrap: improvements for compiler builds Reverted rust-lang#108288 and applied a proper fix with the following commit. r? ```@Mark-Simulacrum```
2 parents 97bcf0d + 8a461aa commit 5f8988b

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

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

+34-28
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,14 @@ impl Rustc {
803803
}
804804

805805
impl Step for Rustc {
806-
type Output = ();
806+
// We return the stage of the "actual" compiler (not the uplifted one).
807+
//
808+
// By "actual" we refer to the uplifting logic where we may not compile the requested stage;
809+
// instead, we uplift it from the previous stages. Which can lead to bootstrap failures in
810+
// specific situations where we request stage X from other steps. However we may end up
811+
// uplifting it from stage Y, causing the other stage to fail when attempting to link with
812+
// stage X which was never actually built.
813+
type Output = u32;
807814
const ONLY_HOSTS: bool = true;
808815
const DEFAULT: bool = false;
809816

@@ -834,7 +841,7 @@ impl Step for Rustc {
834841
/// This will build the compiler for a particular stage of the build using
835842
/// the `compiler` targeting the `target` architecture. The artifacts
836843
/// created will also be linked into the sysroot directory.
837-
fn run(self, builder: &Builder<'_>) {
844+
fn run(self, builder: &Builder<'_>) -> u32 {
838845
let compiler = self.compiler;
839846
let target = self.target;
840847

@@ -848,7 +855,7 @@ impl Step for Rustc {
848855
compiler,
849856
builder.config.ci_rustc_dev_contents(),
850857
);
851-
return;
858+
return compiler.stage;
852859
}
853860

854861
builder.ensure(Std::new(compiler, target));
@@ -857,7 +864,8 @@ impl Step for Rustc {
857864
builder.info("WARNING: Using a potentially old librustc. This may not behave well.");
858865
builder.info("WARNING: Use `--keep-stage-std` if you want to rebuild the compiler when it changes");
859866
builder.ensure(RustcLink::from_rustc(self, compiler));
860-
return;
867+
868+
return compiler.stage;
861869
}
862870

863871
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
@@ -880,7 +888,7 @@ impl Step for Rustc {
880888
};
881889
builder.info(&msg);
882890
builder.ensure(RustcLink::from_rustc(self, compiler_to_use));
883-
return;
891+
return compiler_to_use.stage;
884892
}
885893

886894
// Ensure that build scripts and proc macros have a std / libproc_macro to link against.
@@ -984,6 +992,8 @@ impl Step for Rustc {
984992
self,
985993
builder.compiler(compiler.stage, builder.config.build),
986994
));
995+
996+
compiler.stage
987997
}
988998
}
989999

@@ -1642,21 +1652,6 @@ impl Step for Assemble {
16421652
return target_compiler;
16431653
}
16441654

1645-
// Get the compiler that we'll use to bootstrap ourselves.
1646-
//
1647-
// Note that this is where the recursive nature of the bootstrap
1648-
// happens, as this will request the previous stage's compiler on
1649-
// downwards to stage 0.
1650-
//
1651-
// Also note that we're building a compiler for the host platform. We
1652-
// only assume that we can run `build` artifacts, which means that to
1653-
// produce some other architecture compiler we need to start from
1654-
// `build` to get there.
1655-
//
1656-
// FIXME: It may be faster if we build just a stage 1 compiler and then
1657-
// use that to bootstrap this compiler forward.
1658-
let build_compiler = builder.compiler(target_compiler.stage - 1, builder.config.build);
1659-
16601655
// If we're downloading a compiler from CI, we can use the same compiler for all stages other than 0.
16611656
if builder.download_rustc() {
16621657
let sysroot =
@@ -1671,19 +1666,30 @@ impl Step for Assemble {
16711666
return target_compiler;
16721667
}
16731668

1669+
// Get the compiler that we'll use to bootstrap ourselves.
1670+
//
1671+
// Note that this is where the recursive nature of the bootstrap
1672+
// happens, as this will request the previous stage's compiler on
1673+
// downwards to stage 0.
1674+
//
1675+
// Also note that we're building a compiler for the host platform. We
1676+
// only assume that we can run `build` artifacts, which means that to
1677+
// produce some other architecture compiler we need to start from
1678+
// `build` to get there.
1679+
//
1680+
// FIXME: It may be faster if we build just a stage 1 compiler and then
1681+
// use that to bootstrap this compiler forward.
1682+
let mut build_compiler = builder.compiler(target_compiler.stage - 1, builder.config.build);
1683+
16741684
// Build the libraries for this compiler to link to (i.e., the libraries
16751685
// it uses at runtime). NOTE: Crates the target compiler compiles don't
16761686
// link to these. (FIXME: Is that correct? It seems to be correct most
16771687
// of the time but I think we do link to these for stage2/bin compilers
16781688
// when not performing a full bootstrap).
1679-
builder.ensure(Rustc::new(build_compiler, target_compiler.host));
1680-
1681-
// FIXME: For now patch over problems noted in #90244 by early returning here, even though
1682-
// we've not properly assembled the target sysroot. A full fix is pending further investigation,
1683-
// for now full bootstrap usage is rare enough that this is OK.
1684-
if target_compiler.stage >= 3 && !builder.config.full_bootstrap {
1685-
return target_compiler;
1686-
}
1689+
let actual_stage = builder.ensure(Rustc::new(build_compiler, target_compiler.host));
1690+
// Current build_compiler.stage might be uplifted instead of being built; so update it
1691+
// to not fail while linking the artifacts.
1692+
build_compiler.stage = actual_stage;
16871693

16881694
for &backend in builder.config.rust_codegen_backends.iter() {
16891695
if backend == "llvm" {

0 commit comments

Comments
 (0)