@@ -28,7 +28,7 @@ use build_helper::up_to_date;
28
28
29
29
use util:: symlink_dir;
30
30
use builder:: { Builder , Compiler , RunConfig , ShouldRun , Step } ;
31
- use tool:: Tool ;
31
+ use tool:: { self , prepare_tool_cargo , Tool } ;
32
32
use compile;
33
33
use cache:: { INTERNER , Interned } ;
34
34
use config:: Config ;
@@ -70,7 +70,7 @@ macro_rules! book {
70
70
book ! (
71
71
Nomicon , "src/doc/nomicon" , "nomicon" ;
72
72
Reference , "src/doc/reference" , "reference" ;
73
- Rustdoc , "src/doc/rustdoc" , "rustdoc" ;
73
+ RustdocBook , "src/doc/rustdoc" , "rustdoc" ;
74
74
RustcBook , "src/doc/rustc" , "rustc" ;
75
75
RustByExample , "src/doc/rust-by-example" , "rust-by-example" ;
76
76
) ;
@@ -671,8 +671,12 @@ impl Step for Rustc {
671
671
let stage = self . stage ;
672
672
let target = self . target ;
673
673
builder. info ( & format ! ( "Documenting stage{} compiler ({})" , stage, target) ) ;
674
+
675
+ // This is the intended out directory for compiler documentation.
674
676
let out = builder. compiler_doc_out ( target) ;
675
677
t ! ( fs:: create_dir_all( & out) ) ;
678
+
679
+ // Get the correct compiler for this stage.
676
680
let compiler = builder. compiler ( stage, builder. config . build ) ;
677
681
let rustdoc = builder. rustdoc ( compiler. host ) ;
678
682
let compiler = if builder. force_use_stage1 ( compiler, target) {
@@ -682,21 +686,23 @@ impl Step for Rustc {
682
686
} ;
683
687
684
688
if !builder. config . compiler_docs {
685
- builder. info ( & format ! ( "\t skipping - compiler docs disabled" ) ) ;
689
+ builder. info ( & format ! ( "\t skipping - compiler/librustdoc docs disabled" ) ) ;
686
690
return ;
687
691
}
688
692
689
- // Build libstd docs so that we generate relative links
693
+ // Build libstd docs so that we generate relative links.
690
694
builder. ensure ( Std { stage, target } ) ;
691
695
696
+ // Build rustc.
692
697
builder. ensure ( compile:: Rustc { compiler, target } ) ;
693
- let out_dir = builder. stage_out ( compiler, Mode :: Librustc )
694
- . join ( target) . join ( "doc" ) ;
698
+
695
699
// We do not symlink to the same shared folder that already contains std library
696
700
// documentation from previous steps as we do not want to include that.
701
+ let out_dir = builder. stage_out ( compiler, Mode :: Librustc ) . join ( target) . join ( "doc" ) ;
697
702
builder. clear_if_dirty ( & out, & rustdoc) ;
698
703
t ! ( symlink_dir_force( & builder. config, & out, & out_dir) ) ;
699
704
705
+ // Build cargo command.
700
706
let mut cargo = builder. cargo ( compiler, Mode :: Librustc , target, "doc" ) ;
701
707
cargo. env ( "RUSTDOCFLAGS" , "--document-private-items" ) ;
702
708
compile:: rustc_cargo ( builder, & mut cargo) ;
@@ -735,6 +741,76 @@ fn find_compiler_crates(
735
741
}
736
742
}
737
743
744
+ #[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
745
+ pub struct Rustdoc {
746
+ stage : u32 ,
747
+ target : Interned < String > ,
748
+ }
749
+
750
+ impl Step for Rustdoc {
751
+ type Output = ( ) ;
752
+ const DEFAULT : bool = true ;
753
+ const ONLY_HOSTS : bool = true ;
754
+
755
+ fn should_run ( run : ShouldRun ) -> ShouldRun {
756
+ run. krate ( "rustdoc-tool" )
757
+ }
758
+
759
+ fn make_run ( run : RunConfig ) {
760
+ run. builder . ensure ( Rustdoc {
761
+ stage : run. builder . top_stage ,
762
+ target : run. target ,
763
+ } ) ;
764
+ }
765
+
766
+ /// Generate compiler documentation.
767
+ ///
768
+ /// This will generate all documentation for compiler and dependencies.
769
+ /// Compiler documentation is distributed separately, so we make sure
770
+ /// we do not merge it with the other documentation from std, test and
771
+ /// proc_macros. This is largely just a wrapper around `cargo doc`.
772
+ fn run ( self , builder : & Builder ) {
773
+ let stage = self . stage ;
774
+ let target = self . target ;
775
+ builder. info ( & format ! ( "Documenting stage{} rustdoc ({})" , stage, target) ) ;
776
+
777
+ // This is the intended out directory for compiler documentation.
778
+ let out = builder. compiler_doc_out ( target) ;
779
+ t ! ( fs:: create_dir_all( & out) ) ;
780
+
781
+ // Get the correct compiler for this stage.
782
+ let compiler = builder. compiler ( stage, builder. config . build ) ;
783
+ let rustdoc = builder. rustdoc ( compiler. host ) ;
784
+ let compiler = if builder. force_use_stage1 ( compiler, target) {
785
+ builder. compiler ( 1 , compiler. host )
786
+ } else {
787
+ compiler
788
+ } ;
789
+
790
+ if !builder. config . compiler_docs {
791
+ builder. info ( & format ! ( "\t skipping - compiler/librustdoc docs disabled" ) ) ;
792
+ return ;
793
+ }
794
+
795
+ // Build libstd docs so that we generate relative links.
796
+ builder. ensure ( Std { stage, target } ) ;
797
+
798
+ // Build rustdoc.
799
+ builder. ensure ( tool:: Rustdoc { host : compiler. host } ) ;
800
+
801
+ // Symlink compiler docs to the output directory of rustdoc documentation.
802
+ let out_dir = builder. stage_out ( compiler, Mode :: Tool ) . join ( target) . join ( "doc" ) ;
803
+ t ! ( fs:: create_dir_all( & out_dir) ) ;
804
+ builder. clear_if_dirty ( & out, & rustdoc) ;
805
+ t ! ( symlink_dir_force( & builder. config, & out, & out_dir) ) ;
806
+
807
+ // Build cargo command.
808
+ let mut cargo = prepare_tool_cargo ( builder, compiler, target, "doc" , "src/tools/rustdoc" ) ;
809
+ cargo. env ( "RUSTDOCFLAGS" , "--document-private-items" ) ;
810
+ builder. run ( & mut cargo) ;
811
+ }
812
+ }
813
+
738
814
#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
739
815
pub struct ErrorIndex {
740
816
target : Interned < String > ,
0 commit comments