@@ -65,10 +65,10 @@ impl Builder<'_> {
65
65
}
66
66
67
67
#[ 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 ,
72
72
}
73
73
74
74
impl Step for ToolBuild {
@@ -114,10 +114,28 @@ impl Step for ToolBuild {
114
114
self . source_type ,
115
115
& self . extra_features ,
116
116
) ;
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
+
117
133
if !self . allow_features . is_empty ( ) {
118
134
cargo. allow_features ( self . allow_features ) ;
119
135
}
136
+
120
137
cargo. args ( self . cargo_args ) ;
138
+
121
139
let _guard = builder. msg_tool (
122
140
Kind :: Build ,
123
141
self . mode ,
@@ -163,9 +181,6 @@ pub fn prepare_tool_cargo(
163
181
source_type : SourceType ,
164
182
extra_features : & [ String ] ,
165
183
) -> CargoCommand {
166
- let compiler =
167
- if mode == Mode :: ToolRustc { get_tool_rustc_compiler ( builder, compiler) } else { compiler } ;
168
-
169
184
let mut cargo = builder:: Cargo :: new ( builder, compiler, mode, source_type, target, cmd_kind) ;
170
185
171
186
let dir = builder. src . join ( path) ;
@@ -667,80 +682,46 @@ impl Step for Rustdoc {
667
682
}
668
683
}
669
684
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
-
678
685
// The presence of `target_compiler` ensures that the necessary libraries (codegen backends,
679
686
// compiler libraries, ...) are built. Rustdoc does not require the presence of any
680
687
// libraries within sysroot_libdir (i.e., rustlib), though doctests may want it (since
681
688
// they'll be linked to those libraries). As such, don't explicitly `ensure` any additional
682
689
// libraries here. The intuition here is that If we've built a compiler, we should be able
683
690
// to build rustdoc.
684
691
//
685
- let mut features = Vec :: new ( ) ;
692
+ let mut extra_features = Vec :: new ( ) ;
686
693
if builder. config . jemalloc {
687
- features . push ( "jemalloc" . to_string ( ) ) ;
694
+ extra_features . push ( "jemalloc" . to_string ( ) ) ;
688
695
}
689
696
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
+ } ) ;
731
712
732
713
// don't create a stage0-sysroot/bin directory.
733
714
if target_compiler. stage > 0 {
734
715
if builder. config . rust_debuginfo_level_tools == DebuginfoLevel :: None {
735
716
// Due to LTO a lot of debug info from C++ dependencies such as jemalloc can make it into
736
717
// our final binaries
737
- compile:: strip_debug ( builder, target, & tool_rustdoc ) ;
718
+ compile:: strip_debug ( builder, target, & tool_path ) ;
738
719
}
739
720
let bin_rustdoc = bin_rustdoc ( ) ;
740
- builder. copy_link ( & tool_rustdoc , & bin_rustdoc) ;
721
+ builder. copy_link ( & tool_path , & bin_rustdoc) ;
741
722
bin_rustdoc
742
723
} else {
743
- tool_rustdoc
724
+ tool_path
744
725
}
745
726
}
746
727
}
@@ -1084,7 +1065,7 @@ macro_rules! tool_extended {
1084
1065
}
1085
1066
1086
1067
impl Step for $name {
1087
- type Output = PathBuf ;
1068
+ type Output = ToolBuildResult ;
1088
1069
const DEFAULT : bool = true ; // Overridden by `should_run_tool_build_step`
1089
1070
const ONLY_HOSTS : bool = true ;
1090
1071
@@ -1104,7 +1085,7 @@ macro_rules! tool_extended {
1104
1085
} ) ;
1105
1086
}
1106
1087
1107
- fn run( self , builder: & Builder <' _>) -> PathBuf {
1088
+ fn run( self , builder: & Builder <' _>) -> ToolBuildResult {
1108
1089
let Self { compiler, target } = self ;
1109
1090
run_tool_build_step(
1110
1091
builder,
@@ -1150,9 +1131,9 @@ fn run_tool_build_step(
1150
1131
tool_name : & ' static str ,
1151
1132
path : & ' static str ,
1152
1133
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 {
1156
1137
compiler,
1157
1138
target,
1158
1139
tool : tool_name,
@@ -1177,9 +1158,10 @@ fn run_tool_build_step(
1177
1158
}
1178
1159
1179
1160
// 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 }
1181
1163
} else {
1182
- tool_path
1164
+ ToolBuildResult { tool_path, build_compiler , target_compiler }
1183
1165
}
1184
1166
}
1185
1167
0 commit comments