@@ -88,7 +88,7 @@ impl Step for ToolBuild {
8888 //
8989 // Compiler tools should be linked in the same way as the compiler it's paired with,
9090 // so it must be built with the previous stage compiler.
91- self . compiler . stage -= 1
91+ self . compiler . stage -= 1 ;
9292 }
9393 Mode :: ToolStd => builder. ensure ( compile:: Std :: new ( self . compiler , self . target ) ) ,
9494 Mode :: ToolBootstrap => { }
@@ -105,9 +105,26 @@ impl Step for ToolBuild {
105105 self . source_type ,
106106 & self . extra_features ,
107107 ) ;
108+
108109 if !self . allow_features . is_empty ( ) {
109110 cargo. allow_features ( self . allow_features ) ;
110111 }
112+
113+ if self . path . ends_with ( "/rustdoc" ) &&
114+ // rustdoc is performance sensitive, so apply LTO to it.
115+ is_lto_stage ( & self . compiler )
116+ {
117+ let lto = match builder. config . rust_lto {
118+ RustcLto :: Off => Some ( "off" ) ,
119+ RustcLto :: Thin => Some ( "thin" ) ,
120+ RustcLto :: Fat => Some ( "fat" ) ,
121+ RustcLto :: ThinLocal => None ,
122+ } ;
123+ if let Some ( lto) = lto {
124+ cargo. env ( cargo_profile_var ( "LTO" , & builder. config ) , lto) ;
125+ }
126+ }
127+
111128 cargo. args ( self . cargo_args ) ;
112129 let _guard = builder. msg_tool (
113130 Kind :: Build ,
@@ -592,120 +609,74 @@ impl Step for Rustdoc {
592609 }
593610
594611 fn run ( self , builder : & Builder < ' _ > ) -> PathBuf {
595- let target_compiler = self . compiler ;
596- if target_compiler. stage == 0 {
597- if !target_compiler. is_snapshot ( builder) {
612+ let compiler = self . compiler ;
613+ let target = compiler. host ;
614+
615+ if compiler. stage == 0 {
616+ if !compiler. is_snapshot ( builder) {
598617 panic ! ( "rustdoc in stage 0 must be snapshot rustdoc" ) ;
599618 }
600619 return builder. initial_rustdoc . clone ( ) ;
601620 }
602- let target = target_compiler. host ;
603621
604622 let bin_rustdoc = || {
605- let sysroot = builder. sysroot ( target_compiler ) ;
623+ let sysroot = builder. sysroot ( compiler ) ;
606624 let bindir = sysroot. join ( "bin" ) ;
607625 t ! ( fs:: create_dir_all( & bindir) ) ;
608- let bin_rustdoc = bindir. join ( exe ( "rustdoc" , target_compiler . host ) ) ;
626+ let bin_rustdoc = bindir. join ( exe ( "rustdoc" , target ) ) ;
609627 let _ = fs:: remove_file ( & bin_rustdoc) ;
610628 bin_rustdoc
611629 } ;
612630
613631 // If CI rustc is enabled and we haven't modified the rustdoc sources,
614632 // use the precompiled rustdoc from CI rustc's sysroot to speed up bootstrapping.
615633 if builder. download_rustc ( )
616- && target_compiler . stage > 0
634+ && compiler . stage > 0
617635 && builder. rust_info ( ) . is_managed_git_subrepository ( )
618636 {
619637 let files_to_track = & [ "src/librustdoc" , "src/tools/rustdoc" ] ;
620638
621639 // Check if unchanged
622640 if builder. config . last_modified_commit ( files_to_track, "download-rustc" , true ) . is_some ( )
623641 {
624- let precompiled_rustdoc = builder
625- . config
626- . ci_rustc_dir ( )
627- . join ( "bin" )
628- . join ( exe ( "rustdoc" , target_compiler. host ) ) ;
642+ let precompiled_rustdoc =
643+ builder. config . ci_rustc_dir ( ) . join ( "bin" ) . join ( exe ( "rustdoc" , target) ) ;
629644
630645 let bin_rustdoc = bin_rustdoc ( ) ;
631646 builder. copy_link ( & precompiled_rustdoc, & bin_rustdoc) ;
632647 return bin_rustdoc;
633648 }
634649 }
635650
636- let build_compiler = if builder. download_rustc ( ) && target_compiler. stage == 1 {
637- // We already have the stage 1 compiler, we don't need to cut the stage.
638- builder. compiler ( target_compiler. stage , builder. config . build )
639- } else {
640- // Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
641- // we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
642- // compilers, which isn't what we want. Rustdoc should be linked in the same way as the
643- // rustc compiler it's paired with, so it must be built with the previous stage compiler.
644- builder. compiler ( target_compiler. stage - 1 , builder. config . build )
645- } ;
646-
647- // When using `download-rustc` and a stage0 build_compiler, copying rustc doesn't actually
648- // build stage0 libstd (because the libstd in sysroot has the wrong ABI). Explicitly build
649- // it.
650- builder. ensure ( compile:: Std :: new ( build_compiler, target_compiler. host ) ) ;
651- builder. ensure ( compile:: Rustc :: new ( build_compiler, target_compiler. host ) ) ;
652-
653651 // The presence of `target_compiler` ensures that the necessary libraries (codegen backends,
654652 // compiler libraries, ...) are built. Rustdoc does not require the presence of any
655653 // libraries within sysroot_libdir (i.e., rustlib), though doctests may want it (since
656654 // they'll be linked to those libraries). As such, don't explicitly `ensure` any additional
657655 // libraries here. The intuition here is that If we've built a compiler, we should be able
658656 // to build rustdoc.
659657 //
660- let mut features = Vec :: new ( ) ;
658+ let mut extra_features = Vec :: new ( ) ;
661659 if builder. config . jemalloc {
662- features . push ( "jemalloc" . to_string ( ) ) ;
660+ extra_features . push ( "jemalloc" . to_string ( ) ) ;
663661 }
664662
665- // NOTE: Never modify the rustflags here, it breaks the build cache for other tools!
666- let mut cargo = prepare_tool_cargo (
667- builder,
668- build_compiler,
669- Mode :: ToolRustc ,
663+ let tool_rustdoc = builder. ensure ( ToolBuild {
664+ compiler,
670665 target,
671- Kind :: Build ,
672- "src/tools/rustdoc" ,
673- SourceType :: InTree ,
674- features. as_slice ( ) ,
675- ) ;
676-
677- // rustdoc is performance sensitive, so apply LTO to it.
678- if is_lto_stage ( & build_compiler) {
679- let lto = match builder. config . rust_lto {
680- RustcLto :: Off => Some ( "off" ) ,
681- RustcLto :: Thin => Some ( "thin" ) ,
682- RustcLto :: Fat => Some ( "fat" ) ,
683- RustcLto :: ThinLocal => None ,
684- } ;
685- if let Some ( lto) = lto {
686- cargo. env ( cargo_profile_var ( "LTO" , & builder. config ) , lto) ;
687- }
688- }
689-
690- let _guard = builder. msg_tool (
691- Kind :: Build ,
692- Mode :: ToolRustc ,
693- "rustdoc" ,
694- build_compiler. stage ,
695- & self . compiler . host ,
696- & target,
697- ) ;
698- cargo. into_cmd ( ) . run ( builder) ;
699-
700666 // Cargo adds a number of paths to the dylib search path on windows, which results in
701667 // the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
702668 // rustdoc a different name.
703- let tool_rustdoc = builder
704- . cargo_out ( build_compiler, Mode :: ToolRustc , target)
705- . join ( exe ( "rustdoc_tool_binary" , target_compiler. host ) ) ;
669+ tool : "rustdoc_tool_binary" ,
670+ mode : Mode :: ToolRustc ,
671+ path : "src/tools/rustdoc" ,
672+ source_type : SourceType :: InTree ,
673+ extra_features,
674+ allow_features : "" ,
675+ cargo_args : Vec :: new ( ) ,
676+ } ) ;
706677
707678 // don't create a stage0-sysroot/bin directory.
708- if target_compiler . stage > 0 {
679+ if compiler . stage > 0 {
709680 if builder. config . rust_debuginfo_level_tools == DebuginfoLevel :: None {
710681 // Due to LTO a lot of debug info from C++ dependencies such as jemalloc can make it into
711682 // our final binaries
@@ -943,50 +914,29 @@ impl Step for LlvmBitcodeLinker {
943914 instrument( level = "debug" , name = "LlvmBitcodeLinker::run" , skip_all)
944915 ) ]
945916 fn run ( self , builder : & Builder < ' _ > ) -> PathBuf {
946- let bin_name = "llvm-bitcode-linker" ;
947-
948- // If enabled, use ci-rustc and skip building the in-tree compiler.
949- if !builder. download_rustc ( ) {
950- builder. ensure ( compile:: Std :: new ( self . compiler , self . compiler . host ) ) ;
951- builder. ensure ( compile:: Rustc :: new ( self . compiler , self . target ) ) ;
952- }
953-
954- let cargo = prepare_tool_cargo (
955- builder,
956- self . compiler ,
957- Mode :: ToolRustc ,
958- self . target ,
959- Kind :: Build ,
960- "src/tools/llvm-bitcode-linker" ,
961- SourceType :: InTree ,
962- & self . extra_features ,
963- ) ;
964-
965- let _guard = builder. msg_tool (
966- Kind :: Build ,
967- Mode :: ToolRustc ,
968- bin_name,
969- self . compiler . stage ,
970- & self . compiler . host ,
971- & self . target ,
972- ) ;
973-
974- cargo. into_cmd ( ) . run ( builder) ;
975-
976- let tool_out = builder
977- . cargo_out ( self . compiler , Mode :: ToolRustc , self . target )
978- . join ( exe ( bin_name, self . compiler . host ) ) ;
917+ let bin_source = builder. ensure ( ToolBuild {
918+ compiler : self . compiler ,
919+ target : self . target ,
920+ tool : "llvm-bitcode-linker" ,
921+ mode : Mode :: ToolRustc ,
922+ path : "src/tools/llvm-bitcode-linker" ,
923+ source_type : SourceType :: InTree ,
924+ extra_features : self . extra_features ,
925+ allow_features : "" ,
926+ cargo_args : Vec :: new ( ) ,
927+ } ) ;
979928
980929 if self . compiler . stage > 0 {
981930 let bindir_self_contained = builder
982931 . sysroot ( self . compiler )
983932 . join ( format ! ( "lib/rustlib/{}/bin/self-contained" , self . target. triple) ) ;
984933 t ! ( fs:: create_dir_all( & bindir_self_contained) ) ;
985- let bin_destination = bindir_self_contained. join ( exe ( bin_name, self . compiler . host ) ) ;
986- builder. copy_link ( & tool_out, & bin_destination) ;
934+ let bin_destination =
935+ bindir_self_contained. join ( exe ( "llvm-bitcode-linker" , self . compiler . host ) ) ;
936+ builder. copy_link ( & bin_source, & bin_destination) ;
987937 bin_destination
988938 } else {
989- tool_out
939+ bin_source
990940 }
991941 }
992942}
0 commit comments