@@ -16,6 +16,7 @@ use build_helper::{output, t};
1616use crate :: cache:: { Cache , Interned , INTERNER } ;
1717use crate :: check;
1818use crate :: compile;
19+ use crate :: config:: TargetSelection ;
1920use crate :: dist;
2021use crate :: doc;
2122use crate :: flags:: Subcommand ;
@@ -86,8 +87,8 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {
8687
8788pub struct RunConfig < ' a > {
8889 pub builder : & ' a Builder < ' a > ,
89- pub host : Interned < String > ,
90- pub target : Interned < String > ,
90+ pub host : TargetSelection ,
91+ pub target : TargetSelection ,
9192 pub path : PathBuf ,
9293}
9394
@@ -576,7 +577,7 @@ impl<'a> Builder<'a> {
576577 /// not take `Compiler` since all `Compiler` instances are meant to be
577578 /// obtained through this function, since it ensures that they are valid
578579 /// (i.e., built and assembled).
579- pub fn compiler ( & self , stage : u32 , host : Interned < String > ) -> Compiler {
580+ pub fn compiler ( & self , stage : u32 , host : TargetSelection ) -> Compiler {
580581 self . ensure ( compile:: Assemble { target_compiler : Compiler { stage, host } } )
581582 }
582583
@@ -594,8 +595,8 @@ impl<'a> Builder<'a> {
594595 pub fn compiler_for (
595596 & self ,
596597 stage : u32 ,
597- host : Interned < String > ,
598- target : Interned < String > ,
598+ host : TargetSelection ,
599+ target : TargetSelection ,
599600 ) -> Compiler {
600601 if self . build . force_use_stage1 ( Compiler { stage, host } , target) {
601602 self . compiler ( 1 , self . config . build )
@@ -610,15 +611,11 @@ impl<'a> Builder<'a> {
610611
611612 /// Returns the libdir where the standard library and other artifacts are
612613 /// found for a compiler's sysroot.
613- pub fn sysroot_libdir (
614- & self ,
615- compiler : Compiler ,
616- target : Interned < String > ,
617- ) -> Interned < PathBuf > {
614+ pub fn sysroot_libdir ( & self , compiler : Compiler , target : TargetSelection ) -> Interned < PathBuf > {
618615 #[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
619616 struct Libdir {
620617 compiler : Compiler ,
621- target : Interned < String > ,
618+ target : TargetSelection ,
622619 }
623620 impl Step for Libdir {
624621 type Output = Interned < PathBuf > ;
@@ -633,7 +630,7 @@ impl<'a> Builder<'a> {
633630 . sysroot ( self . compiler )
634631 . join ( lib)
635632 . join ( "rustlib" )
636- . join ( self . target )
633+ . join ( self . target . triple )
637634 . join ( "lib" ) ;
638635 let _ = fs:: remove_dir_all ( & sysroot) ;
639636 t ! ( fs:: create_dir_all( & sysroot) ) ;
@@ -656,7 +653,7 @@ impl<'a> Builder<'a> {
656653 Some ( relative_libdir) if compiler. stage >= 1 => {
657654 self . sysroot ( compiler) . join ( relative_libdir)
658655 }
659- _ => self . sysroot ( compiler) . join ( libdir ( & compiler. host ) ) ,
656+ _ => self . sysroot ( compiler) . join ( libdir ( compiler. host ) ) ,
660657 }
661658 }
662659 }
@@ -668,11 +665,11 @@ impl<'a> Builder<'a> {
668665 /// Windows.
669666 pub fn libdir_relative ( & self , compiler : Compiler ) -> & Path {
670667 if compiler. is_snapshot ( self ) {
671- libdir ( & self . config . build ) . as_ref ( )
668+ libdir ( self . config . build ) . as_ref ( )
672669 } else {
673670 match self . config . libdir_relative ( ) {
674671 Some ( relative_libdir) if compiler. stage >= 1 => relative_libdir,
675- _ => libdir ( & compiler. host ) . as_ref ( ) ,
672+ _ => libdir ( compiler. host ) . as_ref ( ) ,
676673 }
677674 }
678675 }
@@ -707,7 +704,7 @@ impl<'a> Builder<'a> {
707704 if compiler. is_snapshot ( self ) {
708705 self . initial_rustc . clone ( )
709706 } else {
710- self . sysroot ( compiler) . join ( "bin" ) . join ( exe ( "rustc" , & compiler. host ) )
707+ self . sysroot ( compiler) . join ( "bin" ) . join ( exe ( "rustc" , compiler. host ) )
711708 }
712709 }
713710
@@ -741,7 +738,7 @@ impl<'a> Builder<'a> {
741738 ///
742739 /// Note that this returns `None` if LLVM is disabled, or if we're in a
743740 /// check build or dry-run, where there's no need to build all of LLVM.
744- fn llvm_config ( & self , target : Interned < String > ) -> Option < PathBuf > {
741+ fn llvm_config ( & self , target : TargetSelection ) -> Option < PathBuf > {
745742 if self . config . llvm_enabled ( ) && self . kind != Kind :: Check && !self . config . dry_run {
746743 let llvm_config = self . ensure ( native:: Llvm { target } ) ;
747744 if llvm_config. is_file ( ) {
@@ -763,7 +760,7 @@ impl<'a> Builder<'a> {
763760 compiler : Compiler ,
764761 mode : Mode ,
765762 source_type : SourceType ,
766- target : Interned < String > ,
763+ target : TargetSelection ,
767764 cmd : & str ,
768765 ) -> Cargo {
769766 let mut cargo = Command :: new ( & self . initial_cargo ) ;
@@ -773,7 +770,7 @@ impl<'a> Builder<'a> {
773770 let my_out = match mode {
774771 // This is the intended out directory for compiler documentation.
775772 Mode :: Rustc | Mode :: ToolRustc | Mode :: Codegen => self . compiler_doc_out ( target) ,
776- Mode :: Std => out_dir. join ( target) . join ( "doc" ) ,
773+ Mode :: Std => out_dir. join ( target. triple ) . join ( "doc" ) ,
777774 _ => panic ! ( "doc mode {:?} not expected" , mode) ,
778775 } ;
779776 let rustdoc = self . rustdoc ( compiler) ;
@@ -795,7 +792,7 @@ impl<'a> Builder<'a> {
795792 }
796793
797794 if cmd != "install" {
798- cargo. arg ( "--target" ) . arg ( target) ;
795+ cargo. arg ( "--target" ) . arg ( target. rustc_target_arg ( ) ) ;
799796 } else {
800797 assert_eq ! ( target, compiler. host) ;
801798 }
@@ -821,7 +818,7 @@ impl<'a> Builder<'a> {
821818 compiler. stage
822819 } ;
823820
824- let mut rustflags = Rustflags :: new ( & target) ;
821+ let mut rustflags = Rustflags :: new ( target) ;
825822 if stage != 0 {
826823 if let Ok ( s) = env:: var ( "CARGOFLAGS_NOT_BOOTSTRAP" ) {
827824 cargo. args ( s. split_whitespace ( ) ) ;
@@ -994,7 +991,7 @@ impl<'a> Builder<'a> {
994991 // argument manually via `-C link-args=-Wl,-rpath,...`. Plus isn't it
995992 // fun to pass a flag to a tool to pass a flag to pass a flag to a tool
996993 // to change a flag in a binary?
997- if self . config . rust_rpath && util:: use_host_linker ( & target) {
994+ if self . config . rust_rpath && util:: use_host_linker ( target) {
998995 let rpath = if target. contains ( "apple" ) {
999996 // Note that we need to take one extra step on macOS to also pass
1000997 // `-Wl,-instal_name,@rpath/...` to get things to work right. To
@@ -1022,7 +1019,7 @@ impl<'a> Builder<'a> {
10221019 }
10231020
10241021 if let Some ( target_linker) = self . linker ( target, can_use_lld) {
1025- let target = crate :: envify ( & target) ;
1022+ let target = crate :: envify ( & target. triple ) ;
10261023 cargo. env ( & format ! ( "CARGO_TARGET_{}_LINKER" , target) , target_linker) ;
10271024 }
10281025 if !( [ "build" , "check" , "clippy" , "fix" , "rustc" ] . contains ( & cmd) ) && want_rustdoc {
@@ -1193,21 +1190,23 @@ impl<'a> Builder<'a> {
11931190 }
11941191 } ;
11951192 let cc = ccacheify ( & self . cc ( target) ) ;
1196- cargo. env ( format ! ( "CC_{}" , target) , & cc) ;
1193+ cargo. env ( format ! ( "CC_{}" , target. triple ) , & cc) ;
11971194
11981195 let cflags = self . cflags ( target, GitRepo :: Rustc ) . join ( " " ) ;
1199- cargo. env ( format ! ( "CFLAGS_{}" , target) , cflags. clone ( ) ) ;
1196+ cargo. env ( format ! ( "CFLAGS_{}" , target. triple ) , cflags. clone ( ) ) ;
12001197
12011198 if let Some ( ar) = self . ar ( target) {
12021199 let ranlib = format ! ( "{} s" , ar. display( ) ) ;
1203- cargo. env ( format ! ( "AR_{}" , target) , ar) . env ( format ! ( "RANLIB_{}" , target) , ranlib) ;
1200+ cargo
1201+ . env ( format ! ( "AR_{}" , target. triple) , ar)
1202+ . env ( format ! ( "RANLIB_{}" , target. triple) , ranlib) ;
12041203 }
12051204
12061205 if let Ok ( cxx) = self . cxx ( target) {
12071206 let cxx = ccacheify ( & cxx) ;
12081207 cargo
1209- . env ( format ! ( "CXX_{}" , target) , & cxx)
1210- . env ( format ! ( "CXXFLAGS_{}" , target) , cflags) ;
1208+ . env ( format ! ( "CXX_{}" , target. triple ) , & cxx)
1209+ . env ( format ! ( "CXXFLAGS_{}" , target. triple ) , cflags) ;
12111210 }
12121211 }
12131212
@@ -1241,7 +1240,7 @@ impl<'a> Builder<'a> {
12411240 // Environment variables *required* throughout the build
12421241 //
12431242 // FIXME: should update code to not require this env var
1244- cargo. env ( "CFG_COMPILER_HOST_TRIPLE" , target) ;
1243+ cargo. env ( "CFG_COMPILER_HOST_TRIPLE" , target. triple ) ;
12451244
12461245 // Set this for all builds to make sure doc builds also get it.
12471246 cargo. env ( "CFG_RELEASE_CHANNEL" , & self . config . channel ) ;
@@ -1397,15 +1396,15 @@ mod tests;
13971396struct Rustflags ( String ) ;
13981397
13991398impl Rustflags {
1400- fn new ( target : & str ) -> Rustflags {
1399+ fn new ( target : TargetSelection ) -> Rustflags {
14011400 let mut ret = Rustflags ( String :: new ( ) ) ;
14021401
14031402 // Inherit `RUSTFLAGS` by default ...
14041403 ret. env ( "RUSTFLAGS" ) ;
14051404
14061405 // ... and also handle target-specific env RUSTFLAGS if they're
14071406 // configured.
1408- let target_specific = format ! ( "CARGO_TARGET_{}_RUSTFLAGS" , crate :: envify( target) ) ;
1407+ let target_specific = format ! ( "CARGO_TARGET_{}_RUSTFLAGS" , crate :: envify( & target. triple ) ) ;
14091408 ret. env ( & target_specific) ;
14101409
14111410 ret
0 commit comments