@@ -4,8 +4,10 @@ use std::{env, fs};
4
4
use crate :: core:: build_steps:: toolstate:: ToolState ;
5
5
use crate :: core:: build_steps:: { compile, llvm} ;
6
6
use 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 } ;
9
11
use crate :: utils:: channel:: GitInfo ;
10
12
use crate :: utils:: exec:: { BootstrapCommand , command} ;
11
13
use crate :: utils:: helpers:: { add_dylib_path, exe, t} ;
@@ -645,7 +647,7 @@ impl Step for Rustdoc {
645
647
}
646
648
647
649
// 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 (
649
651
builder,
650
652
build_compiler,
651
653
Mode :: ToolRustc ,
@@ -656,6 +658,17 @@ impl Step for Rustdoc {
656
658
features. as_slice ( ) ,
657
659
) ;
658
660
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
+
659
672
let _guard = builder. msg_tool (
660
673
Kind :: Build ,
661
674
Mode :: ToolRustc ,
0 commit comments