@@ -43,6 +43,9 @@ const EXCEPTIONS: &[(&str, &str)] = &[
43
43
( "arrayref" , "BSD-2-Clause" ) , // cargo-miri/directories/.../rust-argon2 (redox)
44
44
( "instant" , "BSD-3-Clause" ) , // rustc_driver/tracing-subscriber/parking_lot
45
45
( "snap" , "BSD-3-Clause" ) , // rustc
46
+ ] ;
47
+
48
+ const RUNTIME_EXCEPTIONS : & [ ( & str , & str ) ] = & [
46
49
// FIXME: this dependency violates the documentation comment above:
47
50
( "fortanix-sgx-abi" , "MPL-2.0" ) , // libstd but only for `sgx` target
48
51
] ;
@@ -79,7 +82,6 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
79
82
"chalk-ir" ,
80
83
"cloudabi" ,
81
84
"cmake" ,
82
- "compiler_builtins" ,
83
85
"crc32fast" ,
84
86
"crossbeam-deque" ,
85
87
"crossbeam-epoch" ,
@@ -88,15 +90,13 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
88
90
"datafrog" ,
89
91
"difference" ,
90
92
"digest" ,
91
- "dlmalloc" ,
92
93
"either" ,
93
94
"ena" ,
94
95
"env_logger" ,
95
96
"expect-test" ,
96
97
"fake-simd" ,
97
98
"filetime" ,
98
99
"flate2" ,
99
- "fortanix-sgx-abi" ,
100
100
"fuchsia-zircon" ,
101
101
"fuchsia-zircon-sys" ,
102
102
"generic-array" ,
@@ -144,7 +144,6 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
144
144
"rand_core" ,
145
145
"rand_hc" ,
146
146
"rand_pcg" ,
147
- "rand_xorshift" ,
148
147
"redox_syscall" ,
149
148
"regex" ,
150
149
"regex-syntax" ,
@@ -190,6 +189,37 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
190
189
"winapi-x86_64-pc-windows-gnu" ,
191
190
] ;
192
191
192
+ /// Crates the runtime is allowed to depend on. Avoid adding to the list if possible.
193
+ ///
194
+ /// This list is here to provide a speed-bump to adding a new dependency to
195
+ /// the runtime. Please check with the compiler team before adding an entry.
196
+ const PERMITTED_RUNTIME_DEPENDENCIES : & [ & str ] = & [
197
+ "addr2line" ,
198
+ "adler" ,
199
+ "cc" ,
200
+ "cfg-if" ,
201
+ "compiler_builtins" ,
202
+ "dlmalloc" ,
203
+ "fortanix-sgx-abi" ,
204
+ "getopts" ,
205
+ "getrandom" ,
206
+ "gimli" ,
207
+ "hashbrown" ,
208
+ "hermit-abi" ,
209
+ "libc" ,
210
+ "miniz_oxide" ,
211
+ "object" ,
212
+ "ppv-lite86" ,
213
+ "rand" ,
214
+ "rand_chacha" ,
215
+ "rand_core" ,
216
+ "rand_hc" ,
217
+ "rand_xorshift" ,
218
+ "rustc-demangle" ,
219
+ "unicode-width" ,
220
+ "wasi" ,
221
+ ] ;
222
+
193
223
/// Dependency checks.
194
224
///
195
225
/// `root` is path to the directory with the root `Cargo.toml` (for the workspace). `cargo` is path
@@ -200,17 +230,32 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
200
230
. manifest_path ( root. join ( "Cargo.toml" ) )
201
231
. features ( cargo_metadata:: CargoOpt :: AllFeatures ) ;
202
232
let metadata = t ! ( cmd. exec( ) ) ;
203
- check_exceptions ( & metadata, bad) ;
204
- check_dependencies ( & metadata, bad) ;
233
+ check_exceptions ( & metadata, EXCEPTIONS , false , bad) ;
234
+ check_dependencies ( & metadata, PERMITTED_DEPENDENCIES , RESTRICTED_DEPENDENCY_CRATES , bad) ;
205
235
check_crate_duplicate ( & metadata, bad) ;
236
+
237
+ let mut cmd = cargo_metadata:: MetadataCommand :: new ( ) ;
238
+ cmd. cargo_path ( cargo)
239
+ . manifest_path ( root. join ( "library" ) . join ( "Cargo.toml" ) )
240
+ . features ( cargo_metadata:: CargoOpt :: AllFeatures ) ;
241
+ let metadata = t ! ( cmd. exec( ) ) ;
242
+ check_exceptions ( & metadata, RUNTIME_EXCEPTIONS , true , bad) ;
243
+ check_dependencies ( & metadata, PERMITTED_RUNTIME_DEPENDENCIES , RUNTIME_CRATES , bad) ;
244
+ // Not running `check_crate_duplicate`, as the crates that don't allow duplicates are not used
245
+ // by the runtime.
206
246
}
207
247
208
248
/// Check that all licenses are in the valid list in `LICENSES`.
209
249
///
210
250
/// Packages listed in `EXCEPTIONS` are allowed for tools.
211
- fn check_exceptions ( metadata : & Metadata , bad : & mut bool ) {
251
+ fn check_exceptions (
252
+ metadata : & Metadata ,
253
+ exceptions : & [ ( & str , & str ) ] ,
254
+ is_runtime : bool ,
255
+ bad : & mut bool ,
256
+ ) {
212
257
// Validate the EXCEPTIONS list hasn't changed.
213
- for ( name, license) in EXCEPTIONS {
258
+ for ( name, license) in exceptions {
214
259
// Check that the package actually exists.
215
260
if !metadata. packages . iter ( ) . any ( |p| p. name == * name) {
216
261
println ! (
@@ -257,8 +302,8 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
257
302
}
258
303
}
259
304
260
- let exception_names: Vec < _ > = EXCEPTIONS . iter ( ) . map ( |( name, _license) | * name) . collect ( ) ;
261
- let runtime_ids = compute_runtime_crates ( metadata) ;
305
+ let exception_names: Vec < _ > = exceptions . iter ( ) . map ( |( name, _license) | * name) . collect ( ) ;
306
+ let runtime_ids = if is_runtime { compute_runtime_crates ( metadata) } else { HashSet :: new ( ) } ;
262
307
263
308
// Check if any package does not have a valid license.
264
309
for pkg in & metadata. packages {
@@ -295,9 +340,14 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
295
340
/// `true` if a check failed.
296
341
///
297
342
/// Specifically, this checks that the dependencies are on the `PERMITTED_DEPENDENCIES`.
298
- fn check_dependencies ( metadata : & Metadata , bad : & mut bool ) {
343
+ fn check_dependencies (
344
+ metadata : & Metadata ,
345
+ permitted : & [ & ' static str ] ,
346
+ restricted_dependency_crates : & [ & ' static str ] ,
347
+ bad : & mut bool ,
348
+ ) {
299
349
// Check that the PERMITTED_DEPENDENCIES does not have unused entries.
300
- for name in PERMITTED_DEPENDENCIES {
350
+ for name in permitted {
301
351
if !metadata. packages . iter ( ) . any ( |p| p. name == * name) {
302
352
println ! (
303
353
"could not find allowed package `{}`\n \
@@ -308,12 +358,12 @@ fn check_dependencies(metadata: &Metadata, bad: &mut bool) {
308
358
}
309
359
}
310
360
// Get the list in a convenient form.
311
- let permitted_dependencies: HashSet < _ > = PERMITTED_DEPENDENCIES . iter ( ) . cloned ( ) . collect ( ) ;
361
+ let permitted_dependencies: HashSet < _ > = permitted . iter ( ) . cloned ( ) . collect ( ) ;
312
362
313
363
// Check dependencies.
314
364
let mut visited = BTreeSet :: new ( ) ;
315
365
let mut unapproved = BTreeSet :: new ( ) ;
316
- for & krate in RESTRICTED_DEPENDENCY_CRATES . iter ( ) {
366
+ for & krate in restricted_dependency_crates . iter ( ) {
317
367
let pkg = pkg_from_name ( metadata, krate) ;
318
368
let mut bad =
319
369
check_crate_dependencies ( & permitted_dependencies, metadata, & mut visited, pkg) ;
0 commit comments