@@ -413,13 +413,15 @@ impl<'a> Builder<'a> {
413413 pub fn rustdoc_cmd ( & self , host : Interned < String > ) -> Command {
414414 let mut cmd = Command :: new ( & self . out . join ( "bootstrap/debug/rustdoc" ) ) ;
415415 let compiler = self . compiler ( self . top_stage , host) ;
416- cmd
417- . env ( "RUSTC_STAGE" , compiler. stage . to_string ( ) )
418- . env ( "RUSTC_SYSROOT" , self . sysroot ( compiler) )
419- . env ( "RUSTC_LIBDIR" , self . sysroot_libdir ( compiler, self . build . build ) )
420- . env ( "CFG_RELEASE_CHANNEL" , & self . build . config . channel )
421- . env ( "RUSTDOC_REAL" , self . rustdoc ( host) )
422- . env ( "RUSTDOC_CRATE_VERSION" , self . build . rust_version ( ) ) ;
416+ cmd. env ( "RUSTC_STAGE" , compiler. stage . to_string ( ) )
417+ . env ( "RUSTC_SYSROOT" , self . sysroot ( compiler) )
418+ . env ( "RUSTC_LIBDIR" , self . sysroot_libdir ( compiler, self . build . build ) )
419+ . env ( "CFG_RELEASE_CHANNEL" , & self . build . config . channel )
420+ . env ( "RUSTDOC_REAL" , self . rustdoc ( host) )
421+ . env ( "RUSTDOC_CRATE_VERSION" , self . build . rust_version ( ) ) ;
422+ if let Some ( linker) = self . build . linker ( host) {
423+ cmd. env ( "RUSTC_TARGET_LINKER" , linker) ;
424+ }
423425 cmd
424426 }
425427
@@ -482,8 +484,14 @@ impl<'a> Builder<'a> {
482484 } else {
483485 PathBuf :: from ( "/path/to/nowhere/rustdoc/not/required" )
484486 } )
485- . env ( "TEST_MIRI" , self . config . test_miri . to_string ( ) )
486- . env ( "RUSTC_FLAGS" , self . rustc_flags ( target) . join ( " " ) ) ;
487+ . env ( "TEST_MIRI" , self . config . test_miri . to_string ( ) ) ;
488+
489+ if let Some ( host_linker) = self . build . linker ( compiler. host ) {
490+ cargo. env ( "RUSTC_HOST_LINKER" , host_linker) ;
491+ }
492+ if let Some ( target_linker) = self . build . linker ( target) {
493+ cargo. env ( "RUSTC_TARGET_LINKER" , target_linker) ;
494+ }
487495
488496 if mode != Mode :: Tool {
489497 // Tools don't get debuginfo right now, e.g. cargo and rls don't
@@ -557,17 +565,35 @@ impl<'a> Builder<'a> {
557565
558566 cargo. env ( "RUSTC_VERBOSE" , format ! ( "{}" , self . verbosity) ) ;
559567
560- // Specify some various options for build scripts used throughout
561- // the build.
568+ // Throughout the build Cargo can execute a number of build scripts
569+ // compiling C/C++ code and we need to pass compilers, archivers, flags, etc
570+ // obtained previously to those build scripts.
571+ // Build scripts use either the `cc` crate or `configure/make` so we pass
572+ // the options through environment variables that are fetched and understood by both.
562573 //
563574 // FIXME: the guard against msvc shouldn't need to be here
564575 if !target. contains ( "msvc" ) {
565- cargo. env ( format ! ( "CC_{}" , target) , self . cc ( target) )
566- . env ( format ! ( "AR_{}" , target) , self . ar ( target) . unwrap ( ) ) // only msvc is None
567- . env ( format ! ( "CFLAGS_{}" , target) , self . cflags ( target) . join ( " " ) ) ;
576+ let cc = self . cc ( target) ;
577+ cargo. env ( format ! ( "CC_{}" , target) , cc)
578+ . env ( "CC" , cc) ;
579+
580+ let cflags = self . cflags ( target) . join ( " " ) ;
581+ cargo. env ( format ! ( "CFLAGS_{}" , target) , cflags. clone ( ) )
582+ . env ( "CFLAGS" , cflags. clone ( ) ) ;
583+
584+ if let Some ( ar) = self . ar ( target) {
585+ let ranlib = format ! ( "{} s" , ar. display( ) ) ;
586+ cargo. env ( format ! ( "AR_{}" , target) , ar)
587+ . env ( "AR" , ar)
588+ . env ( format ! ( "RANLIB_{}" , target) , ranlib. clone ( ) )
589+ . env ( "RANLIB" , ranlib) ;
590+ }
568591
569592 if let Ok ( cxx) = self . cxx ( target) {
570- cargo. env ( format ! ( "CXX_{}" , target) , cxx) ;
593+ cargo. env ( format ! ( "CXX_{}" , target) , cxx)
594+ . env ( "CXX" , cxx)
595+ . env ( format ! ( "CXXFLAGS_{}" , target) , cflags. clone ( ) )
596+ . env ( "CXXFLAGS" , cflags) ;
571597 }
572598 }
573599
0 commit comments