@@ -65,10 +65,10 @@ impl Builder<'_> {
6565}
6666
6767#[ derive( Clone ) ]
68- struct ToolBuildResult {
69- tool_path : PathBuf ,
70- build_compiler : Compiler ,
71- target_compiler : Compiler ,
68+ pub struct ToolBuildResult {
69+ pub tool_path : PathBuf ,
70+ pub build_compiler : Compiler ,
71+ pub target_compiler : Compiler ,
7272}
7373
7474impl Step for ToolBuild {
@@ -114,10 +114,28 @@ impl Step for ToolBuild {
114114 self . source_type ,
115115 & self . extra_features ,
116116 ) ;
117+
118+ if path. ends_with ( "/rustdoc" ) &&
119+ // rustdoc is performance sensitive, so apply LTO to it.
120+ is_lto_stage ( & self . compiler )
121+ {
122+ let lto = match builder. config . rust_lto {
123+ RustcLto :: Off => Some ( "off" ) ,
124+ RustcLto :: Thin => Some ( "thin" ) ,
125+ RustcLto :: Fat => Some ( "fat" ) ,
126+ RustcLto :: ThinLocal => None ,
127+ } ;
128+ if let Some ( lto) = lto {
129+ cargo. env ( cargo_profile_var ( "LTO" , & builder. config ) , lto) ;
130+ }
131+ }
132+
117133 if !self . allow_features . is_empty ( ) {
118134 cargo. allow_features ( self . allow_features ) ;
119135 }
136+
120137 cargo. args ( self . cargo_args ) ;
138+
121139 let _guard = builder. msg_tool (
122140 Kind :: Build ,
123141 self . mode ,
@@ -163,9 +181,6 @@ pub fn prepare_tool_cargo(
163181 source_type : SourceType ,
164182 extra_features : & [ String ] ,
165183) -> CargoCommand {
166- let compiler =
167- if mode == Mode :: ToolRustc { get_tool_rustc_compiler ( builder, compiler) } else { compiler } ;
168-
169184 let mut cargo = builder:: Cargo :: new ( builder, compiler, mode, source_type, target, cmd_kind) ;
170185
171186 let dir = builder. src . join ( path) ;
@@ -667,80 +682,46 @@ impl Step for Rustdoc {
667682 }
668683 }
669684
670- let build_compiler = get_tool_rustc_compiler ( builder, target_compiler) ;
671-
672- // When using `download-rustc` and a stage0 build_compiler, copying rustc doesn't actually
673- // build stage0 libstd (because the libstd in sysroot has the wrong ABI). Explicitly build
674- // it.
675- builder. ensure ( compile:: Std :: new ( build_compiler, target_compiler. host ) ) ;
676- builder. ensure ( compile:: Rustc :: new ( build_compiler, target_compiler. host ) ) ;
677-
678685 // The presence of `target_compiler` ensures that the necessary libraries (codegen backends,
679686 // compiler libraries, ...) are built. Rustdoc does not require the presence of any
680687 // libraries within sysroot_libdir (i.e., rustlib), though doctests may want it (since
681688 // they'll be linked to those libraries). As such, don't explicitly `ensure` any additional
682689 // libraries here. The intuition here is that If we've built a compiler, we should be able
683690 // to build rustdoc.
684691 //
685- let mut features = Vec :: new ( ) ;
692+ let mut extra_features = Vec :: new ( ) ;
686693 if builder. config . jemalloc ( target) {
687- features . push ( "jemalloc" . to_string ( ) ) ;
694+ extra_features . push ( "jemalloc" . to_string ( ) ) ;
688695 }
689696
690- // NOTE: Never modify the rustflags here, it breaks the build cache for other tools!
691- let mut cargo = prepare_tool_cargo (
692- builder,
693- target_compiler,
694- Mode :: ToolRustc ,
695- target,
696- Kind :: Build ,
697- "src/tools/rustdoc" ,
698- SourceType :: InTree ,
699- features. as_slice ( ) ,
700- ) ;
701-
702- // rustdoc is performance sensitive, so apply LTO to it.
703- if is_lto_stage ( & build_compiler) {
704- let lto = match builder. config . rust_lto {
705- RustcLto :: Off => Some ( "off" ) ,
706- RustcLto :: Thin => Some ( "thin" ) ,
707- RustcLto :: Fat => Some ( "fat" ) ,
708- RustcLto :: ThinLocal => None ,
709- } ;
710- if let Some ( lto) = lto {
711- cargo. env ( cargo_profile_var ( "LTO" , & builder. config ) , lto) ;
712- }
713- }
714-
715- let _guard = builder. msg_tool (
716- Kind :: Build ,
717- Mode :: ToolRustc ,
718- "rustdoc" ,
719- build_compiler. stage ,
720- & self . compiler . host ,
721- & target,
722- ) ;
723- cargo. into_cmd ( ) . run ( builder) ;
724-
725- // Cargo adds a number of paths to the dylib search path on windows, which results in
726- // the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
727- // rustdoc a different name.
728- let tool_rustdoc = builder
729- . cargo_out ( build_compiler, Mode :: ToolRustc , target)
730- . join ( exe ( "rustdoc_tool_binary" , target_compiler. host ) ) ;
697+ let ToolBuildResult { tool_path, build_compiler : _build_compiler, target_compiler } =
698+ builder. ensure ( ToolBuild {
699+ compiler : target_compiler,
700+ target,
701+ // Cargo adds a number of paths to the dylib search path on windows, which results in
702+ // the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
703+ // rustdoc a different name.
704+ tool : "rustdoc_tool_binary" ,
705+ mode : Mode :: ToolRustc ,
706+ path : "src/tools/rustdoc" ,
707+ source_type : SourceType :: InTree ,
708+ extra_features,
709+ allow_features : "" ,
710+ cargo_args : Vec :: new ( ) ,
711+ } ) ;
731712
732713 // don't create a stage0-sysroot/bin directory.
733714 if target_compiler. stage > 0 {
734715 if builder. config . rust_debuginfo_level_tools == DebuginfoLevel :: None {
735716 // Due to LTO a lot of debug info from C++ dependencies such as jemalloc can make it into
736717 // our final binaries
737- compile:: strip_debug ( builder, target, & tool_rustdoc ) ;
718+ compile:: strip_debug ( builder, target, & tool_path ) ;
738719 }
739720 let bin_rustdoc = bin_rustdoc ( ) ;
740- builder. copy_link ( & tool_rustdoc , & bin_rustdoc) ;
721+ builder. copy_link ( & tool_path , & bin_rustdoc) ;
741722 bin_rustdoc
742723 } else {
743- tool_rustdoc
724+ tool_path
744725 }
745726 }
746727}
@@ -1084,7 +1065,7 @@ macro_rules! tool_extended {
10841065 }
10851066
10861067 impl Step for $name {
1087- type Output = PathBuf ;
1068+ type Output = ToolBuildResult ;
10881069 const DEFAULT : bool = true ; // Overridden by `should_run_tool_build_step`
10891070 const ONLY_HOSTS : bool = true ;
10901071
@@ -1104,7 +1085,7 @@ macro_rules! tool_extended {
11041085 } ) ;
11051086 }
11061087
1107- fn run( self , builder: & Builder <' _>) -> PathBuf {
1088+ fn run( self , builder: & Builder <' _>) -> ToolBuildResult {
11081089 let Self { compiler, target } = self ;
11091090 run_tool_build_step(
11101091 builder,
@@ -1150,9 +1131,9 @@ fn run_tool_build_step(
11501131 tool_name : & ' static str ,
11511132 path : & ' static str ,
11521133 add_bins_to_sysroot : Option < & [ & str ] > ,
1153- ) -> PathBuf {
1154- let ToolBuildResult { tool_path, build_compiler : _build_compiler , target_compiler } = builder
1155- . ensure ( ToolBuild {
1134+ ) -> ToolBuildResult {
1135+ let ToolBuildResult { tool_path, build_compiler, target_compiler } =
1136+ builder . ensure ( ToolBuild {
11561137 compiler,
11571138 target,
11581139 tool : tool_name,
@@ -1177,9 +1158,10 @@ fn run_tool_build_step(
11771158 }
11781159
11791160 // Return a path into the bin dir.
1180- bindir. join ( exe ( tool_name, target_compiler. host ) )
1161+ let path = bindir. join ( exe ( tool_name, target_compiler. host ) ) ;
1162+ ToolBuildResult { tool_path : path, build_compiler, target_compiler }
11811163 } else {
1182- tool_path
1164+ ToolBuildResult { tool_path, build_compiler , target_compiler }
11831165 }
11841166}
11851167
0 commit comments