@@ -16,8 +16,7 @@ use crate::core::build_steps::tool::{
16
16
self , RustcPrivateCompilers , SourceType , Tool , prepare_tool_cargo,
17
17
} ;
18
18
use 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,
21
20
} ;
22
21
use crate :: core:: config:: { Config , TargetSelection } ;
23
22
use crate :: helpers:: { submodule_path_of, symlink_dir, t, up_to_date} ;
@@ -26,7 +25,7 @@ use crate::{FileType, Mode};
26
25
macro_rules! book {
27
26
( $( $name: ident, $path: expr, $book_name: expr, $lang: expr ; ) +) => {
28
27
$(
29
- #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
28
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
30
29
pub struct $name {
31
30
target: TargetSelection ,
32
31
}
@@ -797,13 +796,21 @@ pub struct Rustc {
797
796
798
797
impl Rustc {
799
798
/// 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 {
801
809
let crates = builder
802
810
. in_tree_crates ( "rustc-main" , Some ( target) )
803
811
. into_iter ( )
804
812
. map ( |krate| krate. name . to_string ( ) )
805
813
. collect ( ) ;
806
- let build_compiler = prepare_doc_compiler ( builder, target, stage) ;
807
814
Self { build_compiler, target, crates }
808
815
}
809
816
}
@@ -821,7 +828,7 @@ impl Step for Rustc {
821
828
}
822
829
823
830
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 ) ) ;
825
832
}
826
833
827
834
/// Generates compiler documentation.
@@ -942,12 +949,14 @@ macro_rules! tool_doc {
942
949
(
943
950
$tool: ident,
944
951
$path: literal,
945
- $( rustc_tool = $rustc_tool : literal, ) ?
952
+ $( rustc_private_tool = $rustc_private_tool : literal, ) ?
946
953
$( is_library = $is_library: expr, ) ?
947
954
$( crates = $crates: expr) ?
948
955
) => {
949
956
#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
950
957
pub struct $tool {
958
+ build_compiler: Compiler ,
959
+ mode: Mode ,
951
960
target: TargetSelection ,
952
961
}
953
962
@@ -962,15 +971,26 @@ macro_rules! tool_doc {
962
971
}
963
972
964
973
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 } ) ;
966
989
}
967
990
968
- /// Generates compiler documentation.
991
+ /// Generates documentation for a tool .
969
992
///
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`.
974
994
fn run( self , builder: & Builder <' _>) {
975
995
let mut source_type = SourceType :: InTree ;
976
996
@@ -979,31 +999,17 @@ macro_rules! tool_doc {
979
999
builder. require_submodule( & submodule_path, None ) ;
980
1000
}
981
1001
982
- let stage = builder. top_stage;
983
- let target = self . target;
1002
+ let $tool { build_compiler, mode, target } = self ;
984
1003
985
1004
// This is the intended out directory for compiler documentation.
986
1005
let out = builder. compiler_doc_out( target) ;
987
1006
t!( fs:: create_dir_all( & out) ) ;
988
1007
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
-
1002
1008
// Build cargo command.
1003
1009
let mut cargo = prepare_tool_cargo(
1004
1010
builder,
1005
- compiler ,
1006
- Mode :: ToolRustc ,
1011
+ build_compiler ,
1012
+ mode ,
1007
1013
target,
1008
1014
Kind :: Doc ,
1009
1015
$path,
@@ -1030,18 +1036,18 @@ macro_rules! tool_doc {
1030
1036
cargo. rustdocflag( "--show-type-layout" ) ;
1031
1037
cargo. rustdocflag( "--generate-link-to-definition" ) ;
1032
1038
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" ) ;
1034
1040
$( for krate in $crates {
1035
1041
let dir_name = krate. replace( "-" , "_" ) ;
1036
1042
t!( fs:: create_dir_all( out_dir. join( & * dir_name) ) ) ;
1037
1043
} ) ?
1038
1044
1039
1045
// Symlink compiler docs to the output directory of rustdoc documentation.
1040
1046
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" ) ;
1042
1048
symlink_dir_force( & builder. config, & out, & proc_macro_out_dir) ;
1043
1049
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) ;
1045
1051
cargo. into_cmd( ) . run( builder) ;
1046
1052
1047
1053
if !builder. config. dry_run( ) {
@@ -1055,7 +1061,7 @@ macro_rules! tool_doc {
1055
1061
}
1056
1062
1057
1063
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 ) )
1059
1065
}
1060
1066
}
1061
1067
}
@@ -1065,7 +1071,7 @@ macro_rules! tool_doc {
1065
1071
tool_doc ! (
1066
1072
BuildHelper ,
1067
1073
"src/build_helper" ,
1068
- rustc_tool = false ,
1074
+ rustc_private_tool = false ,
1069
1075
is_library = true ,
1070
1076
crates = [ "build_helper" ]
1071
1077
) ;
@@ -1076,7 +1082,7 @@ tool_doc!(Miri, "src/tools/miri", crates = ["miri"]);
1076
1082
tool_doc ! (
1077
1083
Cargo ,
1078
1084
"src/tools/cargo" ,
1079
- rustc_tool = false ,
1085
+ rustc_private_tool = false ,
1080
1086
crates = [
1081
1087
"cargo" ,
1082
1088
"cargo-credential" ,
@@ -1090,25 +1096,25 @@ tool_doc!(
1090
1096
"rustfix" ,
1091
1097
]
1092
1098
) ;
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" ] ) ;
1094
1100
tool_doc ! (
1095
1101
Bootstrap ,
1096
1102
"src/bootstrap" ,
1097
- rustc_tool = false ,
1103
+ rustc_private_tool = false ,
1098
1104
is_library = true ,
1099
1105
crates = [ "bootstrap" ]
1100
1106
) ;
1101
1107
tool_doc ! (
1102
1108
RunMakeSupport ,
1103
1109
"src/tools/run-make-support" ,
1104
- rustc_tool = false ,
1110
+ rustc_private_tool = false ,
1105
1111
is_library = true ,
1106
1112
crates = [ "run_make_support" ]
1107
1113
) ;
1108
1114
tool_doc ! (
1109
1115
Compiletest ,
1110
1116
"src/tools/compiletest" ,
1111
- rustc_tool = false ,
1117
+ rustc_private_tool = false ,
1112
1118
is_library = true ,
1113
1119
crates = [ "compiletest" ]
1114
1120
) ;
0 commit comments