@@ -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 ( "RUSTDOC_LINKER" , linker) ;
424+ }
423425 cmd
424426 }
425427
@@ -485,6 +487,10 @@ impl<'a> Builder<'a> {
485487 . env ( "TEST_MIRI" , self . config . test_miri . to_string ( ) )
486488 . env ( "RUSTC_FLAGS" , self . rustc_flags ( target) . join ( " " ) ) ;
487489
490+ if let Some ( linker) = self . build . linker ( target) {
491+ cargo. env ( "RUSTDOC_LINKER" , linker) ;
492+ }
493+
488494 if mode != Mode :: Tool {
489495 // Tools don't get debuginfo right now, e.g. cargo and rls don't
490496 // get compiled with debuginfo.
@@ -557,17 +563,35 @@ impl<'a> Builder<'a> {
557563
558564 cargo. env ( "RUSTC_VERBOSE" , format ! ( "{}" , self . verbosity) ) ;
559565
560- // Specify some various options for build scripts used throughout
561- // the build.
566+ // Throughout the build Cargo can execute a number of build scripts
567+ // compiling C/C++ code and we need to pass compilers, archivers, flags, etc
568+ // obtained previously to those build scripts.
569+ // Build scripts use either the `cc` crate or `configure/make` so we pass
570+ // the options through environment variables that are fetched and understood by both.
562571 //
563572 // FIXME: the guard against msvc shouldn't need to be here
564573 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 ( " " ) ) ;
574+ let cc = self . cc ( target) ;
575+ cargo. env ( format ! ( "CC_{}" , target) , cc)
576+ . env ( "CC" , cc) ;
577+
578+ let cflags = self . cflags ( target) . join ( " " ) ;
579+ cargo. env ( format ! ( "CFLAGS_{}" , target) , cflags. clone ( ) )
580+ . env ( "CFLAGS" , cflags. clone ( ) ) ;
581+
582+ if let Some ( ar) = self . ar ( target) {
583+ let ranlib = format ! ( "{} s" , ar. display( ) ) ;
584+ cargo. env ( format ! ( "AR_{}" , target) , ar)
585+ . env ( "AR" , ar)
586+ . env ( format ! ( "RANLIB_{}" , target) , ranlib. clone ( ) )
587+ . env ( "RANLIB" , ranlib) ;
588+ }
568589
569590 if let Ok ( cxx) = self . cxx ( target) {
570- cargo. env ( format ! ( "CXX_{}" , target) , cxx) ;
591+ cargo. env ( format ! ( "CXX_{}" , target) , cxx)
592+ . env ( "CXX" , cxx)
593+ . env ( format ! ( "CXXFLAGS_{}" , target) , cflags. clone ( ) )
594+ . env ( "CXXFLAGS" , cflags) ;
571595 }
572596 }
573597
0 commit comments