@@ -16,8 +16,7 @@ use crate::core::build_steps::tool::{
1616 self , RustcPrivateCompilers , SourceType , Tool , prepare_tool_cargo,
1717} ;
1818use crate :: core:: builder:: {
19- self , Alias , Builder , Compiler , Kind , RunConfig , ShouldRun , Step , StepMetadata ,
20- crate_description,
19+ self , Builder , Compiler , Kind , RunConfig , ShouldRun , Step , StepMetadata , crate_description,
2120} ;
2221use crate :: core:: config:: { Config , TargetSelection } ;
2322use crate :: helpers:: { submodule_path_of, symlink_dir, t, up_to_date} ;
@@ -26,7 +25,7 @@ use crate::{FileType, Mode};
2625macro_rules! book {
2726 ( $( $name: ident, $path: expr, $book_name: expr, $lang: expr ; ) +) => {
2827 $(
29- #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
28+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
3029 pub struct $name {
3130 target: TargetSelection ,
3231 }
@@ -797,13 +796,21 @@ pub struct Rustc {
797796
798797impl Rustc {
799798 /// Document `stage` compiler for the given `target`.
800- pub ( crate ) fn for_stage ( builder : & Builder < ' _ > , target : TargetSelection , stage : u32 ) -> Self {
799+ pub ( crate ) fn for_stage ( builder : & Builder < ' _ > , stage : u32 , target : TargetSelection ) -> Self {
800+ let build_compiler = prepare_doc_compiler ( builder, target, stage) ;
801+ Self :: from_build_compiler ( builder, build_compiler, target)
802+ }
803+
804+ fn from_build_compiler (
805+ builder : & Builder < ' _ > ,
806+ build_compiler : Compiler ,
807+ target : TargetSelection ,
808+ ) -> Self {
801809 let crates = builder
802810 . in_tree_crates ( "rustc-main" , Some ( target) )
803811 . into_iter ( )
804812 . map ( |krate| krate. name . to_string ( ) )
805813 . collect ( ) ;
806- let build_compiler = prepare_doc_compiler ( builder, target, stage) ;
807814 Self { build_compiler, target, crates }
808815 }
809816}
@@ -821,7 +828,7 @@ impl Step for Rustc {
821828 }
822829
823830 fn make_run ( run : RunConfig < ' _ > ) {
824- run. builder . ensure ( Rustc :: for_stage ( run. builder , run. target , run. builder . top_stage ) ) ;
831+ run. builder . ensure ( Rustc :: for_stage ( run. builder , run. builder . top_stage , run. target ) ) ;
825832 }
826833
827834 /// Generates compiler documentation.
@@ -942,12 +949,14 @@ macro_rules! tool_doc {
942949 (
943950 $tool: ident,
944951 $path: literal,
945- $( rustc_tool = $rustc_tool : literal, ) ?
952+ $( rustc_private_tool = $rustc_private_tool : literal, ) ?
946953 $( is_library = $is_library: expr, ) ?
947954 $( crates = $crates: expr) ?
948955 ) => {
949956 #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
950957 pub struct $tool {
958+ build_compiler: Compiler ,
959+ mode: Mode ,
951960 target: TargetSelection ,
952961 }
953962
@@ -962,15 +971,26 @@ macro_rules! tool_doc {
962971 }
963972
964973 fn make_run( run: RunConfig <' _>) {
965- run. builder. ensure( $tool { target: run. target } ) ;
974+ let target = run. target;
975+ let ( build_compiler, mode) = if true $( && $rustc_private_tool) ? {
976+ // Rustdoc needs the rustc sysroot available to build.
977+ let compilers = RustcPrivateCompilers :: new( run. builder, run. builder. top_stage, target) ;
978+
979+ // Build rustc docs so that we generate relative links.
980+ run. builder. ensure( Rustc :: from_build_compiler( run. builder, compilers. build_compiler( ) , target) ) ;
981+
982+ ( compilers. build_compiler( ) , Mode :: ToolRustc )
983+ } else {
984+ // bootstrap/host tools have to be documented with the stage 0 compiler
985+ ( prepare_doc_compiler( run. builder, target, 1 ) , Mode :: ToolBootstrap )
986+ } ;
987+
988+ run. builder. ensure( $tool { build_compiler, mode, target } ) ;
966989 }
967990
968- /// Generates compiler documentation.
991+ /// Generates documentation for a tool .
969992 ///
970- /// This will generate all documentation for compiler and dependencies.
971- /// Compiler documentation is distributed separately, so we make sure
972- /// we do not merge it with the other documentation from std, test and
973- /// proc_macros. This is largely just a wrapper around `cargo doc`.
993+ /// This is largely just a wrapper around `cargo doc`.
974994 fn run( self , builder: & Builder <' _>) {
975995 let mut source_type = SourceType :: InTree ;
976996
@@ -979,31 +999,17 @@ macro_rules! tool_doc {
979999 builder. require_submodule( & submodule_path, None ) ;
9801000 }
9811001
982- let stage = builder. top_stage;
983- let target = self . target;
1002+ let $tool { build_compiler, mode, target } = self ;
9841003
9851004 // This is the intended out directory for compiler documentation.
9861005 let out = builder. compiler_doc_out( target) ;
9871006 t!( fs:: create_dir_all( & out) ) ;
9881007
989- let compiler = builder. compiler( stage, builder. config. host_target) ;
990- builder. std( compiler, target) ;
991-
992- if true $( && $rustc_tool) ? {
993- // Build rustc docs so that we generate relative links.
994- builder. ensure( Rustc :: new( stage, target, builder) ) ;
995-
996- // Rustdoc needs the rustc sysroot available to build.
997- // FIXME: is there a way to only ensure `check::Rustc` here? Last time I tried it failed
998- // with strange errors, but only on a full bors test ...
999- builder. ensure( compile:: Rustc :: new( compiler, target) ) ;
1000- }
1001-
10021008 // Build cargo command.
10031009 let mut cargo = prepare_tool_cargo(
10041010 builder,
1005- compiler ,
1006- Mode :: ToolRustc ,
1011+ build_compiler ,
1012+ mode ,
10071013 target,
10081014 Kind :: Doc ,
10091015 $path,
@@ -1030,18 +1036,18 @@ macro_rules! tool_doc {
10301036 cargo. rustdocflag( "--show-type-layout" ) ;
10311037 cargo. rustdocflag( "--generate-link-to-definition" ) ;
10321038
1033- let out_dir = builder. stage_out( compiler , Mode :: ToolRustc ) . join( target) . join( "doc" ) ;
1039+ let out_dir = builder. stage_out( build_compiler , mode ) . join( target) . join( "doc" ) ;
10341040 $( for krate in $crates {
10351041 let dir_name = krate. replace( "-" , "_" ) ;
10361042 t!( fs:: create_dir_all( out_dir. join( & * dir_name) ) ) ;
10371043 } ) ?
10381044
10391045 // Symlink compiler docs to the output directory of rustdoc documentation.
10401046 symlink_dir_force( & builder. config, & out, & out_dir) ;
1041- let proc_macro_out_dir = builder. stage_out( compiler , Mode :: ToolRustc ) . join( "doc" ) ;
1047+ let proc_macro_out_dir = builder. stage_out( build_compiler , mode ) . join( "doc" ) ;
10421048 symlink_dir_force( & builder. config, & out, & proc_macro_out_dir) ;
10431049
1044- let _guard = builder. msg_doc( compiler , stringify!( $tool) . to_lowercase( ) , target) ;
1050+ let _guard = builder. msg_doc( build_compiler , stringify!( $tool) . to_lowercase( ) , target) ;
10451051 cargo. into_cmd( ) . run( builder) ;
10461052
10471053 if !builder. config. dry_run( ) {
@@ -1055,7 +1061,7 @@ macro_rules! tool_doc {
10551061 }
10561062
10571063 fn metadata( & self ) -> Option <StepMetadata > {
1058- Some ( StepMetadata :: doc( stringify!( $tool) , self . target) )
1064+ Some ( StepMetadata :: doc( stringify!( $tool) , self . target) . built_by ( self . build_compiler ) )
10591065 }
10601066 }
10611067 }
@@ -1065,7 +1071,7 @@ macro_rules! tool_doc {
10651071tool_doc ! (
10661072 BuildHelper ,
10671073 "src/build_helper" ,
1068- rustc_tool = false ,
1074+ rustc_private_tool = false ,
10691075 is_library = true ,
10701076 crates = [ "build_helper" ]
10711077) ;
@@ -1076,7 +1082,7 @@ tool_doc!(Miri, "src/tools/miri", crates = ["miri"]);
10761082tool_doc ! (
10771083 Cargo ,
10781084 "src/tools/cargo" ,
1079- rustc_tool = false ,
1085+ rustc_private_tool = false ,
10801086 crates = [
10811087 "cargo" ,
10821088 "cargo-credential" ,
@@ -1090,25 +1096,25 @@ tool_doc!(
10901096 "rustfix" ,
10911097 ]
10921098) ;
1093- tool_doc ! ( Tidy , "src/tools/tidy" , rustc_tool = false , crates = [ "tidy" ] ) ;
1099+ tool_doc ! ( Tidy , "src/tools/tidy" , rustc_private_tool = false , crates = [ "tidy" ] ) ;
10941100tool_doc ! (
10951101 Bootstrap ,
10961102 "src/bootstrap" ,
1097- rustc_tool = false ,
1103+ rustc_private_tool = false ,
10981104 is_library = true ,
10991105 crates = [ "bootstrap" ]
11001106) ;
11011107tool_doc ! (
11021108 RunMakeSupport ,
11031109 "src/tools/run-make-support" ,
1104- rustc_tool = false ,
1110+ rustc_private_tool = false ,
11051111 is_library = true ,
11061112 crates = [ "run_make_support" ]
11071113) ;
11081114tool_doc ! (
11091115 Compiletest ,
11101116 "src/tools/compiletest" ,
1111- rustc_tool = false ,
1117+ rustc_private_tool = false ,
11121118 is_library = true ,
11131119 crates = [ "compiletest" ]
11141120) ;
0 commit comments