@@ -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
@@ -725,7 +722,11 @@ impl<'a> Builder<'a> {
725722 . env ( "CFG_RELEASE_CHANNEL" , & self . config . channel )
726723 . env ( "RUSTDOC_REAL" , self . rustdoc ( compiler) )
727724 . env ( "RUSTDOC_CRATE_VERSION" , self . rust_version ( ) )
728- . env ( "RUSTC_BOOTSTRAP" , "1" ) ;
725+ . env ( "RUSTC_BOOTSTRAP" , "1" )
726+ . arg ( "-Winvalid_codeblock_attributes" ) ;
727+ if self . config . deny_warnings {
728+ cmd. arg ( "-Dwarnings" ) ;
729+ }
729730
730731 // Remove make-related flags that can cause jobserver problems.
731732 cmd. env_remove ( "MAKEFLAGS" ) ;
@@ -741,7 +742,7 @@ impl<'a> Builder<'a> {
741742 ///
742743 /// Note that this returns `None` if LLVM is disabled, or if we're in a
743744 /// 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 > {
745+ fn llvm_config ( & self , target : TargetSelection ) -> Option < PathBuf > {
745746 if self . config . llvm_enabled ( ) && self . kind != Kind :: Check && !self . config . dry_run {
746747 let llvm_config = self . ensure ( native:: Llvm { target } ) ;
747748 if llvm_config. is_file ( ) {
@@ -763,7 +764,7 @@ impl<'a> Builder<'a> {
763764 compiler : Compiler ,
764765 mode : Mode ,
765766 source_type : SourceType ,
766- target : Interned < String > ,
767+ target : TargetSelection ,
767768 cmd : & str ,
768769 ) -> Cargo {
769770 let mut cargo = Command :: new ( & self . initial_cargo ) ;
@@ -773,7 +774,7 @@ impl<'a> Builder<'a> {
773774 let my_out = match mode {
774775 // This is the intended out directory for compiler documentation.
775776 Mode :: Rustc | Mode :: ToolRustc | Mode :: Codegen => self . compiler_doc_out ( target) ,
776- Mode :: Std => out_dir. join ( target) . join ( "doc" ) ,
777+ Mode :: Std => out_dir. join ( target. triple ) . join ( "doc" ) ,
777778 _ => panic ! ( "doc mode {:?} not expected" , mode) ,
778779 } ;
779780 let rustdoc = self . rustdoc ( compiler) ;
@@ -795,7 +796,7 @@ impl<'a> Builder<'a> {
795796 }
796797
797798 if cmd != "install" {
798- cargo. arg ( "--target" ) . arg ( target) ;
799+ cargo. arg ( "--target" ) . arg ( target. rustc_target_arg ( ) ) ;
799800 } else {
800801 assert_eq ! ( target, compiler. host) ;
801802 }
@@ -821,7 +822,7 @@ impl<'a> Builder<'a> {
821822 compiler. stage
822823 } ;
823824
824- let mut rustflags = Rustflags :: new ( & target) ;
825+ let mut rustflags = Rustflags :: new ( target) ;
825826 if stage != 0 {
826827 if let Ok ( s) = env:: var ( "CARGOFLAGS_NOT_BOOTSTRAP" ) {
827828 cargo. args ( s. split_whitespace ( ) ) ;
@@ -838,7 +839,7 @@ impl<'a> Builder<'a> {
838839 // FIXME: It might be better to use the same value for both `RUSTFLAGS` and `RUSTDOCFLAGS`,
839840 // but this breaks CI. At the very least, stage0 `rustdoc` needs `--cfg bootstrap`. See
840841 // #71458.
841- let rustdocflags = rustflags. clone ( ) ;
842+ let mut rustdocflags = rustflags. clone ( ) ;
842843
843844 if let Ok ( s) = env:: var ( "CARGOFLAGS" ) {
844845 cargo. args ( s. split_whitespace ( ) ) ;
@@ -994,7 +995,7 @@ impl<'a> Builder<'a> {
994995 // argument manually via `-C link-args=-Wl,-rpath,...`. Plus isn't it
995996 // fun to pass a flag to a tool to pass a flag to pass a flag to a tool
996997 // to change a flag in a binary?
997- if self . config . rust_rpath && util:: use_host_linker ( & target) {
998+ if self . config . rust_rpath && util:: use_host_linker ( target) {
998999 let rpath = if target. contains ( "apple" ) {
9991000 // Note that we need to take one extra step on macOS to also pass
10001001 // `-Wl,-instal_name,@rpath/...` to get things to work right. To
@@ -1022,7 +1023,7 @@ impl<'a> Builder<'a> {
10221023 }
10231024
10241025 if let Some ( target_linker) = self . linker ( target, can_use_lld) {
1025- let target = crate :: envify ( & target) ;
1026+ let target = crate :: envify ( & target. triple ) ;
10261027 cargo. env ( & format ! ( "CARGO_TARGET_{}_LINKER" , target) , target_linker) ;
10271028 }
10281029 if !( [ "build" , "check" , "clippy" , "fix" , "rustc" ] . contains ( & cmd) ) && want_rustdoc {
@@ -1140,6 +1141,7 @@ impl<'a> Builder<'a> {
11401141
11411142 if self . config . deny_warnings {
11421143 lint_flags. push ( "-Dwarnings" ) ;
1144+ rustdocflags. arg ( "-Dwarnings" ) ;
11431145 }
11441146
11451147 // FIXME(#58633) hide "unused attribute" errors in incremental
@@ -1157,6 +1159,8 @@ impl<'a> Builder<'a> {
11571159 // are always ignored in dependencies. Eventually this should be
11581160 // fixed via better support from Cargo.
11591161 cargo. env ( "RUSTC_LINT_FLAGS" , lint_flags. join ( " " ) ) ;
1162+
1163+ rustdocflags. arg ( "-Winvalid_codeblock_attributes" ) ;
11601164 }
11611165
11621166 if let Mode :: Rustc | Mode :: Codegen = mode {
@@ -1193,21 +1197,23 @@ impl<'a> Builder<'a> {
11931197 }
11941198 } ;
11951199 let cc = ccacheify ( & self . cc ( target) ) ;
1196- cargo. env ( format ! ( "CC_{}" , target) , & cc) ;
1200+ cargo. env ( format ! ( "CC_{}" , target. triple ) , & cc) ;
11971201
11981202 let cflags = self . cflags ( target, GitRepo :: Rustc ) . join ( " " ) ;
1199- cargo. env ( format ! ( "CFLAGS_{}" , target) , cflags. clone ( ) ) ;
1203+ cargo. env ( format ! ( "CFLAGS_{}" , target. triple ) , cflags. clone ( ) ) ;
12001204
12011205 if let Some ( ar) = self . ar ( target) {
12021206 let ranlib = format ! ( "{} s" , ar. display( ) ) ;
1203- 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) ;
12041210 }
12051211
12061212 if let Ok ( cxx) = self . cxx ( target) {
12071213 let cxx = ccacheify ( & cxx) ;
12081214 cargo
1209- . env ( format ! ( "CXX_{}" , target) , & cxx)
1210- . env ( format ! ( "CXXFLAGS_{}" , target) , cflags) ;
1215+ . env ( format ! ( "CXX_{}" , target. triple ) , & cxx)
1216+ . env ( format ! ( "CXXFLAGS_{}" , target. triple ) , cflags) ;
12111217 }
12121218 }
12131219
@@ -1241,7 +1247,7 @@ impl<'a> Builder<'a> {
12411247 // Environment variables *required* throughout the build
12421248 //
12431249 // FIXME: should update code to not require this env var
1244- cargo. env ( "CFG_COMPILER_HOST_TRIPLE" , target) ;
1250+ cargo. env ( "CFG_COMPILER_HOST_TRIPLE" , target. triple ) ;
12451251
12461252 // Set this for all builds to make sure doc builds also get it.
12471253 cargo. env ( "CFG_RELEASE_CHANNEL" , & self . config . channel ) ;
@@ -1397,15 +1403,15 @@ mod tests;
13971403struct Rustflags ( String ) ;
13981404
13991405impl Rustflags {
1400- fn new ( target : & str ) -> Rustflags {
1406+ fn new ( target : TargetSelection ) -> Rustflags {
14011407 let mut ret = Rustflags ( String :: new ( ) ) ;
14021408
14031409 // Inherit `RUSTFLAGS` by default ...
14041410 ret. env ( "RUSTFLAGS" ) ;
14051411
14061412 // ... and also handle target-specific env RUSTFLAGS if they're
14071413 // configured.
1408- let target_specific = format ! ( "CARGO_TARGET_{}_RUSTFLAGS" , crate :: envify( target) ) ;
1414+ let target_specific = format ! ( "CARGO_TARGET_{}_RUSTFLAGS" , crate :: envify( & target. triple ) ) ;
14091415 ret. env ( & target_specific) ;
14101416
14111417 ret
0 commit comments