@@ -229,7 +229,7 @@ impl Step for Std {
229229 . join ( "bin" ) ;
230230 if src_sysroot_bin. exists ( ) {
231231 let target_sysroot_bin =
232- builder. sysroot_libdir ( compiler, target) . parent ( ) . unwrap ( ) . join ( "bin" ) ;
232+ builder. sysroot_target_libdir ( compiler, target) . parent ( ) . unwrap ( ) . join ( "bin" ) ;
233233 t ! ( fs:: create_dir_all( & target_sysroot_bin) ) ;
234234 builder. cp_link_r ( & src_sysroot_bin, & target_sysroot_bin) ;
235235 }
@@ -343,7 +343,7 @@ fn copy_third_party_objects(
343343 && ( target. contains ( "linux" ) || target. contains ( "fuchsia" ) )
344344 {
345345 let libunwind_path =
346- copy_llvm_libunwind ( builder, target, & builder. sysroot_libdir ( * compiler, target) ) ;
346+ copy_llvm_libunwind ( builder, target, & builder. sysroot_target_libdir ( * compiler, target) ) ;
347347 target_deps. push ( ( libunwind_path, DependencyType :: Target ) ) ;
348348 }
349349
@@ -356,7 +356,8 @@ fn copy_self_contained_objects(
356356 compiler : & Compiler ,
357357 target : TargetSelection ,
358358) -> Vec < ( PathBuf , DependencyType ) > {
359- let libdir_self_contained = builder. sysroot_libdir ( * compiler, target) . join ( "self-contained" ) ;
359+ let libdir_self_contained =
360+ builder. sysroot_target_libdir ( * compiler, target) . join ( "self-contained" ) ;
360361 t ! ( fs:: create_dir_all( & libdir_self_contained) ) ;
361362 let mut target_deps = vec ! [ ] ;
362363
@@ -610,8 +611,8 @@ impl Step for StdLink {
610611 let hostdir = sysroot. join ( lib) . join ( "rustlib" ) . join ( compiler. host . triple ) . join ( "lib" ) ;
611612 ( libdir, hostdir)
612613 } else {
613- let libdir = builder. sysroot_libdir ( target_compiler, target) ;
614- let hostdir = builder. sysroot_libdir ( target_compiler, compiler. host ) ;
614+ let libdir = builder. sysroot_target_libdir ( target_compiler, target) ;
615+ let hostdir = builder. sysroot_target_libdir ( target_compiler, compiler. host ) ;
615616 ( libdir, hostdir)
616617 } ;
617618
@@ -678,7 +679,7 @@ fn copy_sanitizers(
678679 }
679680
680681 let mut target_deps = Vec :: new ( ) ;
681- let libdir = builder. sysroot_libdir ( * compiler, target) ;
682+ let libdir = builder. sysroot_target_libdir ( * compiler, target) ;
682683
683684 for runtime in & runtimes {
684685 let dst = libdir. join ( & runtime. name ) ;
@@ -764,7 +765,7 @@ impl Step for StartupObjects {
764765
765766 let src_dir = & builder. src . join ( "library" ) . join ( "rtstartup" ) ;
766767 let dst_dir = & builder. native_dir ( target) . join ( "rtstartup" ) ;
767- let sysroot_dir = & builder. sysroot_libdir ( for_compiler, target) ;
768+ let sysroot_dir = & builder. sysroot_target_libdir ( for_compiler, target) ;
768769 t ! ( fs:: create_dir_all( dst_dir) ) ;
769770
770771 for file in & [ "rsbegin" , "rsend" ] {
@@ -1229,9 +1230,16 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
12291230 }
12301231}
12311232
1233+ /// `RustcLink` copies all of the rlibs from the rustc build into the previous stage's sysroot.
1234+ /// This is necessary for tools using `rustc_private`, where the previous compiler will build
1235+ /// a tool against the next compiler.
1236+ /// To build a tool against a compiler, the rlibs of that compiler that it links against
1237+ /// must be in the sysroot of the compiler that's doing the compiling.
12321238#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
12331239struct RustcLink {
1240+ /// The compiler whose rlibs we are copying around.
12341241 pub compiler : Compiler ,
1242+ /// This is the compiler into whose sysroot we want to copy the rlibs into.
12351243 pub target_compiler : Compiler ,
12361244 pub target : TargetSelection ,
12371245 /// Not actually used; only present to make sure the cache invalidation is correct.
@@ -1263,8 +1271,8 @@ impl Step for RustcLink {
12631271 let target = self . target ;
12641272 add_to_sysroot (
12651273 builder,
1266- & builder. sysroot_libdir ( target_compiler, target) ,
1267- & builder. sysroot_libdir ( target_compiler, compiler. host ) ,
1274+ & builder. sysroot_target_libdir ( target_compiler, target) ,
1275+ & builder. sysroot_target_libdir ( target_compiler, compiler. host ) ,
12681276 & librustc_stamp ( builder, compiler, target) ,
12691277 ) ;
12701278 }
@@ -1789,7 +1797,7 @@ impl Step for Assemble {
17891797 let sysroot = builder. sysroot ( target_compiler) ;
17901798 let rustc_libdir = builder. rustc_libdir ( target_compiler) ;
17911799 t ! ( fs:: create_dir_all( & rustc_libdir) ) ;
1792- let src_libdir = builder. sysroot_libdir ( build_compiler, host) ;
1800+ let src_libdir = builder. sysroot_target_libdir ( build_compiler, host) ;
17931801 for f in builder. read_dir ( & src_libdir) {
17941802 let filename = f. file_name ( ) . into_string ( ) . unwrap ( ) ;
17951803 if ( is_dylib ( & filename) || is_debug_info ( & filename) ) && !proc_macros. contains ( & filename)
@@ -1802,7 +1810,7 @@ impl Step for Assemble {
18021810
18031811 // We prepend this bin directory to the user PATH when linking Rust binaries. To
18041812 // avoid shadowing the system LLD we rename the LLD we provide to `rust-lld`.
1805- let libdir = builder. sysroot_libdir ( target_compiler, target_compiler. host ) ;
1813+ let libdir = builder. sysroot_target_libdir ( target_compiler, target_compiler. host ) ;
18061814 let libdir_bin = libdir. parent ( ) . unwrap ( ) . join ( "bin" ) ;
18071815 t ! ( fs:: create_dir_all( & libdir_bin) ) ;
18081816 if let Some ( lld_install) = lld_install {
0 commit comments