1
1
//! Implementation of compiling the compiler and standard library, in "check"-based modes.
2
2
3
- use crate :: builder:: { Builder , Kind , RunConfig , ShouldRun , Step } ;
3
+ use crate :: builder:: { crate_description , Builder , Kind , RunConfig , ShouldRun , Step } ;
4
4
use crate :: cache:: Interned ;
5
5
use crate :: compile:: { add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo} ;
6
6
use crate :: config:: TargetSelection ;
@@ -12,6 +12,12 @@ use std::path::{Path, PathBuf};
12
12
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
13
13
pub struct Std {
14
14
pub target : TargetSelection ,
15
+ /// Whether to build only a subset of crates.
16
+ ///
17
+ /// This shouldn't be used from other steps; see the comment on [`compile::Rustc`].
18
+ ///
19
+ /// [`compile::Rustc`]: crate::compile::Rustc
20
+ crates : Interned < Vec < String > > ,
15
21
}
16
22
17
23
/// Returns args for the subcommand itself (not for cargo)
@@ -66,16 +72,24 @@ fn cargo_subcommand(kind: Kind) -> &'static str {
66
72
}
67
73
}
68
74
75
+ impl Std {
76
+ pub fn new ( target : TargetSelection ) -> Self {
77
+ Self { target, crates : INTERNER . intern_list ( vec ! [ ] ) }
78
+ }
79
+ }
80
+
69
81
impl Step for Std {
70
82
type Output = ( ) ;
71
83
const DEFAULT : bool = true ;
72
84
73
85
fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
74
- run. all_krates ( "sysroot" ) . path ( "library" )
86
+ let crates = run. builder . in_tree_crates ( "sysroot" , None ) ;
87
+ run. crates ( crates) . path ( "library" )
75
88
}
76
89
77
90
fn make_run ( run : RunConfig < ' _ > ) {
78
- run. builder . ensure ( Std { target : run. target } ) ;
91
+ let crates = run. cargo_crates_in_set ( ) ;
92
+ run. builder . ensure ( Std { target : run. target , crates } ) ;
79
93
}
80
94
81
95
fn run ( self , builder : & Builder < ' _ > ) {
@@ -97,7 +111,14 @@ impl Step for Std {
97
111
cargo. arg ( "--lib" ) ;
98
112
}
99
113
100
- let _guard = builder. msg_check ( "library artifacts" , target) ;
114
+ for krate in & * self . crates {
115
+ cargo. arg ( "-p" ) . arg ( krate) ;
116
+ }
117
+
118
+ let _guard = builder. msg_check (
119
+ format_args ! ( "library artifacts{}" , crate_description( & self . crates) ) ,
120
+ target,
121
+ ) ;
101
122
run_cargo (
102
123
builder,
103
124
cargo,
@@ -117,7 +138,8 @@ impl Step for Std {
117
138
}
118
139
119
140
// don't run on std twice with x.py clippy
120
- if builder. kind == Kind :: Clippy {
141
+ // don't check test dependencies if we haven't built libtest
142
+ if builder. kind == Kind :: Clippy || !self . crates . is_empty ( ) {
121
143
return ;
122
144
}
123
145
@@ -147,8 +169,8 @@ impl Step for Std {
147
169
// Explicitly pass -p for all dependencies krates -- this will force cargo
148
170
// to also check the tests/benches/examples for these crates, rather
149
171
// than just the leaf crate.
150
- for krate in builder . in_tree_crates ( "test" , Some ( target ) ) {
151
- cargo. arg ( "-p" ) . arg ( krate. name ) ;
172
+ for krate in & * self . crates {
173
+ cargo. arg ( "-p" ) . arg ( krate) ;
152
174
}
153
175
154
176
let _guard = builder. msg_check ( "library test/bench/example targets" , target) ;
@@ -167,6 +189,22 @@ impl Step for Std {
167
189
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
168
190
pub struct Rustc {
169
191
pub target : TargetSelection ,
192
+ /// Whether to build only a subset of crates.
193
+ ///
194
+ /// This shouldn't be used from other steps; see the comment on [`compile::Rustc`].
195
+ ///
196
+ /// [`compile::Rustc`]: crate::compile::Rustc
197
+ crates : Interned < Vec < String > > ,
198
+ }
199
+
200
+ impl Rustc {
201
+ pub fn new ( target : TargetSelection , builder : & Builder < ' _ > ) -> Self {
202
+ let mut crates = vec ! [ ] ;
203
+ for krate in builder. in_tree_crates ( "rustc-main" , None ) {
204
+ crates. push ( krate. name . to_string ( ) ) ;
205
+ }
206
+ Self { target, crates : INTERNER . intern_list ( crates) }
207
+ }
170
208
}
171
209
172
210
impl Step for Rustc {
@@ -175,11 +213,13 @@ impl Step for Rustc {
175
213
const DEFAULT : bool = true ;
176
214
177
215
fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
178
- run. all_krates ( "rustc-main" ) . path ( "compiler" )
216
+ let crates = run. builder . in_tree_crates ( "rustc-main" , None ) ;
217
+ run. crates ( crates) . path ( "compiler" )
179
218
}
180
219
181
220
fn make_run ( run : RunConfig < ' _ > ) {
182
- run. builder . ensure ( Rustc { target : run. target } ) ;
221
+ let crates = run. cargo_crates_in_set ( ) ;
222
+ run. builder . ensure ( Rustc { target : run. target , crates } ) ;
183
223
}
184
224
185
225
/// Builds the compiler.
@@ -200,7 +240,7 @@ impl Step for Rustc {
200
240
builder. ensure ( crate :: compile:: Std :: new ( compiler, compiler. host ) ) ;
201
241
builder. ensure ( crate :: compile:: Std :: new ( compiler, target) ) ;
202
242
} else {
203
- builder. ensure ( Std { target } ) ;
243
+ builder. ensure ( Std :: new ( target) ) ;
204
244
}
205
245
206
246
let mut cargo = builder. cargo (
@@ -218,14 +258,17 @@ impl Step for Rustc {
218
258
cargo. arg ( "--all-targets" ) ;
219
259
}
220
260
221
- // Explicitly pass -p for all compiler krates -- this will force cargo
261
+ // Explicitly pass -p for all compiler crates -- this will force cargo
222
262
// to also check the tests/benches/examples for these crates, rather
223
263
// than just the leaf crate.
224
- for krate in builder . in_tree_crates ( "rustc-main" , Some ( target ) ) {
225
- cargo. arg ( "-p" ) . arg ( krate. name ) ;
264
+ for krate in & * self . crates {
265
+ cargo. arg ( "-p" ) . arg ( krate) ;
226
266
}
227
267
228
- let _guard = builder. msg_check ( "compiler artifacts" , target) ;
268
+ let _guard = builder. msg_check (
269
+ format_args ! ( "compiler artifacts{}" , crate_description( & self . crates) ) ,
270
+ target,
271
+ ) ;
229
272
run_cargo (
230
273
builder,
231
274
cargo,
@@ -268,7 +311,7 @@ impl Step for CodegenBackend {
268
311
let target = self . target ;
269
312
let backend = self . backend ;
270
313
271
- builder. ensure ( Rustc { target } ) ;
314
+ builder. ensure ( Rustc :: new ( target, builder ) ) ;
272
315
273
316
let mut cargo = builder. cargo (
274
317
compiler,
@@ -318,7 +361,7 @@ impl Step for RustAnalyzer {
318
361
let compiler = builder. compiler ( builder. top_stage , builder. config . build ) ;
319
362
let target = self . target ;
320
363
321
- builder. ensure ( Std { target } ) ;
364
+ builder. ensure ( Std :: new ( target) ) ;
322
365
323
366
let mut cargo = prepare_tool_cargo (
324
367
builder,
@@ -386,7 +429,7 @@ macro_rules! tool_check_step {
386
429
let compiler = builder. compiler( builder. top_stage, builder. config. build) ;
387
430
let target = self . target;
388
431
389
- builder. ensure( Rustc { target } ) ;
432
+ builder. ensure( Rustc :: new ( target, builder ) ) ;
390
433
391
434
let mut cargo = prepare_tool_cargo(
392
435
builder,
0 commit comments