@@ -189,51 +189,50 @@ impl Step for Std {
189189
190190 let mut target_deps = builder. ensure ( StartupObjects { compiler : build_compiler, target } ) ;
191191
192- let compiler_to_use =
193- builder. compiler_for ( build_compiler. stage , build_compiler. host , target) ;
194- trace ! ( ?compiler_to_use) ;
195-
196- if compiler_to_use != build_compiler
197- // Never uplift std unless we have compiled stage 1; if stage 1 is compiled,
198- // uplift it from there.
199- //
200- // FIXME: improve `fn compiler_for` to avoid adding stage condition here.
201- && build_compiler. stage > 1
192+ // Stage of the stdlib that we're building
193+ let stage = build_compiler. stage ;
194+
195+ // If we're building a stage2+ libstd, full bootstrap is
196+ // disabled and we have a stage1 libstd already compiled for the given target,
197+ // then simply uplift a previously built stage1 library.
198+ if build_compiler. stage > 1
199+ && !builder. config . full_bootstrap
200+ // This estimates if a stage1 libstd exists for the given target. If we're not
201+ // cross-compiling, it should definitely exist by the time we're building a stage2
202+ // libstd.
203+ // Or if we are cross-compiling, and we are building a cross-compiled rustc, then that
204+ // rustc needs to link to a cross-compiled libstd, so again we should have a stage1
205+ // libstd for the given target prepared.
206+ // Even if we guess wrong in the cross-compiled case, the worst that should happen is
207+ // that we build a fresh stage1 libstd below, and then we immediately uplift it, so we
208+ // don't pay the libstd build cost twice.
209+ && ( target == builder. host_target || builder. config . hosts . contains ( & target) )
202210 {
203- trace ! (
204- ?compiler_to_use,
205- ?build_compiler,
206- "build_compiler != compiler_to_use, uplifting library"
207- ) ;
211+ let build_compiler_for_std_to_uplift = builder. compiler ( 1 , builder. host_target ) ;
212+ builder. std ( build_compiler_for_std_to_uplift, target) ;
208213
209- builder. std ( compiler_to_use, target) ;
210- let msg = if compiler_to_use. host == target {
214+ let msg = if build_compiler_for_std_to_uplift. host == target {
211215 format ! (
212- "Uplifting library (stage{} -> stage{})" ,
213- compiler_to_use . stage , build_compiler . stage
216+ "Uplifting library (stage{} -> stage{stage })" ,
217+ build_compiler_for_std_to_uplift . stage
214218 )
215219 } else {
216220 format ! (
217- "Uplifting library (stage{}:{} -> stage{}:{})" ,
218- compiler_to_use . stage, compiler_to_use . host, build_compiler . stage , target
221+ "Uplifting library (stage{}:{} -> stage{stage }:{target })" ,
222+ build_compiler_for_std_to_uplift . stage, build_compiler_for_std_to_uplift . host,
219223 )
220224 } ;
225+
221226 builder. info ( & msg) ;
222227
223228 // Even if we're not building std this stage, the new sysroot must
224229 // still contain the third party objects needed by various targets.
225230 self . copy_extra_objects ( builder, & build_compiler, target) ;
226231
227- builder. ensure ( StdLink :: from_std ( self , compiler_to_use ) ) ;
232+ builder. ensure ( StdLink :: from_std ( self , build_compiler_for_std_to_uplift ) ) ;
228233 return ;
229234 }
230235
231- trace ! (
232- ?compiler_to_use,
233- ?build_compiler,
234- "compiler == compiler_to_use, handling not-cross-compile scenario"
235- ) ;
236-
237236 target_deps. extend ( self . copy_extra_objects ( builder, & build_compiler, target) ) ;
238237
239238 // We build a sysroot for mir-opt tests using the same trick that Miri does: A check build
0 commit comments