@@ -240,7 +240,7 @@ impl Step for Std {
240240 . join ( "bin" ) ;
241241 if src_sysroot_bin. exists ( ) {
242242 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" ) ;
244244 t ! ( fs:: create_dir_all( & target_sysroot_bin) ) ;
245245 builder. cp_link_r ( & src_sysroot_bin, & target_sysroot_bin) ;
246246 }
@@ -354,7 +354,7 @@ fn copy_third_party_objects(
354354 && ( target. contains ( "linux" ) || target. contains ( "fuchsia" ) )
355355 {
356356 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) ) ;
358358 target_deps. push ( ( libunwind_path, DependencyType :: Target ) ) ;
359359 }
360360
@@ -367,7 +367,8 @@ fn copy_self_contained_objects(
367367 compiler : & Compiler ,
368368 target : TargetSelection ,
369369) -> 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" ) ;
371372 t ! ( fs:: create_dir_all( & libdir_self_contained) ) ;
372373 let mut target_deps = vec ! [ ] ;
373374
@@ -675,8 +676,8 @@ impl Step for StdLink {
675676 let hostdir = sysroot. join ( lib) . join ( "rustlib" ) . join ( compiler. host ) . join ( "lib" ) ;
676677 ( libdir, hostdir)
677678 } 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 ) ;
680681 ( libdir, hostdir)
681682 } ;
682683
@@ -743,7 +744,7 @@ fn copy_sanitizers(
743744 }
744745
745746 let mut target_deps = Vec :: new ( ) ;
746- let libdir = builder. sysroot_libdir ( * compiler, target) ;
747+ let libdir = builder. sysroot_target_libdir ( * compiler, target) ;
747748
748749 for runtime in & runtimes {
749750 let dst = libdir. join ( & runtime. name ) ;
@@ -821,7 +822,7 @@ impl Step for StartupObjects {
821822
822823 let src_dir = & builder. src . join ( "library" ) . join ( "rtstartup" ) ;
823824 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) ;
825826 t ! ( fs:: create_dir_all( dst_dir) ) ;
826827
827828 for file in & [ "rsbegin" , "rsend" ] {
@@ -1273,10 +1274,17 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
12731274 }
12741275}
12751276
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.
12761282#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
12771283struct RustcLink {
1284+ /// The compiler whose rlibs we are copying around.
12781285 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 ,
12801288 pub target : TargetSelection ,
12811289 /// Not actually used; only present to make sure the cache invalidation is correct.
12821290 crates : Vec < String > ,
@@ -1286,7 +1294,7 @@ impl RustcLink {
12861294 fn from_rustc ( rustc : Rustc , host_compiler : Compiler ) -> Self {
12871295 Self {
12881296 compiler : host_compiler,
1289- target_compiler : rustc. compiler ,
1297+ previous_stage_compiler : rustc. compiler ,
12901298 target : rustc. target ,
12911299 crates : rustc. crates ,
12921300 }
@@ -1303,12 +1311,12 @@ impl Step for RustcLink {
13031311 /// Same as `std_link`, only for librustc
13041312 fn run ( self , builder : & Builder < ' _ > ) {
13051313 let compiler = self . compiler ;
1306- let target_compiler = self . target_compiler ;
1314+ let previous_stage_compiler = self . previous_stage_compiler ;
13071315 let target = self . target ;
13081316 add_to_sysroot (
13091317 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 ) ,
13121320 & librustc_stamp ( builder, compiler, target) ,
13131321 ) ;
13141322 }
@@ -1845,7 +1853,7 @@ impl Step for Assemble {
18451853 let sysroot = builder. sysroot ( target_compiler) ;
18461854 let rustc_libdir = builder. rustc_libdir ( target_compiler) ;
18471855 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) ;
18491857 for f in builder. read_dir ( & src_libdir) {
18501858 let filename = f. file_name ( ) . into_string ( ) . unwrap ( ) ;
18511859 if ( is_dylib ( & filename) || is_debug_info ( & filename) ) && !proc_macros. contains ( & filename)
@@ -1858,7 +1866,7 @@ impl Step for Assemble {
18581866
18591867 // We prepend this bin directory to the user PATH when linking Rust binaries. To
18601868 // 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 ) ;
18621870 let libdir_bin = libdir. parent ( ) . unwrap ( ) . join ( "bin" ) ;
18631871 t ! ( fs:: create_dir_all( & libdir_bin) ) ;
18641872 if let Some ( lld_install) = lld_install {
0 commit comments