@@ -44,12 +44,29 @@ const EXCEPTIONS: &[(&str, &str)] = &[
4444 ( "fortanix-sgx-abi" , "MPL-2.0" ) , // libstd but only for `sgx` target
4545] ;
4646
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+
4764/// These are the root crates that are part of the runtime. The licenses for
4865/// these and all their dependencies *must not* be in the exception list.
4966const RUNTIME_CRATES : & [ & str ] = & [ "std" , "core" , "alloc" , "test" , "panic_abort" , "panic_unwind" ] ;
5067
5168/// Crates whose dependencies must be explicitly permitted.
52- const RESTRICTED_DEPENDENCY_CRATES : & [ & str ] = & [ "rustc_middle " , "rustc_codegen_llvm" ] ;
69+ const RESTRICTED_DEPENDENCY_CRATES : & [ & str ] = & [ "rustc_driver " , "rustc_codegen_llvm" ] ;
5370
5471/// Crates rustc is allowed to depend on. Avoid adding to the list if possible.
5572///
@@ -72,7 +89,10 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
7289 "cc" ,
7390 "cfg-if" ,
7491 "chalk-derive" ,
92+ "chalk-engine" ,
7593 "chalk-ir" ,
94+ "chalk-solve" ,
95+ "chrono" ,
7696 "cmake" ,
7797 "compiler_builtins" ,
7898 "cpuid-bool" ,
@@ -92,6 +112,7 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
92112 "expect-test" ,
93113 "fake-simd" ,
94114 "filetime" ,
115+ "fixedbitset" ,
95116 "flate2" ,
96117 "fortanix-sgx-abi" ,
97118 "fuchsia-zircon" ,
@@ -107,13 +128,15 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
107128 "indexmap" ,
108129 "instant" ,
109130 "itertools" ,
131+ "itoa" ,
110132 "jobserver" ,
111133 "kernel32-sys" ,
112134 "lazy_static" ,
113135 "libc" ,
114136 "libz-sys" ,
115137 "lock_api" ,
116138 "log" ,
139+ "matchers" ,
117140 "maybe-uninit" ,
118141 "md-5" ,
119142 "measureme" ,
@@ -123,13 +146,16 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
123146 "memoffset" ,
124147 "miniz_oxide" ,
125148 "num_cpus" ,
149+ "num-integer" ,
150+ "num-traits" ,
126151 "object" ,
127152 "once_cell" ,
128153 "opaque-debug" ,
129154 "parking_lot" ,
130155 "parking_lot_core" ,
131156 "pathdiff" ,
132157 "perf-event-open-sys" ,
158+ "petgraph" ,
133159 "pin-project-lite" ,
134160 "pkg-config" ,
135161 "polonius-engine" ,
@@ -147,22 +173,28 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
147173 "rand_xorshift" ,
148174 "redox_syscall" ,
149175 "regex" ,
176+ "regex-automata" ,
150177 "regex-syntax" ,
151178 "remove_dir_all" ,
179+ "rls-data" ,
180+ "rls-span" ,
152181 "rustc-demangle" ,
153182 "rustc-hash" ,
154183 "rustc-rayon" ,
155184 "rustc-rayon-core" ,
156185 "rustc_version" ,
186+ "ryu" ,
157187 "scoped-tls" ,
158188 "scopeguard" ,
159189 "semver" ,
160190 "semver-parser" ,
161191 "serde" ,
162192 "serde_derive" ,
193+ "serde_json" ,
163194 "sha-1" ,
164195 "sha2" ,
165196 "smallvec" ,
197+ "sharded-slab" ,
166198 "snap" ,
167199 "stable_deref_trait" ,
168200 "stacker" ,
@@ -172,9 +204,15 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
172204 "termcolor" ,
173205 "termize" ,
174206 "thread_local" ,
207+ "time" ,
208+ "tinyvec" ,
175209 "tracing" ,
176210 "tracing-attributes" ,
177211 "tracing-core" ,
212+ "tracing-log" ,
213+ "tracing-serde" ,
214+ "tracing-subscriber" ,
215+ "tracing-tree" ,
178216 "typenum" ,
179217 "unicode-normalization" ,
180218 "unicode-script" ,
@@ -193,6 +231,59 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
193231 "yansi-term" ,
194232] ;
195233
234+ const PERMITTED_CRANELIFT_DEPENDENCIES : & [ & str ] = & [
235+ "anyhow" ,
236+ "ar" ,
237+ "autocfg" ,
238+ "bitflags" ,
239+ "byteorder" ,
240+ "cfg-if" ,
241+ "cranelift-bforest" ,
242+ "cranelift-codegen" ,
243+ "cranelift-codegen-meta" ,
244+ "cranelift-codegen-shared" ,
245+ "cranelift-entity" ,
246+ "cranelift-frontend" ,
247+ "cranelift-jit" ,
248+ "cranelift-module" ,
249+ "cranelift-native" ,
250+ "cranelift-object" ,
251+ "crc32fast" ,
252+ "errno" ,
253+ "errno-dragonfly" ,
254+ "gcc" ,
255+ "gimli" ,
256+ "hashbrown" ,
257+ "indexmap" ,
258+ "libc" ,
259+ "libloading" ,
260+ "log" ,
261+ "mach" ,
262+ "object" ,
263+ "proc-macro2" ,
264+ "quote" ,
265+ "regalloc" ,
266+ "region" ,
267+ "rustc-hash" ,
268+ "smallvec" ,
269+ "syn" ,
270+ "target-lexicon" ,
271+ "thiserror" ,
272+ "thiserror-impl" ,
273+ "unicode-xid" ,
274+ "winapi" ,
275+ "winapi-i686-pc-windows-gnu" ,
276+ "winapi-x86_64-pc-windows-gnu" ,
277+ ] ;
278+
279+ const FORBIDDEN_TO_HAVE_DUPLICATES : & [ & str ] = & [
280+ // These two crates take quite a long time to build, so don't allow two versions of them
281+ // to accidentally sneak into our dependency graph, in order to ensure we keep our CI times
282+ // under control.
283+ "cargo" ,
284+ "rustc-ap-rustc_ast" ,
285+ ] ;
286+
196287/// Dependency checks.
197288///
198289/// `root` is path to the directory with the root `Cargo.toml` (for the workspace). `cargo` is path
@@ -203,17 +294,39 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
203294 . manifest_path ( root. join ( "Cargo.toml" ) )
204295 . features ( cargo_metadata:: CargoOpt :: AllFeatures ) ;
205296 let metadata = t ! ( cmd. exec( ) ) ;
206- check_exceptions ( & metadata, bad) ;
207- check_dependencies ( & metadata, bad) ;
208- check_crate_duplicate ( & metadata, bad) ;
297+ let runtime_ids = compute_runtime_crates ( & metadata) ;
298+ check_exceptions ( & metadata, EXCEPTIONS , runtime_ids, bad) ;
299+ check_dependencies ( & metadata, PERMITTED_DEPENDENCIES , RESTRICTED_DEPENDENCY_CRATES , bad) ;
300+ check_crate_duplicate ( & metadata, FORBIDDEN_TO_HAVE_DUPLICATES , bad) ;
301+
302+ // Check rustc_codegen_cranelift independently as it has it's own workspace.
303+ let mut cmd = cargo_metadata:: MetadataCommand :: new ( ) ;
304+ cmd. cargo_path ( cargo)
305+ . manifest_path ( root. join ( "compiler/rustc_codegen_cranelift/Cargo.toml" ) )
306+ . features ( cargo_metadata:: CargoOpt :: AllFeatures ) ;
307+ let metadata = t ! ( cmd. exec( ) ) ;
308+ let runtime_ids = HashSet :: new ( ) ;
309+ check_exceptions ( & metadata, EXCEPTIONS_CRANELIFT , runtime_ids, bad) ;
310+ check_dependencies (
311+ & metadata,
312+ PERMITTED_CRANELIFT_DEPENDENCIES ,
313+ & [ "rustc_codegen_cranelift" ] ,
314+ bad,
315+ ) ;
316+ check_crate_duplicate ( & metadata, & [ ] , bad) ;
209317}
210318
211319/// Check that all licenses are in the valid list in `LICENSES`.
212320///
213321/// Packages listed in `EXCEPTIONS` are allowed for tools.
214- fn check_exceptions ( metadata : & Metadata , bad : & mut bool ) {
322+ fn check_exceptions (
323+ metadata : & Metadata ,
324+ exceptions : & [ ( & str , & str ) ] ,
325+ runtime_ids : HashSet < & PackageId > ,
326+ bad : & mut bool ,
327+ ) {
215328 // Validate the EXCEPTIONS list hasn't changed.
216- for ( name, license) in EXCEPTIONS {
329+ for ( name, license) in exceptions {
217330 // Check that the package actually exists.
218331 if !metadata. packages . iter ( ) . any ( |p| p. name == * name) {
219332 tidy_error ! (
@@ -225,13 +338,6 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
225338 }
226339 // Check that the license hasn't changed.
227340 for pkg in metadata. packages . iter ( ) . filter ( |p| p. name == * name) {
228- if pkg. name == "fuchsia-cprng" {
229- // This package doesn't declare a license expression. Manual
230- // inspection of the license file is necessary, which appears
231- // to be BSD-3-Clause.
232- assert ! ( pkg. license. is_none( ) ) ;
233- continue ;
234- }
235341 match & pkg. license {
236342 None => {
237343 tidy_error ! (
@@ -242,14 +348,6 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
242348 }
243349 Some ( pkg_license) => {
244350 if pkg_license. as_str ( ) != * license {
245- if * name == "crossbeam-queue"
246- && * license == "MIT/Apache-2.0 AND BSD-2-Clause"
247- {
248- // We have two versions of crossbeam-queue and both
249- // are fine.
250- continue ;
251- }
252-
253351 println ! ( "dependency exception `{}` license has changed" , name) ;
254352 println ! ( " previously `{}` now `{}`" , license, pkg_license) ;
255353 println ! ( " update EXCEPTIONS for the new license" ) ;
@@ -260,8 +358,7 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
260358 }
261359 }
262360
263- let exception_names: Vec < _ > = EXCEPTIONS . iter ( ) . map ( |( name, _license) | * name) . collect ( ) ;
264- let runtime_ids = compute_runtime_crates ( metadata) ;
361+ let exception_names: Vec < _ > = exceptions. iter ( ) . map ( |( name, _license) | * name) . collect ( ) ;
265362
266363 // Check if any package does not have a valid license.
267364 for pkg in & metadata. packages {
@@ -296,9 +393,14 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
296393/// `true` if a check failed.
297394///
298395/// Specifically, this checks that the dependencies are on the `PERMITTED_DEPENDENCIES`.
299- fn check_dependencies ( metadata : & Metadata , bad : & mut bool ) {
396+ fn check_dependencies (
397+ metadata : & Metadata ,
398+ permitted_dependencies : & [ & ' static str ] ,
399+ restricted_dependency_crates : & [ & ' static str ] ,
400+ bad : & mut bool ,
401+ ) {
300402 // Check that the PERMITTED_DEPENDENCIES does not have unused entries.
301- for name in PERMITTED_DEPENDENCIES {
403+ for name in permitted_dependencies {
302404 if !metadata. packages . iter ( ) . any ( |p| p. name == * name) {
303405 tidy_error ! (
304406 bad,
@@ -309,12 +411,12 @@ fn check_dependencies(metadata: &Metadata, bad: &mut bool) {
309411 }
310412 }
311413 // Get the list in a convenient form.
312- let permitted_dependencies: HashSet < _ > = PERMITTED_DEPENDENCIES . iter ( ) . cloned ( ) . collect ( ) ;
414+ let permitted_dependencies: HashSet < _ > = permitted_dependencies . iter ( ) . cloned ( ) . collect ( ) ;
313415
314416 // Check dependencies.
315417 let mut visited = BTreeSet :: new ( ) ;
316418 let mut unapproved = BTreeSet :: new ( ) ;
317- for & krate in RESTRICTED_DEPENDENCY_CRATES . iter ( ) {
419+ for & krate in restricted_dependency_crates . iter ( ) {
318420 let pkg = pkg_from_name ( metadata, krate) ;
319421 let mut bad =
320422 check_crate_dependencies ( & permitted_dependencies, metadata, & mut visited, pkg) ;
@@ -367,16 +469,12 @@ fn check_crate_dependencies<'a>(
367469}
368470
369471/// Prevents multiple versions of some expensive crates.
370- fn check_crate_duplicate ( metadata : & Metadata , bad : & mut bool ) {
371- const FORBIDDEN_TO_HAVE_DUPLICATES : & [ & str ] = & [
372- // These two crates take quite a long time to build, so don't allow two versions of them
373- // to accidentally sneak into our dependency graph, in order to ensure we keep our CI times
374- // under control.
375- "cargo" ,
376- "rustc-ap-rustc_ast" ,
377- ] ;
378-
379- for & name in FORBIDDEN_TO_HAVE_DUPLICATES {
472+ fn check_crate_duplicate (
473+ metadata : & Metadata ,
474+ forbidden_to_have_duplicates : & [ & str ] ,
475+ bad : & mut bool ,
476+ ) {
477+ for & name in forbidden_to_have_duplicates {
380478 let matches: Vec < _ > = metadata. packages . iter ( ) . filter ( |pkg| pkg. name == name) . collect ( ) ;
381479 match matches. len ( ) {
382480 0 => {
@@ -456,16 +554,7 @@ fn normal_deps_of_r<'a>(
456554 . iter ( )
457555 . find ( |n| & n. id == pkg_id)
458556 . unwrap_or_else ( || panic ! ( "could not find `{}` in resolve" , pkg_id) ) ;
459- // Don't care about dev-dependencies.
460- // Build dependencies *shouldn't* matter unless they do some kind of
461- // codegen. For now we'll assume they don't.
462- let deps = node. deps . iter ( ) . filter ( |node_dep| {
463- node_dep
464- . dep_kinds
465- . iter ( )
466- . any ( |kind_info| kind_info. kind == cargo_metadata:: DependencyKind :: Normal )
467- } ) ;
468- for dep in deps {
557+ for dep in & node. deps {
469558 normal_deps_of_r ( resolve, & dep. pkg , result) ;
470559 }
471560}
0 commit comments