9
9
10
10
use std:: io:: { self , Write } ;
11
11
use std:: path:: { Path , PathBuf } ;
12
- use std:: { fs, mem} ;
12
+ use std:: { env , fs, mem} ;
13
13
14
14
use crate :: core:: build_steps:: compile;
15
15
use crate :: core:: build_steps:: tool:: { self , prepare_tool_cargo, SourceType , Tool } ;
@@ -62,6 +62,7 @@ macro_rules! book {
62
62
src: builder. src. join( $path) ,
63
63
parent: Some ( self ) ,
64
64
languages: $lang. into( ) ,
65
+ rustdoc: None ,
65
66
} )
66
67
}
67
68
}
80
81
EditionGuide , "src/doc/edition-guide" , "edition-guide" , & [ ] , submodule;
81
82
EmbeddedBook , "src/doc/embedded-book" , "embedded-book" , & [ ] , submodule;
82
83
Nomicon , "src/doc/nomicon" , "nomicon" , & [ ] , submodule;
83
- Reference , "src/doc/reference" , "reference" , & [ ] , submodule;
84
84
RustByExample , "src/doc/rust-by-example" , "rust-by-example" , & [ "ja" ] , submodule;
85
85
RustdocBook , "src/doc/rustdoc" , "rustdoc" , & [ ] ;
86
86
StyleGuide , "src/doc/style-guide" , "style-guide" , & [ ] ;
@@ -112,6 +112,7 @@ impl Step for UnstableBook {
112
112
src : builder. md_doc_out ( self . target ) . join ( "unstable-book" ) ,
113
113
parent : Some ( self ) ,
114
114
languages : vec ! [ ] ,
115
+ rustdoc : None ,
115
116
} )
116
117
}
117
118
}
@@ -123,6 +124,7 @@ struct RustbookSrc<P: Step> {
123
124
src : PathBuf ,
124
125
parent : Option < P > ,
125
126
languages : Vec < & ' static str > ,
127
+ rustdoc : Option < PathBuf > ,
126
128
}
127
129
128
130
impl < P : Step > Step for RustbookSrc < P > {
@@ -153,13 +155,18 @@ impl<P: Step> Step for RustbookSrc<P> {
153
155
builder. info ( & format ! ( "Rustbook ({target}) - {name}" ) ) ;
154
156
let _ = fs:: remove_dir_all ( & out) ;
155
157
156
- builder
157
- . tool_cmd ( Tool :: Rustbook )
158
- . arg ( "build" )
159
- . arg ( & src)
160
- . arg ( "-d" )
161
- . arg ( & out)
162
- . run ( builder) ;
158
+ let mut rustbook_cmd = builder. tool_cmd ( Tool :: Rustbook ) ;
159
+ if let Some ( mut rustdoc) = self . rustdoc {
160
+ rustdoc. pop ( ) ;
161
+ let old_path = env:: var_os ( "PATH" ) . unwrap_or_default ( ) ;
162
+ let new_path =
163
+ env:: join_paths ( std:: iter:: once ( rustdoc) . chain ( env:: split_paths ( & old_path) ) )
164
+ . expect ( "could not add rustdoc to PATH" ) ;
165
+
166
+ rustbook_cmd. env ( "PATH" , new_path) ;
167
+ }
168
+
169
+ rustbook_cmd. arg ( "build" ) . arg ( & src) . arg ( "-d" ) . arg ( & out) . run ( builder) ;
163
170
164
171
for lang in & self . languages {
165
172
let out = out. join ( lang) ;
@@ -232,6 +239,7 @@ impl Step for TheBook {
232
239
src : absolute_path. clone ( ) ,
233
240
parent : Some ( self ) ,
234
241
languages : vec ! [ ] ,
242
+ rustdoc : None ,
235
243
} ) ;
236
244
237
245
// building older edition redirects
@@ -244,6 +252,7 @@ impl Step for TheBook {
244
252
// treat the other editions as not having a parent.
245
253
parent : Option :: < Self > :: None ,
246
254
languages : vec ! [ ] ,
255
+ rustdoc : None ,
247
256
} ) ;
248
257
}
249
258
@@ -1214,6 +1223,51 @@ impl Step for RustcBook {
1214
1223
src : out_base,
1215
1224
parent : Some ( self ) ,
1216
1225
languages : vec ! [ ] ,
1226
+ rustdoc : None ,
1227
+ } ) ;
1228
+ }
1229
+ }
1230
+
1231
+ #[ derive( Ord , PartialOrd , Debug , Clone , Hash , PartialEq , Eq ) ]
1232
+ pub struct Reference {
1233
+ pub compiler : Compiler ,
1234
+ pub target : TargetSelection ,
1235
+ }
1236
+
1237
+ impl Step for Reference {
1238
+ type Output = ( ) ;
1239
+ const DEFAULT : bool = true ;
1240
+ const ONLY_HOSTS : bool = true ;
1241
+
1242
+ fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
1243
+ let builder = run. builder ;
1244
+ run. path ( "src/doc/reference" ) . default_condition ( builder. config . docs )
1245
+ }
1246
+
1247
+ fn make_run ( run : RunConfig < ' _ > ) {
1248
+ run. builder . ensure ( Reference {
1249
+ compiler : run. builder . compiler ( run. builder . top_stage , run. builder . config . build ) ,
1250
+ target : run. target ,
1251
+ } ) ;
1252
+ }
1253
+
1254
+ /// Builds the reference book.
1255
+ fn run ( self , builder : & Builder < ' _ > ) {
1256
+ builder. require_and_update_submodule ( "src/doc/reference" , None ) ;
1257
+
1258
+ // This is needed for generating links to the standard library using
1259
+ // the mdbook-spec plugin.
1260
+ builder. ensure ( compile:: Std :: new ( self . compiler , builder. config . build ) ) ;
1261
+ let rustdoc = builder. rustdoc ( self . compiler ) ;
1262
+
1263
+ // Run rustbook/mdbook to generate the HTML pages.
1264
+ builder. ensure ( RustbookSrc {
1265
+ target : self . target ,
1266
+ name : "reference" . to_owned ( ) ,
1267
+ src : builder. src . join ( "src/doc/reference" ) ,
1268
+ parent : Some ( self ) ,
1269
+ languages : vec ! [ ] ,
1270
+ rustdoc : Some ( rustdoc) ,
1217
1271
} ) ;
1218
1272
}
1219
1273
}
0 commit comments