@@ -28,7 +28,7 @@ use build_helper::up_to_date;
2828
2929use util:: symlink_dir;
3030use builder:: { Builder , Compiler , RunConfig , ShouldRun , Step } ;
31- use tool:: Tool ;
31+ use tool:: { self , prepare_tool_cargo , Tool } ;
3232use compile;
3333use cache:: { INTERNER , Interned } ;
3434use config:: Config ;
@@ -70,7 +70,7 @@ macro_rules! book {
7070book ! (
7171 Nomicon , "src/doc/nomicon" , "nomicon" ;
7272 Reference , "src/doc/reference" , "reference" ;
73- Rustdoc , "src/doc/rustdoc" , "rustdoc" ;
73+ RustdocBook , "src/doc/rustdoc" , "rustdoc" ;
7474 RustcBook , "src/doc/rustc" , "rustc" ;
7575 RustByExample , "src/doc/rust-by-example" , "rust-by-example" ;
7676) ;
@@ -671,8 +671,12 @@ impl Step for Rustc {
671671 let stage = self . stage ;
672672 let target = self . target ;
673673 builder. info ( & format ! ( "Documenting stage{} compiler ({})" , stage, target) ) ;
674+
675+ // This is the intended out directory for compiler documentation.
674676 let out = builder. compiler_doc_out ( target) ;
675677 t ! ( fs:: create_dir_all( & out) ) ;
678+
679+ // Get the correct compiler for this stage.
676680 let compiler = builder. compiler ( stage, builder. config . build ) ;
677681 let rustdoc = builder. rustdoc ( compiler. host ) ;
678682 let compiler = if builder. force_use_stage1 ( compiler, target) {
@@ -682,21 +686,23 @@ impl Step for Rustc {
682686 } ;
683687
684688 if !builder. config . compiler_docs {
685- builder. info ( & format ! ( "\t skipping - compiler docs disabled" ) ) ;
689+ builder. info ( & format ! ( "\t skipping - compiler/librustdoc docs disabled" ) ) ;
686690 return ;
687691 }
688692
689- // Build libstd docs so that we generate relative links
693+ // Build libstd docs so that we generate relative links.
690694 builder. ensure ( Std { stage, target } ) ;
691695
696+ // Build rustc.
692697 builder. ensure ( compile:: Rustc { compiler, target } ) ;
693- let out_dir = builder. stage_out ( compiler, Mode :: Librustc )
694- . join ( target) . join ( "doc" ) ;
698+
695699 // We do not symlink to the same shared folder that already contains std library
696700 // 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" ) ;
697702 builder. clear_if_dirty ( & out, & rustdoc) ;
698703 t ! ( symlink_dir_force( & builder. config, & out, & out_dir) ) ;
699704
705+ // Build cargo command.
700706 let mut cargo = builder. cargo ( compiler, Mode :: Librustc , target, "doc" ) ;
701707 cargo. env ( "RUSTDOCFLAGS" , "--document-private-items" ) ;
702708 compile:: rustc_cargo ( builder, & mut cargo) ;
@@ -735,6 +741,76 @@ fn find_compiler_crates(
735741 }
736742}
737743
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+
738814#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
739815pub struct ErrorIndex {
740816 target : Interned < String > ,
0 commit comments