@@ -147,15 +147,23 @@ impl Step for Std {
147
147
) ]
148
148
fn run ( self , builder : & Builder < ' _ > ) {
149
149
let target = self . target ;
150
- let compiler = self . compiler ;
151
150
152
151
// 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 ;
154
154
builder. ensure ( StdLink :: from_std ( self , compiler) ) ;
155
155
156
156
return ;
157
157
}
158
158
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
+
159
167
// When using `download-rustc`, we already have artifacts for the host available. Don't
160
168
// recompile them.
161
169
if builder. download_rustc ( )
@@ -191,17 +199,16 @@ impl Step for Std {
191
199
192
200
let mut target_deps = builder. ensure ( StartupObjects { compiler, target } ) ;
193
201
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) ;
195
203
trace ! ( ?compiler_to_use) ;
196
204
197
205
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,
199
207
// uplift it from there.
200
208
//
201
209
// FIXME: improve `fn compiler_for` to avoid adding stage condition here.
202
- && compiler. stage > 2
210
+ && compiler. stage > 1
203
211
{
204
- compiler_to_use. stage = 2 ;
205
212
trace ! ( ?compiler_to_use, ?compiler, "compiler != compiler_to_use, uplifting library" ) ;
206
213
207
214
builder. ensure ( Std :: new ( compiler_to_use, target) ) ;
@@ -234,27 +241,6 @@ impl Step for Std {
234
241
235
242
target_deps. extend ( self . copy_extra_objects ( builder, & compiler, target) ) ;
236
243
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
-
258
244
// We build a sysroot for mir-opt tests using the same trick that Miri does: A check build
259
245
// with -Zalways-encode-mir. This frees us from the need to have a target linker, and the
260
246
// fact that this is a check build integrates nicely with run_cargo.
@@ -749,7 +735,7 @@ impl Step for StdLink {
749
735
let target = self . target ;
750
736
751
737
// 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 ( ) {
753
739
// NOTE: copies part of `sysroot_libdir` to avoid having to add a new `force_recompile` argument there too
754
740
let lib = builder. sysroot_libdir_relative ( self . compiler ) ;
755
741
let sysroot = builder. ensure ( crate :: core:: build_steps:: compile:: Sysroot {
0 commit comments