@@ -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
@@ -745,7 +742,7 @@ impl<'a> Builder<'a> {
745742 ///
746743 /// Note that this returns `None` if LLVM is disabled, or if we're in a
747744 /// check build or dry-run, where there's no need to build all of LLVM.
748- fn llvm_config ( & self , target : Interned < String > ) -> Option < PathBuf > {
745+ fn llvm_config ( & self , target : TargetSelection ) -> Option < PathBuf > {
749746 if self . config . llvm_enabled ( ) && self . kind != Kind :: Check && !self . config . dry_run {
750747 let llvm_config = self . ensure ( native:: Llvm { target } ) ;
751748 if llvm_config. is_file ( ) {
@@ -767,7 +764,7 @@ impl<'a> Builder<'a> {
767764 compiler : Compiler ,
768765 mode : Mode ,
769766 source_type : SourceType ,
770- target : Interned < String > ,
767+ target : TargetSelection ,
771768 cmd : & str ,
772769 ) -> Cargo {
773770 let mut cargo = Command :: new ( & self . initial_cargo ) ;
@@ -777,7 +774,7 @@ impl<'a> Builder<'a> {
777774 let my_out = match mode {
778775 // This is the intended out directory for compiler documentation.
779776 Mode :: Rustc | Mode :: ToolRustc | Mode :: Codegen => self . compiler_doc_out ( target) ,
780- Mode :: Std => out_dir. join ( target) . join ( "doc" ) ,
777+ Mode :: Std => out_dir. join ( target. triple ) . join ( "doc" ) ,
781778 _ => panic ! ( "doc mode {:?} not expected" , mode) ,
782779 } ;
783780 let rustdoc = self . rustdoc ( compiler) ;
@@ -799,7 +796,7 @@ impl<'a> Builder<'a> {
799796 }
800797
801798 if cmd != "install" {
802- cargo. arg ( "--target" ) . arg ( target) ;
799+ cargo. arg ( "--target" ) . arg ( target. rustc_target_arg ( ) ) ;
803800 } else {
804801 assert_eq ! ( target, compiler. host) ;
805802 }
@@ -825,7 +822,7 @@ impl<'a> Builder<'a> {
825822 compiler. stage
826823 } ;
827824
828- let mut rustflags = Rustflags :: new ( & target) ;
825+ let mut rustflags = Rustflags :: new ( target) ;
829826 if stage != 0 {
830827 if let Ok ( s) = env:: var ( "CARGOFLAGS_NOT_BOOTSTRAP" ) {
831828 cargo. args ( s. split_whitespace ( ) ) ;
@@ -998,7 +995,7 @@ impl<'a> Builder<'a> {
998995 // argument manually via `-C link-args=-Wl,-rpath,...`. Plus isn't it
999996 // fun to pass a flag to a tool to pass a flag to pass a flag to a tool
1000997 // to change a flag in a binary?
1001- if self . config . rust_rpath && util:: use_host_linker ( & target) {
998+ if self . config . rust_rpath && util:: use_host_linker ( target) {
1002999 let rpath = if target. contains ( "apple" ) {
10031000 // Note that we need to take one extra step on macOS to also pass
10041001 // `-Wl,-instal_name,@rpath/...` to get things to work right. To
@@ -1026,7 +1023,7 @@ impl<'a> Builder<'a> {
10261023 }
10271024
10281025 if let Some ( target_linker) = self . linker ( target, can_use_lld) {
1029- let target = crate :: envify ( & target) ;
1026+ let target = crate :: envify ( & target. triple ) ;
10301027 cargo. env ( & format ! ( "CARGO_TARGET_{}_LINKER" , target) , target_linker) ;
10311028 }
10321029 if !( [ "build" , "check" , "clippy" , "fix" , "rustc" ] . contains ( & cmd) ) && want_rustdoc {
@@ -1200,21 +1197,23 @@ impl<'a> Builder<'a> {
12001197 }
12011198 } ;
12021199 let cc = ccacheify ( & self . cc ( target) ) ;
1203- cargo. env ( format ! ( "CC_{}" , target) , & cc) ;
1200+ cargo. env ( format ! ( "CC_{}" , target. triple ) , & cc) ;
12041201
12051202 let cflags = self . cflags ( target, GitRepo :: Rustc ) . join ( " " ) ;
1206- cargo. env ( format ! ( "CFLAGS_{}" , target) , cflags. clone ( ) ) ;
1203+ cargo. env ( format ! ( "CFLAGS_{}" , target. triple ) , cflags. clone ( ) ) ;
12071204
12081205 if let Some ( ar) = self . ar ( target) {
12091206 let ranlib = format ! ( "{} s" , ar. display( ) ) ;
1210- cargo. env ( format ! ( "AR_{}" , target) , ar) . env ( format ! ( "RANLIB_{}" , target) , ranlib) ;
1207+ cargo
1208+ . env ( format ! ( "AR_{}" , target. triple) , ar)
1209+ . env ( format ! ( "RANLIB_{}" , target. triple) , ranlib) ;
12111210 }
12121211
12131212 if let Ok ( cxx) = self . cxx ( target) {
12141213 let cxx = ccacheify ( & cxx) ;
12151214 cargo
1216- . env ( format ! ( "CXX_{}" , target) , & cxx)
1217- . env ( format ! ( "CXXFLAGS_{}" , target) , cflags) ;
1215+ . env ( format ! ( "CXX_{}" , target. triple ) , & cxx)
1216+ . env ( format ! ( "CXXFLAGS_{}" , target. triple ) , cflags) ;
12181217 }
12191218 }
12201219
@@ -1248,7 +1247,7 @@ impl<'a> Builder<'a> {
12481247 // Environment variables *required* throughout the build
12491248 //
12501249 // FIXME: should update code to not require this env var
1251- cargo. env ( "CFG_COMPILER_HOST_TRIPLE" , target) ;
1250+ cargo. env ( "CFG_COMPILER_HOST_TRIPLE" , target. triple ) ;
12521251
12531252 // Set this for all builds to make sure doc builds also get it.
12541253 cargo. env ( "CFG_RELEASE_CHANNEL" , & self . config . channel ) ;
@@ -1404,15 +1403,15 @@ mod tests;
14041403struct Rustflags ( String ) ;
14051404
14061405impl Rustflags {
1407- fn new ( target : & str ) -> Rustflags {
1406+ fn new ( target : TargetSelection ) -> Rustflags {
14081407 let mut ret = Rustflags ( String :: new ( ) ) ;
14091408
14101409 // Inherit `RUSTFLAGS` by default ...
14111410 ret. env ( "RUSTFLAGS" ) ;
14121411
14131412 // ... and also handle target-specific env RUSTFLAGS if they're
14141413 // configured.
1415- let target_specific = format ! ( "CARGO_TARGET_{}_RUSTFLAGS" , crate :: envify( target) ) ;
1414+ let target_specific = format ! ( "CARGO_TARGET_{}_RUSTFLAGS" , crate :: envify( & target. triple ) ) ;
14161415 ret. env ( & target_specific) ;
14171416
14181417 ret
0 commit comments