@@ -754,21 +754,31 @@ fn doc_std(
754
754
builder. cp_link_r ( & out_dir, out) ;
755
755
}
756
756
757
+ /// Prepare a compiler that will be able to document something for `target` at `stage`.
758
+ fn prepare_doc_compiler ( builder : & Builder < ' _ > , target : TargetSelection , stage : u32 ) -> Compiler {
759
+ let build_compiler = builder. compiler ( stage - 1 , builder. host_target ) ;
760
+ builder. std ( build_compiler, target) ;
761
+ build_compiler
762
+ }
763
+
764
+ /// Document the compiler for the given `target` using rustdoc from `build_compiler`.
757
765
#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
758
766
pub struct Rustc {
759
- pub stage : u32 ,
760
- pub target : TargetSelection ,
767
+ build_compiler : Compiler ,
768
+ target : TargetSelection ,
761
769
crates : Vec < String > ,
762
770
}
763
771
764
772
impl Rustc {
765
- pub ( crate ) fn new ( stage : u32 , target : TargetSelection , builder : & Builder < ' _ > ) -> Self {
773
+ /// Document `stage` compiler for the given `target`.
774
+ pub ( crate ) fn for_stage ( builder : & Builder < ' _ > , target : TargetSelection , stage : u32 ) -> Self {
766
775
let crates = builder
767
776
. in_tree_crates ( "rustc-main" , Some ( target) )
768
777
. into_iter ( )
769
778
. map ( |krate| krate. name . to_string ( ) )
770
779
. collect ( ) ;
771
- Self { stage, target, crates }
780
+ let build_compiler = prepare_doc_compiler ( builder, target, stage) ;
781
+ Self { build_compiler, target, crates }
772
782
}
773
783
}
774
784
@@ -785,11 +795,7 @@ impl Step for Rustc {
785
795
}
786
796
787
797
fn make_run ( run : RunConfig < ' _ > ) {
788
- run. builder . ensure ( Rustc {
789
- stage : run. builder . top_stage ,
790
- target : run. target ,
791
- crates : run. make_run_crates ( Alias :: Compiler ) ,
792
- } ) ;
798
+ run. builder . ensure ( Rustc :: for_stage ( run. builder , run. target , run. builder . top_stage ) ) ;
793
799
}
794
800
795
801
/// Generates compiler documentation.
@@ -799,7 +805,6 @@ impl Step for Rustc {
799
805
/// we do not merge it with the other documentation from std, test and
800
806
/// proc_macros. This is largely just a wrapper around `cargo doc`.
801
807
fn run ( self , builder : & Builder < ' _ > ) {
802
- let stage = self . stage ;
803
808
let target = self . target ;
804
809
805
810
// This is the intended out directory for compiler documentation.
@@ -808,21 +813,21 @@ impl Step for Rustc {
808
813
809
814
// Build the standard library, so that proc-macros can use it.
810
815
// (Normally, only the metadata would be necessary, but proc-macros are special since they run at compile-time.)
811
- let compiler = builder . compiler ( stage , builder . config . host_target ) ;
812
- builder. std ( compiler , builder. config . host_target ) ;
816
+ let build_compiler = self . build_compiler ;
817
+ builder. std ( build_compiler , builder. config . host_target ) ;
813
818
814
819
let _guard = builder. msg_rustc_tool (
815
820
Kind :: Doc ,
816
- stage,
821
+ build_compiler . stage ,
817
822
format ! ( "compiler{}" , crate_description( & self . crates) ) ,
818
- compiler . host ,
823
+ build_compiler . host ,
819
824
target,
820
825
) ;
821
826
822
827
// Build cargo command.
823
828
let mut cargo = builder:: Cargo :: new (
824
829
builder,
825
- compiler ,
830
+ build_compiler ,
826
831
Mode :: Rustc ,
827
832
SourceType :: InTree ,
828
833
target,
@@ -840,7 +845,7 @@ impl Step for Rustc {
840
845
// If there is any bug, please comment out the next line.
841
846
cargo. rustdocflag ( "--generate-link-to-definition" ) ;
842
847
843
- compile:: rustc_cargo ( builder, & mut cargo, target, & compiler , & self . crates ) ;
848
+ compile:: rustc_cargo ( builder, & mut cargo, target, & build_compiler , & self . crates ) ;
844
849
cargo. arg ( "-Zskip-rustdoc-fingerprint" ) ;
845
850
846
851
// Only include compiler crates, no dependencies of those, such as `libc`.
@@ -855,7 +860,7 @@ impl Step for Rustc {
855
860
856
861
let mut to_open = None ;
857
862
858
- let out_dir = builder. stage_out ( compiler , Mode :: Rustc ) . join ( target) . join ( "doc" ) ;
863
+ let out_dir = builder. stage_out ( build_compiler , Mode :: Rustc ) . join ( target) . join ( "doc" ) ;
859
864
for krate in & * self . crates {
860
865
// Create all crate output directories first to make sure rustdoc uses
861
866
// relative links.
@@ -877,7 +882,7 @@ impl Step for Rustc {
877
882
symlink_dir_force ( & builder. config , & out, & out_dir) ;
878
883
// Cargo puts proc macros in `target/doc` even if you pass `--target`
879
884
// explicitly (https://github.com/rust-lang/cargo/issues/7677).
880
- let proc_macro_out_dir = builder. stage_out ( compiler , Mode :: Rustc ) . join ( "doc" ) ;
885
+ let proc_macro_out_dir = builder. stage_out ( build_compiler , Mode :: Rustc ) . join ( "doc" ) ;
881
886
symlink_dir_force ( & builder. config , & out, & proc_macro_out_dir) ;
882
887
883
888
cargo. into_cmd ( ) . run ( builder) ;
@@ -903,7 +908,7 @@ impl Step for Rustc {
903
908
}
904
909
905
910
fn metadata ( & self ) -> Option < StepMetadata > {
906
- Some ( StepMetadata :: doc ( "rustc" , self . target ) . stage ( self . stage ) )
911
+ Some ( StepMetadata :: doc ( "rustc" , self . target ) . built_by ( self . build_compiler ) )
907
912
}
908
913
}
909
914
0 commit comments