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