@@ -803,7 +803,14 @@ impl Rustc {
803803}
804804
805805impl 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,12 +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 ) ) ;
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;
16801693
16811694 for & backend in builder. config . rust_codegen_backends . iter ( ) {
16821695 if backend == "llvm" {
0 commit comments