@@ -43,6 +43,9 @@ const EXCEPTIONS: &[(&str, &str)] = &[
4343 ( "arrayref" , "BSD-2-Clause" ) , // cargo-miri/directories/.../rust-argon2 (redox)
4444 ( "instant" , "BSD-3-Clause" ) , // rustc_driver/tracing-subscriber/parking_lot
4545 ( "snap" , "BSD-3-Clause" ) , // rustc
46+ ] ;
47+
48+ const RUNTIME_EXCEPTIONS : & [ ( & str , & str ) ] = & [
4649 // FIXME: this dependency violates the documentation comment above:
4750 ( "fortanix-sgx-abi" , "MPL-2.0" ) , // libstd but only for `sgx` target
4851] ;
@@ -79,7 +82,6 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
7982 "chalk-ir" ,
8083 "cloudabi" ,
8184 "cmake" ,
82- "compiler_builtins" ,
8385 "crc32fast" ,
8486 "crossbeam-deque" ,
8587 "crossbeam-epoch" ,
@@ -88,15 +90,13 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
8890 "datafrog" ,
8991 "difference" ,
9092 "digest" ,
91- "dlmalloc" ,
9293 "either" ,
9394 "ena" ,
9495 "env_logger" ,
9596 "expect-test" ,
9697 "fake-simd" ,
9798 "filetime" ,
9899 "flate2" ,
99- "fortanix-sgx-abi" ,
100100 "fuchsia-zircon" ,
101101 "fuchsia-zircon-sys" ,
102102 "generic-array" ,
@@ -144,7 +144,6 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
144144 "rand_core" ,
145145 "rand_hc" ,
146146 "rand_pcg" ,
147- "rand_xorshift" ,
148147 "redox_syscall" ,
149148 "regex" ,
150149 "regex-syntax" ,
@@ -190,6 +189,37 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
190189 "winapi-x86_64-pc-windows-gnu" ,
191190] ;
192191
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+
193223/// Dependency checks.
194224///
195225/// `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) {
200230 . manifest_path ( root. join ( "Cargo.toml" ) )
201231 . features ( cargo_metadata:: CargoOpt :: AllFeatures ) ;
202232 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) ;
205235 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.
206246}
207247
208248/// Check that all licenses are in the valid list in `LICENSES`.
209249///
210250/// 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+ ) {
212257 // Validate the EXCEPTIONS list hasn't changed.
213- for ( name, license) in EXCEPTIONS {
258+ for ( name, license) in exceptions {
214259 // Check that the package actually exists.
215260 if !metadata. packages . iter ( ) . any ( |p| p. name == * name) {
216261 println ! (
@@ -257,8 +302,8 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
257302 }
258303 }
259304
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 ( ) } ;
262307
263308 // Check if any package does not have a valid license.
264309 for pkg in & metadata. packages {
@@ -295,9 +340,14 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
295340/// `true` if a check failed.
296341///
297342/// 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+ ) {
299349 // Check that the PERMITTED_DEPENDENCIES does not have unused entries.
300- for name in PERMITTED_DEPENDENCIES {
350+ for name in permitted {
301351 if !metadata. packages . iter ( ) . any ( |p| p. name == * name) {
302352 println ! (
303353 "could not find allowed package `{}`\n \
@@ -308,12 +358,12 @@ fn check_dependencies(metadata: &Metadata, bad: &mut bool) {
308358 }
309359 }
310360 // 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 ( ) ;
312362
313363 // Check dependencies.
314364 let mut visited = BTreeSet :: new ( ) ;
315365 let mut unapproved = BTreeSet :: new ( ) ;
316- for & krate in RESTRICTED_DEPENDENCY_CRATES . iter ( ) {
366+ for & krate in restricted_dependency_crates . iter ( ) {
317367 let pkg = pkg_from_name ( metadata, krate) ;
318368 let mut bad =
319369 check_crate_dependencies ( & permitted_dependencies, metadata, & mut visited, pkg) ;
0 commit comments