@@ -680,6 +680,14 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, cargo: &mut Car
680680 cargo. rustdocflag ( "-Zcrate-attr=warn(rust_2018_idioms)" ) ;
681681}
682682
683+ /// Link all libstd rlibs/dylibs into a sysroot of `target_compiler`.
684+ ///
685+ /// Links those artifacts generated by `compiler` to the `stage` compiler's
686+ /// sysroot for the specified `host` and `target`.
687+ ///
688+ /// Note that this assumes that `compiler` has already generated the libstd
689+ /// libraries for `target`, and this method will find them in the relevant
690+ /// output directory.
683691#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
684692pub struct StdLink {
685693 pub compiler : Compiler ,
@@ -710,14 +718,6 @@ impl Step for StdLink {
710718 run. never ( )
711719 }
712720
713- /// Link all libstd rlibs/dylibs into the sysroot location.
714- ///
715- /// Links those artifacts generated by `compiler` to the `stage` compiler's
716- /// sysroot for the specified `host` and `target`.
717- ///
718- /// Note that this assumes that `compiler` has already generated the libstd
719- /// libraries for `target`, and this method will find them in the relevant
720- /// output directory.
721721 #[ cfg_attr(
722722 feature = "tracing" ,
723723 instrument(
@@ -988,14 +988,8 @@ impl Rustc {
988988}
989989
990990impl Step for Rustc {
991- /// We return the stage of the "actual" compiler (not the uplifted one).
992- ///
993- /// By "actual" we refer to the uplifting logic where we may not compile the requested stage;
994- /// instead, we uplift it from the previous stages. Which can lead to bootstrap failures in
995- /// specific situations where we request stage X from other steps. However we may end up
996- /// uplifting it from stage Y, causing the other stage to fail when attempting to link with
997- /// stage X which was never actually built.
998- type Output = u32 ;
991+ type Output = ( ) ;
992+
999993 const ONLY_HOSTS : bool = true ;
1000994 const DEFAULT : bool = false ;
1001995
@@ -1043,7 +1037,7 @@ impl Step for Rustc {
10431037 fields( previous_compiler = ?self . build_compiler, target = ?self . target) ,
10441038 ) ,
10451039 ) ]
1046- fn run ( self , builder : & Builder < ' _ > ) -> u32 {
1040+ fn run ( self , builder : & Builder < ' _ > ) {
10471041 let build_compiler = self . build_compiler ;
10481042 let target = self . target ;
10491043
@@ -1059,7 +1053,7 @@ impl Step for Rustc {
10591053 & sysroot,
10601054 builder. config . ci_rustc_dev_contents ( ) ,
10611055 ) ;
1062- return build_compiler . stage ;
1056+ return ;
10631057 }
10641058
10651059 // Build a standard library for `target` using the `build_compiler`.
@@ -1073,31 +1067,33 @@ impl Step for Rustc {
10731067 builder. info ( "WARNING: Use `--keep-stage-std` if you want to rebuild the compiler when it changes" ) ;
10741068 builder. ensure ( RustcLink :: from_rustc ( self , build_compiler) ) ;
10751069
1076- return build_compiler . stage ;
1070+ return ;
10771071 }
10781072
1079- let compiler_to_use =
1080- builder. compiler_for ( build_compiler. stage , build_compiler. host , target) ;
1081- if compiler_to_use != build_compiler {
1082- builder. ensure ( Rustc :: new ( compiler_to_use, target) ) ;
1083- let msg = if compiler_to_use. host == target {
1084- format ! (
1085- "Uplifting rustc (stage{} -> stage{})" ,
1086- compiler_to_use. stage,
1087- build_compiler. stage + 1
1088- )
1073+ // The stage of the compiler that we're building
1074+ let stage = build_compiler. stage + 1 ;
1075+
1076+ // If we are building a stage3+ compiler, and full bootstrap is disabled, and we have a
1077+ // previous rustc available, we will uplift a compiler from a previous stage.
1078+ if build_compiler. stage >= 2
1079+ && !builder. config . full_bootstrap
1080+ && ( target == builder. host_target || builder. hosts . contains ( & target) )
1081+ {
1082+ // If we're cross-compiling, the earliest rustc that we could have is stage 2.
1083+ // If we're not cross-compiling, then we should have rustc stage 1.
1084+ let stage_to_uplift = if target == builder. host_target { 1 } else { 2 } ;
1085+ let rustc_to_uplift = builder. compiler ( stage_to_uplift, target) ;
1086+ let msg = if rustc_to_uplift. host == target {
1087+ format ! ( "Uplifting rustc (stage{} -> stage{stage})" , rustc_to_uplift. stage, )
10891088 } else {
10901089 format ! (
1091- "Uplifting rustc (stage{}:{} -> stage{}:{})" ,
1092- compiler_to_use. stage,
1093- compiler_to_use. host,
1094- build_compiler. stage + 1 ,
1095- target
1090+ "Uplifting rustc (stage{}:{} -> stage{stage}:{target})" ,
1091+ rustc_to_uplift. stage, rustc_to_uplift. host,
10961092 )
10971093 } ;
10981094 builder. info ( & msg) ;
1099- builder. ensure ( RustcLink :: from_rustc ( self , compiler_to_use ) ) ;
1100- return compiler_to_use . stage ;
1095+ builder. ensure ( RustcLink :: from_rustc ( self , rustc_to_uplift ) ) ;
1096+ return ;
11011097 }
11021098
11031099 // Build a standard library for the current host target using the `build_compiler`.
@@ -1174,8 +1170,6 @@ impl Step for Rustc {
11741170 self ,
11751171 builder. compiler ( build_compiler. stage , builder. config . host_target ) ,
11761172 ) ) ;
1177-
1178- build_compiler. stage
11791173 }
11801174
11811175 fn metadata ( & self ) -> Option < StepMetadata > {
@@ -1984,12 +1978,18 @@ impl Step for Sysroot {
19841978 }
19851979}
19861980
1981+ /// Prepare a compiler sysroot.
1982+ ///
1983+ /// The sysroot may contain various things useful for running the compiler, like linkers and
1984+ /// linker wrappers (LLD, LLVM bitcode linker, etc.).
1985+ ///
1986+ /// This will assemble a compiler in `build/$target/stage$stage`.
19871987#[ derive( Debug , PartialOrd , Ord , Clone , PartialEq , Eq , Hash ) ]
19881988pub struct Assemble {
19891989 /// The compiler which we will produce in this step. Assemble itself will
19901990 /// take care of ensuring that the necessary prerequisites to do so exist,
1991- /// that is, this target can be a stage2 compiler and Assemble will build
1992- /// previous stages for you.
1991+ /// that is, this can be e.g. a stage2 compiler and Assemble will build
1992+ /// the previous stages for you.
19931993 pub target_compiler : Compiler ,
19941994}
19951995
@@ -2007,11 +2007,6 @@ impl Step for Assemble {
20072007 } ) ;
20082008 }
20092009
2010- /// Prepare a new compiler from the artifacts in `stage`
2011- ///
2012- /// This will assemble a compiler in `build/$host/stage$stage`. The compiler
2013- /// must have been previously produced by the `stage - 1` builder.build
2014- /// compiler.
20152010 #[ cfg_attr(
20162011 feature = "tracing" ,
20172012 instrument(
@@ -2149,7 +2144,7 @@ impl Step for Assemble {
21492144 target_compiler. stage - 1 ,
21502145 builder. config. host_target,
21512146 ) ;
2152- let mut build_compiler =
2147+ let build_compiler =
21532148 builder. compiler ( target_compiler. stage - 1 , builder. config . host_target ) ;
21542149
21552150 // Build enzyme
@@ -2173,24 +2168,13 @@ impl Step for Assemble {
21732168 }
21742169
21752170 // Build the libraries for this compiler to link to (i.e., the libraries
2176- // it uses at runtime). NOTE: Crates the target compiler compiles don't
2177- // link to these. (FIXME: Is that correct? It seems to be correct most
2178- // of the time but I think we do link to these for stage2/bin compilers
2179- // when not performing a full bootstrap).
2171+ // it uses at runtime).
21802172 debug ! (
21812173 ?build_compiler,
21822174 "target_compiler.host" = ?target_compiler. host,
21832175 "building compiler libraries to link to"
21842176 ) ;
2185- let actual_stage = builder. ensure ( Rustc :: new ( build_compiler, target_compiler. host ) ) ;
2186- // Current build_compiler.stage might be uplifted instead of being built; so update it
2187- // to not fail while linking the artifacts.
2188- debug ! (
2189- "(old) build_compiler.stage" = build_compiler. stage,
2190- "(adjusted) build_compiler.stage" = actual_stage,
2191- "temporarily adjusting `build_compiler.stage` to account for uplifted libraries"
2192- ) ;
2193- build_compiler. stage = actual_stage;
2177+ builder. ensure ( Rustc :: new ( build_compiler, target_compiler. host ) ) ;
21942178
21952179 let mut codegen_backend_stamps = vec ! [ ] ;
21962180 {
0 commit comments