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