@@ -21,7 +21,7 @@ use tracing::{instrument, span};
2121
2222use crate :: core:: build_steps:: gcc:: { Gcc , add_cg_gcc_cargo_flags} ;
2323use crate :: core:: build_steps:: tool:: { Bindgen , SourceType } ;
24- use crate :: core:: build_steps:: { dist, llvm} ;
24+ use crate :: core:: build_steps:: { bdwgc , dist, llvm} ;
2525use crate :: core:: builder;
2626use crate :: core:: builder:: {
2727 Builder , Cargo , Kind , PathSet , RunConfig , ShouldRun , Step , TaskPath , crate_description,
@@ -283,6 +283,8 @@ impl Step for Std {
283283 }
284284 cargo
285285 } ;
286+ let bindgen = builder. ensure ( Bindgen { target } ) ;
287+ cargo. env ( "RUSTC_BINDGEN" , & bindgen. tool_path ) ;
286288
287289 // See src/bootstrap/synthetic_targets.rs
288290 if target. is_synthetic ( ) {
@@ -292,7 +294,7 @@ impl Step for Std {
292294 cargo. rustflag ( rustflag) ;
293295 }
294296
295- let bindgen = builder. ensure ( Bindgen { compiler , target } ) ;
297+ let bindgen = builder. ensure ( Bindgen { target } ) ;
296298 cargo. env ( "RUSTC_BINDGEN" , bindgen. tool_path ) ;
297299
298300 let _guard = builder. msg (
@@ -333,6 +335,33 @@ fn copy_and_stamp(
333335 target_deps. push ( ( target, dependency_type) ) ;
334336}
335337
338+ fn copy_libgc (
339+ builder : & Builder < ' _ > ,
340+ target : TargetSelection ,
341+ libdir : & Path ,
342+ ) -> Vec < ( PathBuf , DependencyType ) > {
343+ let mut v = Vec :: new ( ) ;
344+ let install_dir = builder. ensure ( bdwgc:: Bdwgc { target } ) ;
345+ if !install_dir. exists ( ) {
346+ return v;
347+ }
348+ for obj in fs:: read_dir ( install_dir) . unwrap ( ) {
349+ let p = obj. unwrap ( ) . path ( ) ;
350+ if !p. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . starts_with ( "libgc" ) {
351+ continue ;
352+ }
353+ if p. is_symlink ( ) {
354+ builder. install ( & t ! ( fs:: canonicalize( & p) ) , & libdir, 0o644 ) ;
355+ let full_dest = libdir. join ( p. file_name ( ) . unwrap ( ) ) ;
356+ builder. copy_link ( & p, & full_dest) ;
357+ } else {
358+ builder. install ( & p, & libdir, 0o644 ) ;
359+ }
360+ v. push ( ( p, DependencyType :: Target ) ) ;
361+ }
362+ v
363+ }
364+
336365fn copy_llvm_libunwind ( builder : & Builder < ' _ > , target : TargetSelection , libdir : & Path ) -> PathBuf {
337366 let libunwind_path = builder. ensure ( llvm:: Libunwind { target } ) ;
338367 let libunwind_source = libunwind_path. join ( "libunwind.a" ) ;
@@ -368,6 +397,11 @@ fn copy_third_party_objects(
368397 target_deps. push ( ( libunwind_path, DependencyType :: Target ) ) ;
369398 }
370399
400+ if builder. config . bdwgc_link_shared {
401+ let libgc_objs = copy_libgc ( builder, target, & builder. rustc_libdir ( * compiler) ) ;
402+ target_deps. extend ( libgc_objs)
403+ }
404+
371405 target_deps
372406}
373407
@@ -537,6 +571,8 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
537571 cargo. env ( "MACOSX_DEPLOYMENT_TARGET" , target) ;
538572 }
539573 }
574+ let bindgen = builder. ensure ( Bindgen { target } ) ;
575+ cargo. env ( "RUSTC_BINDGEN" , & bindgen. tool_path ) ;
540576
541577 // Paths needed by `library/profiler_builtins/build.rs`.
542578 if let Some ( path) = builder. config . profiler_path ( target) {
@@ -549,6 +585,12 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
549585 cargo. env ( "RUST_COMPILER_RT_FOR_PROFILER" , compiler_rt) ;
550586 }
551587
588+ // Evenutally we stick libgc.so in the current compiler stage's sysroot where the linker will
589+ // find it. But first, we must explicitly link the build directory because of bootstrap
590+ // ordering: the first thing rust does is build library/std with stage 0 which doesn't yet know
591+ // about libgc.
592+ cargo. rustflag ( "-L" ) . rustflag ( builder. bdwgc_out ( target) . join ( "lib" ) . to_str ( ) . unwrap ( ) ) ;
593+
552594 // Determine if we're going to compile in optimized C intrinsics to
553595 // the `compiler-builtins` crate. These intrinsics live in LLVM's
554596 // `compiler-rt` repository.
@@ -1191,6 +1233,9 @@ pub fn rustc_cargo(
11911233 }
11921234 }
11931235
1236+ let bindgen = builder. ensure ( Bindgen { target } ) ;
1237+ cargo. env ( "RUSTC_BINDGEN" , & bindgen. tool_path ) ;
1238+
11941239 // Building with protected visibility reduces the number of dynamic relocations needed, giving
11951240 // us a faster startup time. However GNU ld < 2.40 will error if we try to link a shared object
11961241 // with direct references to protected symbols, so for now we only use protected symbols if
@@ -1351,6 +1396,9 @@ pub fn rustc_cargo_env(
13511396 }
13521397 }
13531398
1399+ // Paths needed by `library/bdwgc/build.rs`.
1400+ let bindgen = builder. ensure ( Bindgen { target } ) ;
1401+ cargo. env ( "RUSTC_BINDGEN" , & bindgen. tool_path ) ;
13541402 // Build jemalloc on AArch64 with support for page sizes up to 64K
13551403 // See: https://github.com/rust-lang/rust/pull/135081
13561404 if builder. config . jemalloc ( target)
0 commit comments