@@ -803,7 +803,14 @@ impl Rustc {
803
803
}
804
804
805
805
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 ;
807
814
const ONLY_HOSTS : bool = true ;
808
815
const DEFAULT : bool = false ;
809
816
@@ -834,7 +841,7 @@ impl Step for Rustc {
834
841
/// This will build the compiler for a particular stage of the build using
835
842
/// the `compiler` targeting the `target` architecture. The artifacts
836
843
/// created will also be linked into the sysroot directory.
837
- fn run ( self , builder : & Builder < ' _ > ) {
844
+ fn run ( self , builder : & Builder < ' _ > ) -> u32 {
838
845
let compiler = self . compiler ;
839
846
let target = self . target ;
840
847
@@ -848,7 +855,7 @@ impl Step for Rustc {
848
855
compiler,
849
856
builder. config . ci_rustc_dev_contents ( ) ,
850
857
) ;
851
- return ;
858
+ return compiler . stage ;
852
859
}
853
860
854
861
builder. ensure ( Std :: new ( compiler, target) ) ;
@@ -857,7 +864,8 @@ impl Step for Rustc {
857
864
builder. info ( "WARNING: Using a potentially old librustc. This may not behave well." ) ;
858
865
builder. info ( "WARNING: Use `--keep-stage-std` if you want to rebuild the compiler when it changes" ) ;
859
866
builder. ensure ( RustcLink :: from_rustc ( self , compiler) ) ;
860
- return ;
867
+
868
+ return compiler. stage ;
861
869
}
862
870
863
871
let compiler_to_use = builder. compiler_for ( compiler. stage , compiler. host , target) ;
@@ -880,7 +888,7 @@ impl Step for Rustc {
880
888
} ;
881
889
builder. info ( & msg) ;
882
890
builder. ensure ( RustcLink :: from_rustc ( self , compiler_to_use) ) ;
883
- return ;
891
+ return compiler_to_use . stage ;
884
892
}
885
893
886
894
// Ensure that build scripts and proc macros have a std / libproc_macro to link against.
@@ -984,6 +992,8 @@ impl Step for Rustc {
984
992
self ,
985
993
builder. compiler ( compiler. stage , builder. config . build ) ,
986
994
) ) ;
995
+
996
+ compiler. stage
987
997
}
988
998
}
989
999
@@ -1642,21 +1652,6 @@ impl Step for Assemble {
1642
1652
return target_compiler;
1643
1653
}
1644
1654
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
-
1660
1655
// If we're downloading a compiler from CI, we can use the same compiler for all stages other than 0.
1661
1656
if builder. download_rustc ( ) {
1662
1657
let sysroot =
@@ -1671,19 +1666,30 @@ impl Step for Assemble {
1671
1666
return target_compiler;
1672
1667
}
1673
1668
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
+
1674
1684
// Build the libraries for this compiler to link to (i.e., the libraries
1675
1685
// it uses at runtime). NOTE: Crates the target compiler compiles don't
1676
1686
// link to these. (FIXME: Is that correct? It seems to be correct most
1677
1687
// of the time but I think we do link to these for stage2/bin compilers
1678
1688
// 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;
1687
1693
1688
1694
for & backend in builder. config . rust_codegen_backends . iter ( ) {
1689
1695
if backend == "llvm" {
0 commit comments