@@ -483,21 +483,17 @@ impl Step for Std {
483483 let mut cargo = builder. cargo ( compiler, Mode :: Libstd , target, "doc" ) ;
484484 compile:: std_cargo ( builder, & compiler, target, & mut cargo) ;
485485
486- // We don't want to build docs for internal std dependencies unless
487- // in compiler-docs mode. When not in that mode, we whitelist the crates
488- // for which docs must be built.
489- if !build. config . compiler_docs {
490- cargo. arg ( "--no-deps" ) ;
491- for krate in & [ "alloc" , "core" , "std" , "std_unicode" ] {
492- cargo. arg ( "-p" ) . arg ( krate) ;
493- // Create all crate output directories first to make sure rustdoc uses
494- // relative links.
495- // FIXME: Cargo should probably do this itself.
496- t ! ( fs:: create_dir_all( out_dir. join( krate) ) ) ;
497- }
486+ // Keep a whitelist so we do not build internal stdlib crates, these will be
487+ // build by the rustc step later if enabled.
488+ cargo. arg ( "--no-deps" ) ;
489+ for krate in & [ "alloc" , "core" , "std" , "std_unicode" ] {
490+ cargo. arg ( "-p" ) . arg ( krate) ;
491+ // Create all crate output directories first to make sure rustdoc uses
492+ // relative links.
493+ // FIXME: Cargo should probably do this itself.
494+ t ! ( fs:: create_dir_all( out_dir. join( krate) ) ) ;
498495 }
499496
500-
501497 build. run ( & mut cargo) ;
502498 cp_r ( & my_out, & out) ;
503499 }
@@ -563,6 +559,81 @@ impl Step for Test {
563559 }
564560}
565561
562+ #[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
563+ pub struct WhitelistedRustc {
564+ stage : u32 ,
565+ target : Interned < String > ,
566+ }
567+
568+ impl Step for WhitelistedRustc {
569+ type Output = ( ) ;
570+ const DEFAULT : bool = true ;
571+ const ONLY_HOSTS : bool = true ;
572+
573+ fn should_run ( run : ShouldRun ) -> ShouldRun {
574+ let builder = run. builder ;
575+ run. krate ( "rustc-main" ) . default_condition ( builder. build . config . docs )
576+ }
577+
578+ fn make_run ( run : RunConfig ) {
579+ run. builder . ensure ( WhitelistedRustc {
580+ stage : run. builder . top_stage ,
581+ target : run. target ,
582+ } ) ;
583+ }
584+
585+ /// Generate whitelisted compiler crate documentation.
586+ ///
587+ /// This will generate all documentation for crates that are whitelisted
588+ /// to be included in the standard documentation. This documentation is
589+ /// included in the standard Rust documentation, so we should always
590+ /// document it and symlink to merge with the rest of the std and test
591+ /// documentation. We don't build other compiler documentation
592+ /// here as we want to be able to keep it separate from the standard
593+ /// documentation. This is largely just a wrapper around `cargo doc`.
594+ fn run ( self , builder : & Builder ) {
595+ let build = builder. build ;
596+ let stage = self . stage ;
597+ let target = self . target ;
598+ println ! ( "Documenting stage{} whitelisted compiler ({})" , stage, target) ;
599+ let out = build. doc_out ( target) ;
600+ t ! ( fs:: create_dir_all( & out) ) ;
601+ let compiler = builder. compiler ( stage, build. build ) ;
602+ let rustdoc = builder. rustdoc ( compiler. host ) ;
603+ let compiler = if build. force_use_stage1 ( compiler, target) {
604+ builder. compiler ( 1 , compiler. host )
605+ } else {
606+ compiler
607+ } ;
608+
609+ // Build libstd docs so that we generate relative links
610+ builder. ensure ( Std { stage, target } ) ;
611+
612+ builder. ensure ( compile:: Rustc { compiler, target } ) ;
613+ let out_dir = build. stage_out ( compiler, Mode :: Librustc )
614+ . join ( target) . join ( "doc" ) ;
615+
616+ // See docs in std above for why we symlink
617+ let my_out = build. crate_doc_out ( target) ;
618+ build. clear_if_dirty ( & my_out, & rustdoc) ;
619+ t ! ( symlink_dir_force( & my_out, & out_dir) ) ;
620+
621+ let mut cargo = builder. cargo ( compiler, Mode :: Librustc , target, "doc" ) ;
622+ compile:: rustc_cargo ( build, & mut cargo) ;
623+
624+ // We don't want to build docs for internal compiler dependencies in this
625+ // step (there is another step for that). Therefore, we whitelist the crates
626+ // for which docs must be built.
627+ cargo. arg ( "--no-deps" ) ;
628+ for krate in & [ "proc_macro" ] {
629+ cargo. arg ( "-p" ) . arg ( krate) ;
630+ }
631+
632+ build. run ( & mut cargo) ;
633+ cp_r ( & my_out, & out) ;
634+ }
635+ }
636+
566637#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
567638pub struct Rustc {
568639 stage : u32 ,
@@ -586,16 +657,18 @@ impl Step for Rustc {
586657 } ) ;
587658 }
588659
589- /// Generate all compiler documentation.
660+ /// Generate compiler documentation.
590661 ///
591- /// This will generate all documentation for the compiler libraries and their
592- /// dependencies. This is largely just a wrapper around `cargo doc`.
662+ /// This will generate all documentation for compiler and dependencies.
663+ /// Compiler documentation is distributed separately, so we make sure
664+ /// we do not merge it with the other documentation from std, test and
665+ /// proc_macros. This is largely just a wrapper around `cargo doc`.
593666 fn run ( self , builder : & Builder ) {
594667 let build = builder. build ;
595668 let stage = self . stage ;
596669 let target = self . target ;
597670 println ! ( "Documenting stage{} compiler ({})" , stage, target) ;
598- let out = build. doc_out ( target) ;
671+ let out = build. compiler_doc_out ( target) ;
599672 t ! ( fs:: create_dir_all( & out) ) ;
600673 let compiler = builder. compiler ( stage, build. build ) ;
601674 let rustdoc = builder. rustdoc ( compiler. host ) ;
@@ -605,6 +678,11 @@ impl Step for Rustc {
605678 compiler
606679 } ;
607680
681+ if !build. config . compiler_docs {
682+ println ! ( "\t skipping - compiler docs disabled" ) ;
683+ return ;
684+ }
685+
608686 // Build libstd docs so that we generate relative links
609687 builder. ensure ( Std { stage, target } ) ;
610688
@@ -613,25 +691,22 @@ impl Step for Rustc {
613691 . join ( target) . join ( "doc" ) ;
614692
615693 // See docs in std above for why we symlink
694+ //
695+ // This step must happen after other documentation steps. This
696+ // invariant ensures that compiler documentation is not included
697+ // in the standard documentation tarballs but that all the
698+ // documentation from the standard documentation tarballs is included
699+ // in the compiler documentation tarball.
616700 let my_out = build. crate_doc_out ( target) ;
617701 build. clear_if_dirty ( & my_out, & rustdoc) ;
618702 t ! ( symlink_dir_force( & my_out, & out_dir) ) ;
619703
620704 let mut cargo = builder. cargo ( compiler, Mode :: Librustc , target, "doc" ) ;
621705 compile:: rustc_cargo ( build, & mut cargo) ;
622706
623- if build. config . compiler_docs {
624- // src/rustc/Cargo.toml contains a bin crate called rustc which
625- // would otherwise overwrite the docs for the real rustc lib crate.
626- cargo. arg ( "-p" ) . arg ( "rustc_driver" ) ;
627- } else {
628- // Like with libstd above if compiler docs aren't enabled then we're not
629- // documenting internal dependencies, so we have a whitelist.
630- cargo. arg ( "--no-deps" ) ;
631- for krate in & [ "proc_macro" ] {
632- cargo. arg ( "-p" ) . arg ( krate) ;
633- }
634- }
707+ // src/rustc/Cargo.toml contains a bin crate called rustc which
708+ // would otherwise overwrite the docs for the real rustc lib crate.
709+ cargo. arg ( "-p" ) . arg ( "rustc_driver" ) ;
635710
636711 build. run ( & mut cargo) ;
637712 cp_r ( & my_out, & out) ;
0 commit comments