@@ -147,15 +147,23 @@ impl Step for Std {
147147 ) ]
148148 fn run ( self , builder : & Builder < ' _ > ) {
149149 let target = self . target ;
150- let compiler = self . compiler ;
151150
152151 // We already have std ready to be used for stage 0.
153- if compiler. stage == 0 {
152+ if self . compiler . stage == 0 {
153+ let compiler = self . compiler ;
154154 builder. ensure ( StdLink :: from_std ( self , compiler) ) ;
155155
156156 return ;
157157 }
158158
159+ let compiler = if builder. download_rustc ( ) && self . force_recompile {
160+ // When there are changes in the library tree with CI-rustc, we want to build
161+ // the stageN library and that requires using stageN-1 compiler.
162+ builder. compiler ( self . compiler . stage . saturating_sub ( 1 ) , builder. config . build )
163+ } else {
164+ self . compiler
165+ } ;
166+
159167 // When using `download-rustc`, we already have artifacts for the host available. Don't
160168 // recompile them.
161169 if builder. download_rustc ( )
@@ -191,17 +199,16 @@ impl Step for Std {
191199
192200 let mut target_deps = builder. ensure ( StartupObjects { compiler, target } ) ;
193201
194- let mut compiler_to_use = builder. compiler_for ( compiler. stage , compiler. host , target) ;
202+ let compiler_to_use = builder. compiler_for ( compiler. stage , compiler. host , target) ;
195203 trace ! ( ?compiler_to_use) ;
196204
197205 if compiler_to_use != compiler
198- // Never uplift std unless we have compiled stage 2 ; if stage 2 is compiled,
206+ // Never uplift std unless we have compiled stage 1 ; if stage 1 is compiled,
199207 // uplift it from there.
200208 //
201209 // FIXME: improve `fn compiler_for` to avoid adding stage condition here.
202- && compiler. stage > 2
210+ && compiler. stage > 1
203211 {
204- compiler_to_use. stage = 2 ;
205212 trace ! ( ?compiler_to_use, ?compiler, "compiler != compiler_to_use, uplifting library" ) ;
206213
207214 builder. ensure ( Std :: new ( compiler_to_use, target) ) ;
@@ -234,27 +241,6 @@ impl Step for Std {
234241
235242 target_deps. extend ( self . copy_extra_objects ( builder, & compiler, target) ) ;
236243
237- // The LLD wrappers and `rust-lld` are self-contained linking components that can be
238- // necessary to link the stdlib on some targets. We'll also need to copy these binaries to
239- // the `stage0-sysroot` to ensure the linker is found when bootstrapping on such a target.
240- if compiler. stage == 0 && builder. config . is_host_target ( compiler. host ) {
241- trace ! (
242- "(build == host) copying linking components to `stage0-sysroot` for bootstrapping"
243- ) ;
244- // We want to copy the host `bin` folder within the `rustlib` folder in the sysroot.
245- let src_sysroot_bin = builder
246- . rustc_snapshot_sysroot ( )
247- . join ( "lib" )
248- . join ( "rustlib" )
249- . join ( compiler. host )
250- . join ( "bin" ) ;
251- if src_sysroot_bin. exists ( ) {
252- let target_sysroot_bin = builder. sysroot_target_bindir ( compiler, target) ;
253- t ! ( fs:: create_dir_all( & target_sysroot_bin) ) ;
254- builder. cp_link_r ( & src_sysroot_bin, & target_sysroot_bin) ;
255- }
256- }
257-
258244 // We build a sysroot for mir-opt tests using the same trick that Miri does: A check build
259245 // with -Zalways-encode-mir. This frees us from the need to have a target linker, and the
260246 // fact that this is a check build integrates nicely with run_cargo.
@@ -749,7 +735,7 @@ impl Step for StdLink {
749735 let target = self . target ;
750736
751737 // NOTE: intentionally does *not* check `target == builder.build` to avoid having to add the same check in `test::Crate`.
752- let ( libdir, hostdir) = if self . force_recompile && builder. download_rustc ( ) {
738+ let ( libdir, hostdir) = if ! self . force_recompile && builder. download_rustc ( ) {
753739 // NOTE: copies part of `sysroot_libdir` to avoid having to add a new `force_recompile` argument there too
754740 let lib = builder. sysroot_libdir_relative ( self . compiler ) ;
755741 let sysroot = builder. ensure ( crate :: core:: build_steps:: compile:: Sysroot {
0 commit comments