@@ -151,15 +151,23 @@ impl Step for Std {
151
151
) ]
152
152
fn run ( self , builder : & Builder < ' _ > ) {
153
153
let target = self . target ;
154
- let compiler = self . compiler ;
155
154
156
155
// We already have std ready to be used for stage 0.
157
- if compiler. stage == 0 {
156
+ if self . compiler . stage == 0 {
157
+ let compiler = self . compiler ;
158
158
builder. ensure ( StdLink :: from_std ( self , compiler) ) ;
159
159
160
160
return ;
161
161
}
162
162
163
+ let compiler = if builder. download_rustc ( ) && self . force_recompile {
164
+ // When there are changes in the library tree with CI-rustc, we want to build
165
+ // the stageN library and that requires using stageN-1 compiler.
166
+ builder. compiler ( self . compiler . stage . saturating_sub ( 1 ) , builder. config . build )
167
+ } else {
168
+ self . compiler
169
+ } ;
170
+
163
171
// When using `download-rustc`, we already have artifacts for the host available. Don't
164
172
// recompile them.
165
173
if builder. download_rustc ( ) && builder. is_builder_target ( target) && !self . force_recompile {
@@ -192,17 +200,16 @@ impl Step for Std {
192
200
193
201
let mut target_deps = builder. ensure ( StartupObjects { compiler, target } ) ;
194
202
195
- let mut compiler_to_use = builder. compiler_for ( compiler. stage , compiler. host , target) ;
203
+ let compiler_to_use = builder. compiler_for ( compiler. stage , compiler. host , target) ;
196
204
trace ! ( ?compiler_to_use) ;
197
205
198
206
if compiler_to_use != compiler
199
- // Never uplift std unless we have compiled stage 2 ; if stage 2 is compiled,
207
+ // Never uplift std unless we have compiled stage 1 ; if stage 1 is compiled,
200
208
// uplift it from there.
201
209
//
202
210
// FIXME: improve `fn compiler_for` to avoid adding stage condition here.
203
- && compiler. stage > 2
211
+ && compiler. stage > 1
204
212
{
205
- compiler_to_use. stage = 2 ;
206
213
trace ! ( ?compiler_to_use, ?compiler, "compiler != compiler_to_use, uplifting library" ) ;
207
214
208
215
builder. ensure ( Std :: new ( compiler_to_use, target) ) ;
@@ -235,27 +242,6 @@ impl Step for Std {
235
242
236
243
target_deps. extend ( self . copy_extra_objects ( builder, & compiler, target) ) ;
237
244
238
- // The LLD wrappers and `rust-lld` are self-contained linking components that can be
239
- // necessary to link the stdlib on some targets. We'll also need to copy these binaries to
240
- // the `stage0-sysroot` to ensure the linker is found when bootstrapping on such a target.
241
- if compiler. stage == 0 && builder. is_builder_target ( compiler. host ) {
242
- trace ! (
243
- "(build == host) copying linking components to `stage0-sysroot` for bootstrapping"
244
- ) ;
245
- // We want to copy the host `bin` folder within the `rustlib` folder in the sysroot.
246
- let src_sysroot_bin = builder
247
- . rustc_snapshot_sysroot ( )
248
- . join ( "lib" )
249
- . join ( "rustlib" )
250
- . join ( compiler. host )
251
- . join ( "bin" ) ;
252
- if src_sysroot_bin. exists ( ) {
253
- let target_sysroot_bin = builder. sysroot_target_bindir ( compiler, target) ;
254
- t ! ( fs:: create_dir_all( & target_sysroot_bin) ) ;
255
- builder. cp_link_r ( & src_sysroot_bin, & target_sysroot_bin) ;
256
- }
257
- }
258
-
259
245
// We build a sysroot for mir-opt tests using the same trick that Miri does: A check build
260
246
// with -Zalways-encode-mir. This frees us from the need to have a target linker, and the
261
247
// fact that this is a check build integrates nicely with run_cargo.
@@ -750,7 +736,7 @@ impl Step for StdLink {
750
736
let target = self . target ;
751
737
752
738
// NOTE: intentionally does *not* check `target == builder.build` to avoid having to add the same check in `test::Crate`.
753
- let ( libdir, hostdir) = if self . force_recompile && builder. download_rustc ( ) {
739
+ let ( libdir, hostdir) = if ! self . force_recompile && builder. download_rustc ( ) {
754
740
// NOTE: copies part of `sysroot_libdir` to avoid having to add a new `force_recompile` argument there too
755
741
let lib = builder. sysroot_libdir_relative ( self . compiler ) ;
756
742
let sysroot = builder. ensure ( crate :: core:: build_steps:: compile:: Sysroot {
0 commit comments