@@ -220,7 +220,7 @@ impl Step for Std {
220220 . join ( "bin" ) ;
221221 if src_sysroot_bin. exists ( ) {
222222 let target_sysroot_bin =
223- builder. sysroot_libdir ( compiler, target) . parent ( ) . unwrap ( ) . join ( "bin" ) ;
223+ builder. sysroot_target_libdir ( compiler, target) . parent ( ) . unwrap ( ) . join ( "bin" ) ;
224224 t ! ( fs:: create_dir_all( & target_sysroot_bin) ) ;
225225 builder. cp_link_r ( & src_sysroot_bin, & target_sysroot_bin) ;
226226 }
@@ -334,7 +334,7 @@ fn copy_third_party_objects(
334334 && ( target. contains ( "linux" ) || target. contains ( "fuchsia" ) )
335335 {
336336 let libunwind_path =
337- copy_llvm_libunwind ( builder, target, & builder. sysroot_libdir ( * compiler, target) ) ;
337+ copy_llvm_libunwind ( builder, target, & builder. sysroot_target_libdir ( * compiler, target) ) ;
338338 target_deps. push ( ( libunwind_path, DependencyType :: Target ) ) ;
339339 }
340340
@@ -347,7 +347,8 @@ fn copy_self_contained_objects(
347347 compiler : & Compiler ,
348348 target : TargetSelection ,
349349) -> Vec < ( PathBuf , DependencyType ) > {
350- let libdir_self_contained = builder. sysroot_libdir ( * compiler, target) . join ( "self-contained" ) ;
350+ let libdir_self_contained =
351+ builder. sysroot_target_libdir ( * compiler, target) . join ( "self-contained" ) ;
351352 t ! ( fs:: create_dir_all( & libdir_self_contained) ) ;
352353 let mut target_deps = vec ! [ ] ;
353354
@@ -655,8 +656,8 @@ impl Step for StdLink {
655656 let hostdir = sysroot. join ( lib) . join ( "rustlib" ) . join ( compiler. host ) . join ( "lib" ) ;
656657 ( libdir, hostdir)
657658 } else {
658- let libdir = builder. sysroot_libdir ( target_compiler, target) ;
659- let hostdir = builder. sysroot_libdir ( target_compiler, compiler. host ) ;
659+ let libdir = builder. sysroot_target_libdir ( target_compiler, target) ;
660+ let hostdir = builder. sysroot_target_libdir ( target_compiler, compiler. host ) ;
660661 ( libdir, hostdir)
661662 } ;
662663
@@ -723,7 +724,7 @@ fn copy_sanitizers(
723724 }
724725
725726 let mut target_deps = Vec :: new ( ) ;
726- let libdir = builder. sysroot_libdir ( * compiler, target) ;
727+ let libdir = builder. sysroot_target_libdir ( * compiler, target) ;
727728
728729 for runtime in & runtimes {
729730 let dst = libdir. join ( & runtime. name ) ;
@@ -801,7 +802,7 @@ impl Step for StartupObjects {
801802
802803 let src_dir = & builder. src . join ( "library" ) . join ( "rtstartup" ) ;
803804 let dst_dir = & builder. native_dir ( target) . join ( "rtstartup" ) ;
804- let sysroot_dir = & builder. sysroot_libdir ( for_compiler, target) ;
805+ let sysroot_dir = & builder. sysroot_target_libdir ( for_compiler, target) ;
805806 t ! ( fs:: create_dir_all( dst_dir) ) ;
806807
807808 for file in & [ "rsbegin" , "rsend" ] {
@@ -1287,10 +1288,17 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
12871288 }
12881289}
12891290
1291+ /// `RustcLink` copies all of the rlibs from the rustc build into the previous stage's sysroot.
1292+ /// This is necessary for tools using `rustc_private`, where the previous compiler will build
1293+ /// a tool against the next compiler.
1294+ /// To build a tool against a compiler, the rlibs of that compiler that it links against
1295+ /// must be in the sysroot of the compiler that's doing the compiling.
12901296#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
12911297struct RustcLink {
1298+ /// The compiler whose rlibs we are copying around.
12921299 pub compiler : Compiler ,
1293- pub target_compiler : Compiler ,
1300+ /// This is the compiler into whose sysroot we want to copy the rlibs into.
1301+ pub previous_stage_compiler : Compiler ,
12941302 pub target : TargetSelection ,
12951303 /// Not actually used; only present to make sure the cache invalidation is correct.
12961304 crates : Vec < String > ,
@@ -1300,7 +1308,7 @@ impl RustcLink {
13001308 fn from_rustc ( rustc : Rustc , host_compiler : Compiler ) -> Self {
13011309 Self {
13021310 compiler : host_compiler,
1303- target_compiler : rustc. compiler ,
1311+ previous_stage_compiler : rustc. compiler ,
13041312 target : rustc. target ,
13051313 crates : rustc. crates ,
13061314 }
@@ -1317,12 +1325,12 @@ impl Step for RustcLink {
13171325 /// Same as `std_link`, only for librustc
13181326 fn run ( self , builder : & Builder < ' _ > ) {
13191327 let compiler = self . compiler ;
1320- let target_compiler = self . target_compiler ;
1328+ let previous_stage_compiler = self . previous_stage_compiler ;
13211329 let target = self . target ;
13221330 add_to_sysroot (
13231331 builder,
1324- & builder. sysroot_libdir ( target_compiler , target) ,
1325- & builder. sysroot_libdir ( target_compiler , compiler. host ) ,
1332+ & builder. sysroot_target_libdir ( previous_stage_compiler , target) ,
1333+ & builder. sysroot_target_libdir ( previous_stage_compiler , compiler. host ) ,
13261334 & librustc_stamp ( builder, compiler, target) ,
13271335 ) ;
13281336 }
@@ -1770,7 +1778,7 @@ impl Step for Assemble {
17701778
17711779 // We prepend this bin directory to the user PATH when linking Rust binaries. To
17721780 // avoid shadowing the system LLD we rename the LLD we provide to `rust-lld`.
1773- let libdir = builder. sysroot_libdir ( target_compiler, target_compiler. host ) ;
1781+ let libdir = builder. sysroot_target_libdir ( target_compiler, target_compiler. host ) ;
17741782 let libdir_bin = libdir. parent ( ) . unwrap ( ) . join ( "bin" ) ;
17751783 t ! ( fs:: create_dir_all( & libdir_bin) ) ;
17761784
@@ -1854,8 +1862,9 @@ impl Step for Assemble {
18541862 if let Some ( enzyme_install) = enzyme_install {
18551863 let lib_ext = std:: env:: consts:: DLL_EXTENSION ;
18561864 let src_lib = enzyme_install. join ( "build/Enzyme/libEnzyme-19" ) . with_extension ( lib_ext) ;
1857- let libdir = builder. sysroot_libdir ( build_compiler, build_compiler. host ) ;
1858- let target_libdir = builder. sysroot_libdir ( target_compiler, target_compiler. host ) ;
1865+ let libdir = builder. sysroot_target_libdir ( build_compiler, build_compiler. host ) ;
1866+ let target_libdir =
1867+ builder. sysroot_target_libdir ( target_compiler, target_compiler. host ) ;
18591868 let dst_lib = libdir. join ( "libEnzyme-19" ) . with_extension ( lib_ext) ;
18601869 let target_dst_lib = target_libdir. join ( "libEnzyme-19" ) . with_extension ( lib_ext) ;
18611870 builder. copy_link ( & src_lib, & dst_lib) ;
@@ -1923,7 +1932,7 @@ impl Step for Assemble {
19231932 let sysroot = builder. sysroot ( target_compiler) ;
19241933 let rustc_libdir = builder. rustc_libdir ( target_compiler) ;
19251934 t ! ( fs:: create_dir_all( & rustc_libdir) ) ;
1926- let src_libdir = builder. sysroot_libdir ( build_compiler, host) ;
1935+ let src_libdir = builder. sysroot_target_libdir ( build_compiler, host) ;
19271936 for f in builder. read_dir ( & src_libdir) {
19281937 let filename = f. file_name ( ) . into_string ( ) . unwrap ( ) ;
19291938
0 commit comments