Skip to content

Commit 26de639

Browse files
committed
Add tidy check for list of proc-macro crate transitive dependencies
1 parent 8742e05 commit 26de639

File tree

2 files changed

+189
-0
lines changed

2 files changed

+189
-0
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/// Holds all direct and indirect dependencies of proc-macro crates in tree. See #134863
2+
pub static CRATES: &[&str] = &[
3+
// tidy-alphabetical-start
4+
"annotate-snippets",
5+
"anstyle",
6+
"autocfg",
7+
"basic-toml",
8+
"bitflags",
9+
"block-buffer",
10+
"bumpalo",
11+
"byteorder",
12+
"cfg-if",
13+
"clap_derive",
14+
"color-print-proc-macro",
15+
"cpufeatures",
16+
"crossbeam-channel",
17+
"crossbeam-deque",
18+
"crossbeam-epoch",
19+
"crossbeam-utils",
20+
"crypto-common",
21+
"darling",
22+
"darling_core",
23+
"darling_macro",
24+
"derive-where",
25+
"derive_builder_core",
26+
"derive_setters",
27+
"digest",
28+
"displaydoc",
29+
"either",
30+
"equivalent",
31+
"fluent-bundle",
32+
"fluent-langneg",
33+
"fluent-syntax",
34+
"fnv",
35+
"foldhash",
36+
"futf",
37+
"futures-macro",
38+
"generic-array",
39+
"getrandom",
40+
"hashbrown",
41+
"heck",
42+
"hermit-abi",
43+
"html5ever",
44+
"icu_provider_macros",
45+
"ident_case",
46+
"indexmap",
47+
"intl-memoizer",
48+
"intl_pluralrules",
49+
"itoa",
50+
"libc",
51+
"lock_api",
52+
"log",
53+
"mac",
54+
"markup5ever",
55+
"memchr",
56+
"mime",
57+
"mime_guess",
58+
"minimal-lexical",
59+
"new_debug_unreachable",
60+
"nom",
61+
"num_cpus",
62+
"once_cell",
63+
"parking_lot",
64+
"parking_lot_core",
65+
"pest",
66+
"pest_generator",
67+
"pest_meta",
68+
"phf",
69+
"phf_codegen",
70+
"phf_generator",
71+
"phf_shared",
72+
"ppv-lite86",
73+
"precomputed-hash",
74+
"proc-macro-hack",
75+
"proc-macro2",
76+
"quote",
77+
"rand",
78+
"rand_chacha",
79+
"rand_core",
80+
"rayon",
81+
"rayon-core",
82+
"redox_syscall",
83+
"rinja_derive",
84+
"rinja_parser",
85+
"rustc-hash",
86+
"rustc-rayon",
87+
"rustc-rayon-core",
88+
"rustc_fluent_macro",
89+
"rustc_index_macros",
90+
"rustc_macros",
91+
"rustc_type_ir_macros",
92+
"rustfmt-config_proc_macro",
93+
"rustversion",
94+
"ryu",
95+
"scopeguard",
96+
"self_cell",
97+
"serde",
98+
"serde_derive",
99+
"serde_json",
100+
"sha2",
101+
"siphasher",
102+
"smallvec",
103+
"stable_deref_trait",
104+
"string_cache",
105+
"string_cache_codegen",
106+
"strsim",
107+
"strum_macros",
108+
"syn",
109+
"synstructure",
110+
"tendril",
111+
"thiserror",
112+
"thiserror-impl",
113+
"tinystr",
114+
"tracing-attributes",
115+
"type-map",
116+
"typenum",
117+
"ucd-trie",
118+
"unic-langid",
119+
"unic-langid-impl",
120+
"unic-langid-macros",
121+
"unic-langid-macros-impl",
122+
"unicase",
123+
"unicode-ident",
124+
"unicode-width",
125+
"utf-8",
126+
"version_check",
127+
"wasi",
128+
"wasm-bindgen-backend",
129+
"wasm-bindgen-macro-support",
130+
"wasm-bindgen-shared",
131+
"windows-bindgen",
132+
"windows-implement",
133+
"windows-interface",
134+
"windows-metadata",
135+
"windows-targets",
136+
"windows_aarch64_gnullvm",
137+
"windows_aarch64_msvc",
138+
"windows_i686_gnu",
139+
"windows_i686_gnullvm",
140+
"windows_i686_msvc",
141+
"windows_x86_64_gnu",
142+
"windows_x86_64_gnullvm",
143+
"windows_x86_64_msvc",
144+
"yoke",
145+
"yoke-derive",
146+
"zerocopy",
147+
"zerocopy-derive",
148+
"zerofrom",
149+
"zerofrom-derive",
150+
"zerovec",
151+
"zerovec-derive",
152+
// tidy-alphabetical-end
153+
];

src/tools/tidy/src/deps.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use std::path::Path;
77
use build_helper::ci::CiEnv;
88
use cargo_metadata::{Metadata, Package, PackageId};
99

10+
#[path = "../../../bootstrap/src/utils/proc_macro_deps.rs"]
11+
mod proc_macro_deps;
12+
1013
/// These are licenses that are allowed for all crates, including the runtime,
1114
/// rustc, tools, etc.
1215
#[rustfmt::skip]
@@ -567,6 +570,8 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
567570
pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
568571
let mut checked_runtime_licenses = false;
569572

573+
check_proc_macro_dep_list(root, cargo, bad);
574+
570575
for &(workspace, exceptions, permitted_deps, submodules) in WORKSPACES {
571576
if has_missing_submodule(root, submodules) {
572577
continue;
@@ -600,6 +605,37 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
600605
assert!(checked_runtime_licenses);
601606
}
602607

608+
/// Ensure the list of proc-macro crate transitive dependencies is up to date
609+
fn check_proc_macro_dep_list(root: &Path, cargo: &Path, bad: &mut bool) {
610+
let mut cmd = cargo_metadata::MetadataCommand::new();
611+
cmd.cargo_path(cargo)
612+
.manifest_path(root.join("Cargo.toml"))
613+
.features(cargo_metadata::CargoOpt::AllFeatures)
614+
.other_options(vec!["--locked".to_owned()]);
615+
let metadata = t!(cmd.exec());
616+
let is_proc_macro_pkg =
617+
|pkg: &&Package| pkg.dependencies.iter().any(|dep| dep.name.as_str() == "proc-macro2");
618+
let mut proc_macro_deps = HashSet::new();
619+
for pkg in metadata.packages.iter().filter(is_proc_macro_pkg) {
620+
deps_of(&metadata, &pkg.id, &mut proc_macro_deps);
621+
}
622+
let proc_macro_deps: HashSet<_> =
623+
proc_macro_deps.into_iter().map(|dep| metadata[dep].name.clone()).collect();
624+
let expected = proc_macro_deps::CRATES.iter().map(|s| s.to_string()).collect::<HashSet<_>>();
625+
for missing in proc_macro_deps.difference(&expected) {
626+
tidy_error!(
627+
bad,
628+
"proc-macro crate dependency `{missing}` is not registered in `src/bootstrap/src/utils/proc_macro_deps.rs`",
629+
);
630+
}
631+
for extra in expected.difference(&proc_macro_deps) {
632+
tidy_error!(
633+
bad,
634+
"`{extra}` is not registered in `src/bootstrap/src/utils/proc_macro_deps.rs`, but is not a proc-macro crate dependency",
635+
);
636+
}
637+
}
638+
603639
/// Used to skip a check if a submodule is not checked out, and not in a CI environment.
604640
///
605641
/// This helps prevent enforcing developers to fetch submodules for tidy.

0 commit comments

Comments
 (0)