@@ -4,8 +4,10 @@ use std::{env, fs};
44use crate :: core:: build_steps:: toolstate:: ToolState ;
55use crate :: core:: build_steps:: { compile, llvm} ;
66use crate :: core:: builder;
7- use crate :: core:: builder:: { Builder , Cargo as CargoCommand , RunConfig , ShouldRun , Step } ;
8- use crate :: core:: config:: { DebuginfoLevel , TargetSelection } ;
7+ use crate :: core:: builder:: {
8+ Builder , Cargo as CargoCommand , RunConfig , ShouldRun , Step , cargo_profile_var,
9+ } ;
10+ use crate :: core:: config:: { DebuginfoLevel , RustcLto , TargetSelection } ;
911use crate :: utils:: channel:: GitInfo ;
1012use crate :: utils:: exec:: { BootstrapCommand , command} ;
1113use crate :: utils:: helpers:: { add_dylib_path, exe, t} ;
@@ -645,7 +647,7 @@ impl Step for Rustdoc {
645647 }
646648
647649 // NOTE: Never modify the rustflags here, it breaks the build cache for other tools!
648- let cargo = prepare_tool_cargo (
650+ let mut cargo = prepare_tool_cargo (
649651 builder,
650652 build_compiler,
651653 Mode :: ToolRustc ,
@@ -656,6 +658,17 @@ impl Step for Rustdoc {
656658 features. as_slice ( ) ,
657659 ) ;
658660
661+ // rustdoc is performance sensitive, so apply LTO to it.
662+ let lto = match builder. config . rust_lto {
663+ RustcLto :: Off => Some ( "off" ) ,
664+ RustcLto :: Thin => Some ( "thin" ) ,
665+ RustcLto :: Fat => Some ( "fat" ) ,
666+ RustcLto :: ThinLocal => None ,
667+ } ;
668+ if let Some ( lto) = lto {
669+ cargo. env ( cargo_profile_var ( "LTO" , & builder. config ) , lto) ;
670+ }
671+
659672 let _guard = builder. msg_tool (
660673 Kind :: Build ,
661674 Mode :: ToolRustc ,
0 commit comments