@@ -220,7 +220,7 @@ impl Step for Std {
220
220
. join ( "bin" ) ;
221
221
if src_sysroot_bin. exists ( ) {
222
222
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" ) ;
224
224
t ! ( fs:: create_dir_all( & target_sysroot_bin) ) ;
225
225
builder. cp_link_r ( & src_sysroot_bin, & target_sysroot_bin) ;
226
226
}
@@ -334,7 +334,7 @@ fn copy_third_party_objects(
334
334
&& ( target. contains ( "linux" ) || target. contains ( "fuchsia" ) )
335
335
{
336
336
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) ) ;
338
338
target_deps. push ( ( libunwind_path, DependencyType :: Target ) ) ;
339
339
}
340
340
@@ -347,7 +347,8 @@ fn copy_self_contained_objects(
347
347
compiler : & Compiler ,
348
348
target : TargetSelection ,
349
349
) -> 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" ) ;
351
352
t ! ( fs:: create_dir_all( & libdir_self_contained) ) ;
352
353
let mut target_deps = vec ! [ ] ;
353
354
@@ -655,8 +656,8 @@ impl Step for StdLink {
655
656
let hostdir = sysroot. join ( lib) . join ( "rustlib" ) . join ( compiler. host ) . join ( "lib" ) ;
656
657
( libdir, hostdir)
657
658
} 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 ) ;
660
661
( libdir, hostdir)
661
662
} ;
662
663
@@ -723,7 +724,7 @@ fn copy_sanitizers(
723
724
}
724
725
725
726
let mut target_deps = Vec :: new ( ) ;
726
- let libdir = builder. sysroot_libdir ( * compiler, target) ;
727
+ let libdir = builder. sysroot_target_libdir ( * compiler, target) ;
727
728
728
729
for runtime in & runtimes {
729
730
let dst = libdir. join ( & runtime. name ) ;
@@ -801,7 +802,7 @@ impl Step for StartupObjects {
801
802
802
803
let src_dir = & builder. src . join ( "library" ) . join ( "rtstartup" ) ;
803
804
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) ;
805
806
t ! ( fs:: create_dir_all( dst_dir) ) ;
806
807
807
808
for file in & [ "rsbegin" , "rsend" ] {
@@ -1287,10 +1288,17 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
1287
1288
}
1288
1289
}
1289
1290
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.
1290
1296
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1291
1297
struct RustcLink {
1298
+ /// The compiler whose rlibs we are copying around.
1292
1299
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 ,
1294
1302
pub target : TargetSelection ,
1295
1303
/// Not actually used; only present to make sure the cache invalidation is correct.
1296
1304
crates : Vec < String > ,
@@ -1300,7 +1308,7 @@ impl RustcLink {
1300
1308
fn from_rustc ( rustc : Rustc , host_compiler : Compiler ) -> Self {
1301
1309
Self {
1302
1310
compiler : host_compiler,
1303
- target_compiler : rustc. compiler ,
1311
+ previous_stage_compiler : rustc. compiler ,
1304
1312
target : rustc. target ,
1305
1313
crates : rustc. crates ,
1306
1314
}
@@ -1317,12 +1325,12 @@ impl Step for RustcLink {
1317
1325
/// Same as `std_link`, only for librustc
1318
1326
fn run ( self , builder : & Builder < ' _ > ) {
1319
1327
let compiler = self . compiler ;
1320
- let target_compiler = self . target_compiler ;
1328
+ let previous_stage_compiler = self . previous_stage_compiler ;
1321
1329
let target = self . target ;
1322
1330
add_to_sysroot (
1323
1331
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 ) ,
1326
1334
& librustc_stamp ( builder, compiler, target) ,
1327
1335
) ;
1328
1336
}
@@ -1770,7 +1778,7 @@ impl Step for Assemble {
1770
1778
1771
1779
// We prepend this bin directory to the user PATH when linking Rust binaries. To
1772
1780
// 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 ) ;
1774
1782
let libdir_bin = libdir. parent ( ) . unwrap ( ) . join ( "bin" ) ;
1775
1783
t ! ( fs:: create_dir_all( & libdir_bin) ) ;
1776
1784
@@ -1854,8 +1862,9 @@ impl Step for Assemble {
1854
1862
if let Some ( enzyme_install) = enzyme_install {
1855
1863
let lib_ext = std:: env:: consts:: DLL_EXTENSION ;
1856
1864
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 ) ;
1859
1868
let dst_lib = libdir. join ( "libEnzyme-19" ) . with_extension ( lib_ext) ;
1860
1869
let target_dst_lib = target_libdir. join ( "libEnzyme-19" ) . with_extension ( lib_ext) ;
1861
1870
builder. copy_link ( & src_lib, & dst_lib) ;
@@ -1923,7 +1932,7 @@ impl Step for Assemble {
1923
1932
let sysroot = builder. sysroot ( target_compiler) ;
1924
1933
let rustc_libdir = builder. rustc_libdir ( target_compiler) ;
1925
1934
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) ;
1927
1936
for f in builder. read_dir ( & src_libdir) {
1928
1937
let filename = f. file_name ( ) . into_string ( ) . unwrap ( ) ;
1929
1938
0 commit comments