Skip to content

Commit 5619a46

Browse files
authored
Rollup merge of #145648 - bjorn3:tidy_deps_stricter, r=davidtwco
Add two tidy dependency checks Deny duplicate dependencies for the standard library as it would almost certainly bloat executables. And deny proc-macro dependencies for the standard library as they would break cross-compilation.
2 parents f49d690 + 30fa518 commit 5619a46

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/tools/tidy/src/deps.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ pub fn check(root: &Path, cargo: &Path, bless: bool, bad: &mut bool) {
592592

593593
if workspace == "library" {
594594
check_runtime_license_exceptions(&metadata, bad);
595+
check_runtime_no_duplicate_dependencies(&metadata, bad);
596+
check_runtime_no_proc_macros(&metadata, bad);
595597
checked_runtime_licenses = true;
596598
}
597599
}
@@ -790,6 +792,37 @@ fn check_license_exceptions(
790792
}
791793
}
792794

795+
fn check_runtime_no_duplicate_dependencies(metadata: &Metadata, bad: &mut bool) {
796+
let mut seen_pkgs = HashSet::new();
797+
for pkg in &metadata.packages {
798+
if pkg.source.is_none() {
799+
continue;
800+
}
801+
802+
if !seen_pkgs.insert(&*pkg.name) {
803+
tidy_error!(
804+
bad,
805+
"duplicate package `{}` is not allowed for the standard library",
806+
pkg.name
807+
);
808+
}
809+
}
810+
}
811+
812+
fn check_runtime_no_proc_macros(metadata: &Metadata, bad: &mut bool) {
813+
for pkg in &metadata.packages {
814+
if pkg.targets.iter().any(|target| target.is_proc_macro()) {
815+
tidy_error!(
816+
bad,
817+
"proc macro `{}` is not allowed as standard library dependency.\n\
818+
Using proc macros in the standard library would break cross-compilation \
819+
as proc-macros don't get shipped for the host tuple.",
820+
pkg.name
821+
);
822+
}
823+
}
824+
}
825+
793826
/// Checks the dependency of `restricted_dependency_crates` at the given path. Changes `bad` to
794827
/// `true` if a check failed.
795828
///

0 commit comments

Comments
 (0)