@@ -44,6 +44,23 @@ const EXCEPTIONS: &[(&str, &str)] = &[
44
44
( "fortanix-sgx-abi" , "MPL-2.0" ) , // libstd but only for `sgx` target
45
45
] ;
46
46
47
+ const EXCEPTIONS_CRANELIFT : & [ ( & str , & str ) ] = & [
48
+ ( "cranelift-bforest" , "Apache-2.0 WITH LLVM-exception" ) ,
49
+ ( "cranelift-codegen" , "Apache-2.0 WITH LLVM-exception" ) ,
50
+ ( "cranelift-codegen-meta" , "Apache-2.0 WITH LLVM-exception" ) ,
51
+ ( "cranelift-codegen-shared" , "Apache-2.0 WITH LLVM-exception" ) ,
52
+ ( "cranelift-entity" , "Apache-2.0 WITH LLVM-exception" ) ,
53
+ ( "cranelift-frontend" , "Apache-2.0 WITH LLVM-exception" ) ,
54
+ ( "cranelift-jit" , "Apache-2.0 WITH LLVM-exception" ) ,
55
+ ( "cranelift-module" , "Apache-2.0 WITH LLVM-exception" ) ,
56
+ ( "cranelift-native" , "Apache-2.0 WITH LLVM-exception" ) ,
57
+ ( "cranelift-object" , "Apache-2.0 WITH LLVM-exception" ) ,
58
+ ( "libloading" , "ISC" ) ,
59
+ ( "mach" , "BSD-2-Clause" ) ,
60
+ ( "regalloc" , "Apache-2.0 WITH LLVM-exception" ) ,
61
+ ( "target-lexicon" , "Apache-2.0 WITH LLVM-exception" ) ,
62
+ ] ;
63
+
47
64
/// These are the root crates that are part of the runtime. The licenses for
48
65
/// these and all their dependencies *must not* be in the exception list.
49
66
const RUNTIME_CRATES : & [ & str ] = & [ "std" , "core" , "alloc" , "test" , "panic_abort" , "panic_unwind" ] ;
@@ -212,6 +229,59 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
212
229
"winapi-x86_64-pc-windows-gnu" ,
213
230
] ;
214
231
232
+ const PERMITTED_CRANELIFT_DEPENDENCIES : & [ & str ] = & [
233
+ "anyhow" ,
234
+ "ar" ,
235
+ "autocfg" ,
236
+ "bitflags" ,
237
+ "byteorder" ,
238
+ "cfg-if" ,
239
+ "cranelift-bforest" ,
240
+ "cranelift-codegen" ,
241
+ "cranelift-codegen-meta" ,
242
+ "cranelift-codegen-shared" ,
243
+ "cranelift-entity" ,
244
+ "cranelift-frontend" ,
245
+ "cranelift-jit" ,
246
+ "cranelift-module" ,
247
+ "cranelift-native" ,
248
+ "cranelift-object" ,
249
+ "crc32fast" ,
250
+ "errno" ,
251
+ "errno-dragonfly" ,
252
+ "gcc" ,
253
+ "gimli" ,
254
+ "hashbrown" ,
255
+ "indexmap" ,
256
+ "libc" ,
257
+ "libloading" ,
258
+ "log" ,
259
+ "mach" ,
260
+ "object" ,
261
+ "proc-macro2" ,
262
+ "quote" ,
263
+ "regalloc" ,
264
+ "region" ,
265
+ "rustc-hash" ,
266
+ "smallvec" ,
267
+ "syn" ,
268
+ "target-lexicon" ,
269
+ "thiserror" ,
270
+ "thiserror-impl" ,
271
+ "unicode-xid" ,
272
+ "winapi" ,
273
+ "winapi-i686-pc-windows-gnu" ,
274
+ "winapi-x86_64-pc-windows-gnu" ,
275
+ ] ;
276
+
277
+ const FORBIDDEN_TO_HAVE_DUPLICATES : & [ & str ] = & [
278
+ // These two crates take quite a long time to build, so don't allow two versions of them
279
+ // to accidentally sneak into our dependency graph, in order to ensure we keep our CI times
280
+ // under control.
281
+ "cargo" ,
282
+ "rustc-ap-rustc_ast" ,
283
+ ] ;
284
+
215
285
/// Dependency checks.
216
286
///
217
287
/// `root` is path to the directory with the root `Cargo.toml` (for the workspace). `cargo` is path
@@ -222,17 +292,39 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
222
292
. manifest_path ( root. join ( "Cargo.toml" ) )
223
293
. features ( cargo_metadata:: CargoOpt :: AllFeatures ) ;
224
294
let metadata = t ! ( cmd. exec( ) ) ;
225
- check_exceptions ( & metadata, bad) ;
226
- check_dependencies ( & metadata, bad) ;
227
- check_crate_duplicate ( & metadata, bad) ;
295
+ let runtime_ids = compute_runtime_crates ( & metadata) ;
296
+ check_exceptions ( & metadata, EXCEPTIONS , runtime_ids, bad) ;
297
+ check_dependencies ( & metadata, PERMITTED_DEPENDENCIES , RESTRICTED_DEPENDENCY_CRATES , bad) ;
298
+ check_crate_duplicate ( & metadata, FORBIDDEN_TO_HAVE_DUPLICATES , bad) ;
299
+
300
+ // Check rustc_codegen_cranelift independently as it has it's own workspace.
301
+ let mut cmd = cargo_metadata:: MetadataCommand :: new ( ) ;
302
+ cmd. cargo_path ( cargo)
303
+ . manifest_path ( root. join ( "compiler/rustc_codegen_cranelift/Cargo.toml" ) )
304
+ . features ( cargo_metadata:: CargoOpt :: AllFeatures ) ;
305
+ let metadata = t ! ( cmd. exec( ) ) ;
306
+ let runtime_ids = HashSet :: new ( ) ;
307
+ check_exceptions ( & metadata, EXCEPTIONS_CRANELIFT , runtime_ids, bad) ;
308
+ check_dependencies (
309
+ & metadata,
310
+ PERMITTED_CRANELIFT_DEPENDENCIES ,
311
+ & [ "rustc_codegen_cranelift" ] ,
312
+ bad,
313
+ ) ;
314
+ check_crate_duplicate ( & metadata, & [ ] , bad) ;
228
315
}
229
316
230
317
/// Check that all licenses are in the valid list in `LICENSES`.
231
318
///
232
319
/// Packages listed in `EXCEPTIONS` are allowed for tools.
233
- fn check_exceptions ( metadata : & Metadata , bad : & mut bool ) {
320
+ fn check_exceptions (
321
+ metadata : & Metadata ,
322
+ exceptions : & [ ( & str , & str ) ] ,
323
+ runtime_ids : HashSet < & PackageId > ,
324
+ bad : & mut bool ,
325
+ ) {
234
326
// Validate the EXCEPTIONS list hasn't changed.
235
- for ( name, license) in EXCEPTIONS {
327
+ for ( name, license) in exceptions {
236
328
// Check that the package actually exists.
237
329
if !metadata. packages . iter ( ) . any ( |p| p. name == * name) {
238
330
tidy_error ! (
@@ -264,8 +356,7 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
264
356
}
265
357
}
266
358
267
- let exception_names: Vec < _ > = EXCEPTIONS . iter ( ) . map ( |( name, _license) | * name) . collect ( ) ;
268
- let runtime_ids = compute_runtime_crates ( metadata) ;
359
+ let exception_names: Vec < _ > = exceptions. iter ( ) . map ( |( name, _license) | * name) . collect ( ) ;
269
360
270
361
// Check if any package does not have a valid license.
271
362
for pkg in & metadata. packages {
@@ -300,9 +391,14 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
300
391
/// `true` if a check failed.
301
392
///
302
393
/// Specifically, this checks that the dependencies are on the `PERMITTED_DEPENDENCIES`.
303
- fn check_dependencies ( metadata : & Metadata , bad : & mut bool ) {
394
+ fn check_dependencies (
395
+ metadata : & Metadata ,
396
+ permitted_dependencies : & [ & ' static str ] ,
397
+ restricted_dependency_crates : & [ & ' static str ] ,
398
+ bad : & mut bool ,
399
+ ) {
304
400
// Check that the PERMITTED_DEPENDENCIES does not have unused entries.
305
- for name in PERMITTED_DEPENDENCIES {
401
+ for name in permitted_dependencies {
306
402
if !metadata. packages . iter ( ) . any ( |p| p. name == * name) {
307
403
tidy_error ! (
308
404
bad,
@@ -313,12 +409,12 @@ fn check_dependencies(metadata: &Metadata, bad: &mut bool) {
313
409
}
314
410
}
315
411
// Get the list in a convenient form.
316
- let permitted_dependencies: HashSet < _ > = PERMITTED_DEPENDENCIES . iter ( ) . cloned ( ) . collect ( ) ;
412
+ let permitted_dependencies: HashSet < _ > = permitted_dependencies . iter ( ) . cloned ( ) . collect ( ) ;
317
413
318
414
// Check dependencies.
319
415
let mut visited = BTreeSet :: new ( ) ;
320
416
let mut unapproved = BTreeSet :: new ( ) ;
321
- for & krate in RESTRICTED_DEPENDENCY_CRATES . iter ( ) {
417
+ for & krate in restricted_dependency_crates . iter ( ) {
322
418
let pkg = pkg_from_name ( metadata, krate) ;
323
419
let mut bad =
324
420
check_crate_dependencies ( & permitted_dependencies, metadata, & mut visited, pkg) ;
@@ -371,16 +467,12 @@ fn check_crate_dependencies<'a>(
371
467
}
372
468
373
469
/// Prevents multiple versions of some expensive crates.
374
- fn check_crate_duplicate ( metadata : & Metadata , bad : & mut bool ) {
375
- const FORBIDDEN_TO_HAVE_DUPLICATES : & [ & str ] = & [
376
- // These two crates take quite a long time to build, so don't allow two versions of them
377
- // to accidentally sneak into our dependency graph, in order to ensure we keep our CI times
378
- // under control.
379
- "cargo" ,
380
- "rustc-ap-rustc_ast" ,
381
- ] ;
382
-
383
- for & name in FORBIDDEN_TO_HAVE_DUPLICATES {
470
+ fn check_crate_duplicate (
471
+ metadata : & Metadata ,
472
+ forbidden_to_have_duplicates : & [ & str ] ,
473
+ bad : & mut bool ,
474
+ ) {
475
+ for & name in forbidden_to_have_duplicates {
384
476
let matches: Vec < _ > = metadata. packages . iter ( ) . filter ( |pkg| pkg. name == name) . collect ( ) ;
385
477
match matches. len ( ) {
386
478
0 => {
0 commit comments