@@ -240,7 +240,7 @@ impl Step for Std {
240
240
. join ( "bin" ) ;
241
241
if src_sysroot_bin. exists ( ) {
242
242
let target_sysroot_bin =
243
- builder. sysroot_libdir ( compiler, target) . parent ( ) . unwrap ( ) . join ( "bin" ) ;
243
+ builder. sysroot_target_libdir ( compiler, target) . parent ( ) . unwrap ( ) . join ( "bin" ) ;
244
244
t ! ( fs:: create_dir_all( & target_sysroot_bin) ) ;
245
245
builder. cp_link_r ( & src_sysroot_bin, & target_sysroot_bin) ;
246
246
}
@@ -354,7 +354,7 @@ fn copy_third_party_objects(
354
354
&& ( target. contains ( "linux" ) || target. contains ( "fuchsia" ) )
355
355
{
356
356
let libunwind_path =
357
- copy_llvm_libunwind ( builder, target, & builder. sysroot_libdir ( * compiler, target) ) ;
357
+ copy_llvm_libunwind ( builder, target, & builder. sysroot_target_libdir ( * compiler, target) ) ;
358
358
target_deps. push ( ( libunwind_path, DependencyType :: Target ) ) ;
359
359
}
360
360
@@ -367,7 +367,8 @@ fn copy_self_contained_objects(
367
367
compiler : & Compiler ,
368
368
target : TargetSelection ,
369
369
) -> Vec < ( PathBuf , DependencyType ) > {
370
- let libdir_self_contained = builder. sysroot_libdir ( * compiler, target) . join ( "self-contained" ) ;
370
+ let libdir_self_contained =
371
+ builder. sysroot_target_libdir ( * compiler, target) . join ( "self-contained" ) ;
371
372
t ! ( fs:: create_dir_all( & libdir_self_contained) ) ;
372
373
let mut target_deps = vec ! [ ] ;
373
374
@@ -675,8 +676,8 @@ impl Step for StdLink {
675
676
let hostdir = sysroot. join ( lib) . join ( "rustlib" ) . join ( compiler. host ) . join ( "lib" ) ;
676
677
( libdir, hostdir)
677
678
} else {
678
- let libdir = builder. sysroot_libdir ( target_compiler, target) ;
679
- let hostdir = builder. sysroot_libdir ( target_compiler, compiler. host ) ;
679
+ let libdir = builder. sysroot_target_libdir ( target_compiler, target) ;
680
+ let hostdir = builder. sysroot_target_libdir ( target_compiler, compiler. host ) ;
680
681
( libdir, hostdir)
681
682
} ;
682
683
@@ -743,7 +744,7 @@ fn copy_sanitizers(
743
744
}
744
745
745
746
let mut target_deps = Vec :: new ( ) ;
746
- let libdir = builder. sysroot_libdir ( * compiler, target) ;
747
+ let libdir = builder. sysroot_target_libdir ( * compiler, target) ;
747
748
748
749
for runtime in & runtimes {
749
750
let dst = libdir. join ( & runtime. name ) ;
@@ -821,7 +822,7 @@ impl Step for StartupObjects {
821
822
822
823
let src_dir = & builder. src . join ( "library" ) . join ( "rtstartup" ) ;
823
824
let dst_dir = & builder. native_dir ( target) . join ( "rtstartup" ) ;
824
- let sysroot_dir = & builder. sysroot_libdir ( for_compiler, target) ;
825
+ let sysroot_dir = & builder. sysroot_target_libdir ( for_compiler, target) ;
825
826
t ! ( fs:: create_dir_all( dst_dir) ) ;
826
827
827
828
for file in & [ "rsbegin" , "rsend" ] {
@@ -1273,10 +1274,17 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
1273
1274
}
1274
1275
}
1275
1276
1277
+ /// `RustcLink` copies all of the rlibs from the rustc build into the previous stage's sysroot.
1278
+ /// This is necessary for tools using `rustc_private`, where the previous compiler will build
1279
+ /// a tool against the next compiler.
1280
+ /// To build a tool against a compiler, the rlibs of that compiler that it links against
1281
+ /// must be in the sysroot of the compiler that's doing the compiling.
1276
1282
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1277
1283
struct RustcLink {
1284
+ /// The compiler whose rlibs we are copying around.
1278
1285
pub compiler : Compiler ,
1279
- pub target_compiler : Compiler ,
1286
+ /// This is the compiler into whose sysroot we want to copy the rlibs into.
1287
+ pub previous_stage_compiler : Compiler ,
1280
1288
pub target : TargetSelection ,
1281
1289
/// Not actually used; only present to make sure the cache invalidation is correct.
1282
1290
crates : Vec < String > ,
@@ -1286,7 +1294,7 @@ impl RustcLink {
1286
1294
fn from_rustc ( rustc : Rustc , host_compiler : Compiler ) -> Self {
1287
1295
Self {
1288
1296
compiler : host_compiler,
1289
- target_compiler : rustc. compiler ,
1297
+ previous_stage_compiler : rustc. compiler ,
1290
1298
target : rustc. target ,
1291
1299
crates : rustc. crates ,
1292
1300
}
@@ -1303,12 +1311,12 @@ impl Step for RustcLink {
1303
1311
/// Same as `std_link`, only for librustc
1304
1312
fn run ( self , builder : & Builder < ' _ > ) {
1305
1313
let compiler = self . compiler ;
1306
- let target_compiler = self . target_compiler ;
1314
+ let previous_stage_compiler = self . previous_stage_compiler ;
1307
1315
let target = self . target ;
1308
1316
add_to_sysroot (
1309
1317
builder,
1310
- & builder. sysroot_libdir ( target_compiler , target) ,
1311
- & builder. sysroot_libdir ( target_compiler , compiler. host ) ,
1318
+ & builder. sysroot_target_libdir ( previous_stage_compiler , target) ,
1319
+ & builder. sysroot_target_libdir ( previous_stage_compiler , compiler. host ) ,
1312
1320
& librustc_stamp ( builder, compiler, target) ,
1313
1321
) ;
1314
1322
}
@@ -1845,7 +1853,7 @@ impl Step for Assemble {
1845
1853
let sysroot = builder. sysroot ( target_compiler) ;
1846
1854
let rustc_libdir = builder. rustc_libdir ( target_compiler) ;
1847
1855
t ! ( fs:: create_dir_all( & rustc_libdir) ) ;
1848
- let src_libdir = builder. sysroot_libdir ( build_compiler, host) ;
1856
+ let src_libdir = builder. sysroot_target_libdir ( build_compiler, host) ;
1849
1857
for f in builder. read_dir ( & src_libdir) {
1850
1858
let filename = f. file_name ( ) . into_string ( ) . unwrap ( ) ;
1851
1859
if ( is_dylib ( & filename) || is_debug_info ( & filename) ) && !proc_macros. contains ( & filename)
@@ -1858,7 +1866,7 @@ impl Step for Assemble {
1858
1866
1859
1867
// We prepend this bin directory to the user PATH when linking Rust binaries. To
1860
1868
// avoid shadowing the system LLD we rename the LLD we provide to `rust-lld`.
1861
- let libdir = builder. sysroot_libdir ( target_compiler, target_compiler. host ) ;
1869
+ let libdir = builder. sysroot_target_libdir ( target_compiler, target_compiler. host ) ;
1862
1870
let libdir_bin = libdir. parent ( ) . unwrap ( ) . join ( "bin" ) ;
1863
1871
t ! ( fs:: create_dir_all( & libdir_bin) ) ;
1864
1872
if let Some ( lld_install) = lld_install {
0 commit comments