@@ -12,10 +12,11 @@ use std::path::{Path, PathBuf};
12
12
use std:: { env, fs, mem} ;
13
13
14
14
use crate :: core:: build_steps:: compile;
15
- use crate :: core:: build_steps:: tool:: { self , SourceType , Tool , prepare_tool_cargo} ;
15
+ use crate :: core:: build_steps:: tool:: {
16
+ self , RustcPrivateCompilers , SourceType , Tool , prepare_tool_cargo,
17
+ } ;
16
18
use crate :: core:: builder:: {
17
- self , Alias , Builder , Compiler , Kind , RunConfig , ShouldRun , Step , StepMetadata ,
18
- crate_description,
19
+ self , Builder , Compiler , Kind , RunConfig , ShouldRun , Step , StepMetadata , crate_description,
19
20
} ;
20
21
use crate :: core:: config:: { Config , TargetSelection } ;
21
22
use crate :: helpers:: { submodule_path_of, symlink_dir, t, up_to_date} ;
@@ -24,7 +25,7 @@ use crate::{FileType, Mode};
24
25
macro_rules! book {
25
26
( $( $name: ident, $path: expr, $book_name: expr, $lang: expr ; ) +) => {
26
27
$(
27
- #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
28
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
28
29
pub struct $name {
29
30
target: TargetSelection ,
30
31
}
@@ -795,13 +796,21 @@ pub struct Rustc {
795
796
796
797
impl Rustc {
797
798
/// Document `stage` compiler for the given `target`.
798
- 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 {
799
809
let crates = builder
800
810
. in_tree_crates ( "rustc-main" , Some ( target) )
801
811
. into_iter ( )
802
812
. map ( |krate| krate. name . to_string ( ) )
803
813
. collect ( ) ;
804
- let build_compiler = prepare_doc_compiler ( builder, target, stage) ;
805
814
Self { build_compiler, target, crates }
806
815
}
807
816
}
@@ -819,7 +828,7 @@ impl Step for Rustc {
819
828
}
820
829
821
830
fn make_run ( run : RunConfig < ' _ > ) {
822
- 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 ) ) ;
823
832
}
824
833
825
834
/// Generates compiler documentation.
@@ -940,12 +949,14 @@ macro_rules! tool_doc {
940
949
(
941
950
$tool: ident,
942
951
$path: literal,
943
- $( rustc_tool = $rustc_tool : literal, ) ?
952
+ $( rustc_private_tool = $rustc_private_tool : literal, ) ?
944
953
$( is_library = $is_library: expr, ) ?
945
954
$( crates = $crates: expr) ?
946
955
) => {
947
956
#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
948
957
pub struct $tool {
958
+ build_compiler: Compiler ,
959
+ mode: Mode ,
949
960
target: TargetSelection ,
950
961
}
951
962
@@ -960,15 +971,26 @@ macro_rules! tool_doc {
960
971
}
961
972
962
973
fn make_run( run: RunConfig <' _>) {
963
- 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 } ) ;
964
989
}
965
990
966
- /// Generates compiler documentation.
991
+ /// Generates documentation for a tool .
967
992
///
968
- /// This will generate all documentation for compiler and dependencies.
969
- /// Compiler documentation is distributed separately, so we make sure
970
- /// we do not merge it with the other documentation from std, test and
971
- /// proc_macros. This is largely just a wrapper around `cargo doc`.
993
+ /// This is largely just a wrapper around `cargo doc`.
972
994
fn run( self , builder: & Builder <' _>) {
973
995
let mut source_type = SourceType :: InTree ;
974
996
@@ -977,31 +999,17 @@ macro_rules! tool_doc {
977
999
builder. require_submodule( & submodule_path, None ) ;
978
1000
}
979
1001
980
- let stage = builder. top_stage;
981
- let target = self . target;
1002
+ let $tool { build_compiler, mode, target } = self ;
982
1003
983
1004
// This is the intended out directory for compiler documentation.
984
1005
let out = builder. compiler_doc_out( target) ;
985
1006
t!( fs:: create_dir_all( & out) ) ;
986
1007
987
- let compiler = builder. compiler( stage, builder. config. host_target) ;
988
- builder. std( compiler, target) ;
989
-
990
- if true $( && $rustc_tool) ? {
991
- // Build rustc docs so that we generate relative links.
992
- builder. ensure( Rustc :: new( stage, target, builder) ) ;
993
-
994
- // Rustdoc needs the rustc sysroot available to build.
995
- // FIXME: is there a way to only ensure `check::Rustc` here? Last time I tried it failed
996
- // with strange errors, but only on a full bors test ...
997
- builder. ensure( compile:: Rustc :: new( compiler, target) ) ;
998
- }
999
-
1000
1008
// Build cargo command.
1001
1009
let mut cargo = prepare_tool_cargo(
1002
1010
builder,
1003
- compiler ,
1004
- Mode :: ToolRustc ,
1011
+ build_compiler ,
1012
+ mode ,
1005
1013
target,
1006
1014
Kind :: Doc ,
1007
1015
$path,
@@ -1028,18 +1036,18 @@ macro_rules! tool_doc {
1028
1036
cargo. rustdocflag( "--show-type-layout" ) ;
1029
1037
cargo. rustdocflag( "--generate-link-to-definition" ) ;
1030
1038
1031
- 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" ) ;
1032
1040
$( for krate in $crates {
1033
1041
let dir_name = krate. replace( "-" , "_" ) ;
1034
1042
t!( fs:: create_dir_all( out_dir. join( & * dir_name) ) ) ;
1035
1043
} ) ?
1036
1044
1037
1045
// Symlink compiler docs to the output directory of rustdoc documentation.
1038
1046
symlink_dir_force( & builder. config, & out, & out_dir) ;
1039
- 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" ) ;
1040
1048
symlink_dir_force( & builder. config, & out, & proc_macro_out_dir) ;
1041
1049
1042
- let _guard = builder. msg_doc( compiler , stringify!( $tool) . to_lowercase( ) , target) ;
1050
+ let _guard = builder. msg_doc( build_compiler , stringify!( $tool) . to_lowercase( ) , target) ;
1043
1051
cargo. into_cmd( ) . run( builder) ;
1044
1052
1045
1053
if !builder. config. dry_run( ) {
@@ -1053,7 +1061,7 @@ macro_rules! tool_doc {
1053
1061
}
1054
1062
1055
1063
fn metadata( & self ) -> Option <StepMetadata > {
1056
- Some ( StepMetadata :: doc( stringify!( $tool) , self . target) )
1064
+ Some ( StepMetadata :: doc( stringify!( $tool) , self . target) . built_by ( self . build_compiler ) )
1057
1065
}
1058
1066
}
1059
1067
}
@@ -1063,7 +1071,7 @@ macro_rules! tool_doc {
1063
1071
tool_doc ! (
1064
1072
BuildHelper ,
1065
1073
"src/build_helper" ,
1066
- rustc_tool = false ,
1074
+ rustc_private_tool = false ,
1067
1075
is_library = true ,
1068
1076
crates = [ "build_helper" ]
1069
1077
) ;
@@ -1074,7 +1082,7 @@ tool_doc!(Miri, "src/tools/miri", crates = ["miri"]);
1074
1082
tool_doc ! (
1075
1083
Cargo ,
1076
1084
"src/tools/cargo" ,
1077
- rustc_tool = false ,
1085
+ rustc_private_tool = false ,
1078
1086
crates = [
1079
1087
"cargo" ,
1080
1088
"cargo-credential" ,
@@ -1088,25 +1096,25 @@ tool_doc!(
1088
1096
"rustfix" ,
1089
1097
]
1090
1098
) ;
1091
- tool_doc ! ( Tidy , "src/tools/tidy" , rustc_tool = false , crates = [ "tidy" ] ) ;
1099
+ tool_doc ! ( Tidy , "src/tools/tidy" , rustc_private_tool = false , crates = [ "tidy" ] ) ;
1092
1100
tool_doc ! (
1093
1101
Bootstrap ,
1094
1102
"src/bootstrap" ,
1095
- rustc_tool = false ,
1103
+ rustc_private_tool = false ,
1096
1104
is_library = true ,
1097
1105
crates = [ "bootstrap" ]
1098
1106
) ;
1099
1107
tool_doc ! (
1100
1108
RunMakeSupport ,
1101
1109
"src/tools/run-make-support" ,
1102
- rustc_tool = false ,
1110
+ rustc_private_tool = false ,
1103
1111
is_library = true ,
1104
1112
crates = [ "run_make_support" ]
1105
1113
) ;
1106
1114
tool_doc ! (
1107
1115
Compiletest ,
1108
1116
"src/tools/compiletest" ,
1109
- rustc_tool = false ,
1117
+ rustc_private_tool = false ,
1110
1118
is_library = true ,
1111
1119
crates = [ "compiletest" ]
1112
1120
) ;
0 commit comments