From 812c93e7ee82b7f0292cc3f9f6d220cdf1e01198 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 20 Aug 2025 09:54:39 +0000 Subject: [PATCH 1/2] tidy: Add a check that there are no duplicate runtime dependencies --- src/tools/tidy/src/deps.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 858b058cb7d05..2987f18c880dd 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -592,6 +592,7 @@ pub fn check(root: &Path, cargo: &Path, bless: bool, bad: &mut bool) { if workspace == "library" { check_runtime_license_exceptions(&metadata, bad); + check_runtime_no_duplicate_dependencies(&metadata, bad); checked_runtime_licenses = true; } } @@ -790,6 +791,23 @@ fn check_license_exceptions( } } +fn check_runtime_no_duplicate_dependencies(metadata: &Metadata, bad: &mut bool) { + let mut seen_pkgs = HashSet::new(); + for pkg in &metadata.packages { + if pkg.source.is_none() { + continue; + } + + if !seen_pkgs.insert(&*pkg.name) { + tidy_error!( + bad, + "duplicate package `{}` is not allowed for the standard library", + pkg.name + ); + } + } +} + /// Checks the dependency of `restricted_dependency_crates` at the given path. Changes `bad` to /// `true` if a check failed. /// From 30fa518c612a037ebeb411439ab6b3c7d89807d1 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 20 Aug 2025 10:02:14 +0000 Subject: [PATCH 2/2] tidy: Add check against proc macros as standard library dependencies They would break cross-compilation. --- src/tools/tidy/src/deps.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 2987f18c880dd..80b6d54ce1c80 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -593,6 +593,7 @@ pub fn check(root: &Path, cargo: &Path, bless: bool, bad: &mut bool) { if workspace == "library" { check_runtime_license_exceptions(&metadata, bad); check_runtime_no_duplicate_dependencies(&metadata, bad); + check_runtime_no_proc_macros(&metadata, bad); checked_runtime_licenses = true; } } @@ -808,6 +809,20 @@ fn check_runtime_no_duplicate_dependencies(metadata: &Metadata, bad: &mut bool) } } +fn check_runtime_no_proc_macros(metadata: &Metadata, bad: &mut bool) { + for pkg in &metadata.packages { + if pkg.targets.iter().any(|target| target.is_proc_macro()) { + tidy_error!( + bad, + "proc macro `{}` is not allowed as standard library dependency.\n\ + Using proc macros in the standard library would break cross-compilation \ + as proc-macros don't get shipped for the host tuple.", + pkg.name + ); + } + } +} + /// Checks the dependency of `restricted_dependency_crates` at the given path. Changes `bad` to /// `true` if a check failed. ///