@@ -88,7 +88,7 @@ impl Step for ToolBuild {
88
88
//
89
89
// Compiler tools should be linked in the same way as the compiler it's paired with,
90
90
// so it must be built with the previous stage compiler.
91
- self . compiler . stage -= 1
91
+ self . compiler . stage -= 1 ;
92
92
}
93
93
Mode :: ToolStd => builder. ensure ( compile:: Std :: new ( self . compiler , self . target ) ) ,
94
94
Mode :: ToolBootstrap => { }
@@ -105,9 +105,26 @@ impl Step for ToolBuild {
105
105
self . source_type ,
106
106
& self . extra_features ,
107
107
) ;
108
+
108
109
if !self . allow_features . is_empty ( ) {
109
110
cargo. allow_features ( self . allow_features ) ;
110
111
}
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
+
111
128
cargo. args ( self . cargo_args ) ;
112
129
let _guard = builder. msg_tool (
113
130
Kind :: Build ,
@@ -592,120 +609,74 @@ impl Step for Rustdoc {
592
609
}
593
610
594
611
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) {
598
617
panic ! ( "rustdoc in stage 0 must be snapshot rustdoc" ) ;
599
618
}
600
619
return builder. initial_rustdoc . clone ( ) ;
601
620
}
602
- let target = target_compiler. host ;
603
621
604
622
let bin_rustdoc = || {
605
- let sysroot = builder. sysroot ( target_compiler ) ;
623
+ let sysroot = builder. sysroot ( compiler ) ;
606
624
let bindir = sysroot. join ( "bin" ) ;
607
625
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 ) ) ;
609
627
let _ = fs:: remove_file ( & bin_rustdoc) ;
610
628
bin_rustdoc
611
629
} ;
612
630
613
631
// If CI rustc is enabled and we haven't modified the rustdoc sources,
614
632
// use the precompiled rustdoc from CI rustc's sysroot to speed up bootstrapping.
615
633
if builder. download_rustc ( )
616
- && target_compiler . stage > 0
634
+ && compiler . stage > 0
617
635
&& builder. rust_info ( ) . is_managed_git_subrepository ( )
618
636
{
619
637
let files_to_track = & [ "src/librustdoc" , "src/tools/rustdoc" ] ;
620
638
621
639
// Check if unchanged
622
640
if builder. config . last_modified_commit ( files_to_track, "download-rustc" , true ) . is_some ( )
623
641
{
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) ) ;
629
644
630
645
let bin_rustdoc = bin_rustdoc ( ) ;
631
646
builder. copy_link ( & precompiled_rustdoc, & bin_rustdoc) ;
632
647
return bin_rustdoc;
633
648
}
634
649
}
635
650
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
-
653
651
// The presence of `target_compiler` ensures that the necessary libraries (codegen backends,
654
652
// compiler libraries, ...) are built. Rustdoc does not require the presence of any
655
653
// libraries within sysroot_libdir (i.e., rustlib), though doctests may want it (since
656
654
// they'll be linked to those libraries). As such, don't explicitly `ensure` any additional
657
655
// libraries here. The intuition here is that If we've built a compiler, we should be able
658
656
// to build rustdoc.
659
657
//
660
- let mut features = Vec :: new ( ) ;
658
+ let mut extra_features = Vec :: new ( ) ;
661
659
if builder. config . jemalloc {
662
- features . push ( "jemalloc" . to_string ( ) ) ;
660
+ extra_features . push ( "jemalloc" . to_string ( ) ) ;
663
661
}
664
662
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,
670
665
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
-
700
666
// Cargo adds a number of paths to the dylib search path on windows, which results in
701
667
// the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
702
668
// 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
+ } ) ;
706
677
707
678
// don't create a stage0-sysroot/bin directory.
708
- if target_compiler . stage > 0 {
679
+ if compiler . stage > 0 {
709
680
if builder. config . rust_debuginfo_level_tools == DebuginfoLevel :: None {
710
681
// Due to LTO a lot of debug info from C++ dependencies such as jemalloc can make it into
711
682
// our final binaries
@@ -943,50 +914,29 @@ impl Step for LlvmBitcodeLinker {
943
914
instrument( level = "debug" , name = "LlvmBitcodeLinker::run" , skip_all)
944
915
) ]
945
916
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
+ } ) ;
979
928
980
929
if self . compiler . stage > 0 {
981
930
let bindir_self_contained = builder
982
931
. sysroot ( self . compiler )
983
932
. join ( format ! ( "lib/rustlib/{}/bin/self-contained" , self . target. triple) ) ;
984
933
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) ;
987
937
bin_destination
988
938
} else {
989
- tool_out
939
+ bin_source
990
940
}
991
941
}
992
942
}
0 commit comments