Skip to content

rfc: duplicate dep handling#3230

Open
justus-camp-microsoft wants to merge 2 commits intomicrosoft:mainfrom
justus-camp-microsoft:eliminate_duplicate_deps
Open

rfc: duplicate dep handling#3230
justus-camp-microsoft wants to merge 2 commits intomicrosoft:mainfrom
justus-camp-microsoft:eliminate_duplicate_deps

Conversation

@justus-camp-microsoft
Copy link
Copy Markdown
Contributor

No description provided.

@justus-camp-microsoft justus-camp-microsoft requested a review from a team as a code owner April 8, 2026 18:13
Copilot AI review requested due to automatic review settings April 8, 2026 18:13
// where cargo gives them distinct symbol names, or crates that are
// only used at build time. Add entries here only when the duplicate
// cannot be reasonably unified.
let allowed: std::collections::BTreeSet<&str> = [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these not cause reproducible build issues?


let sh = XtaskShell::new()?;
let output = sh
.cmd("cargo")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be easier to parse our Cargo.lock instead?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new cargo xtask fmt pass intended to detect duplicate crate versions (to improve reproducibility), and updates a few workspace dependencies/patches to eliminate known duplicates (notably base64/pbjson and nix).

Changes:

  • Add a new DuplicateDeps fmt pass that runs cargo tree --duplicates and fails when “problematic” duplicates are found.
  • Update workspace dependencies (nix, rustyline) and [patch.crates-io] entries (pbjson*, gptman) to unify versions and remove duplicates.
  • Refresh Cargo.lock accordingly (including removal of base64 0.13.1).

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
xtask/src/tasks/fmt/mod.rs Wires the new DuplicateDeps pass into the default fmt pass list.
xtask/src/tasks/fmt/duplicate_deps.rs Implements the duplicate-dependency detection logic and a small parser unit test.
Cargo.toml Bumps/selects dependencies and adds/updates patches to unify transitive versions.
Cargo.lock Lockfile updates reflecting the dependency unification and bumps.

Comment on lines +91 to +96
// Any duplicate non-proc-macro crate with the same package name
// can cause nondeterministic function ordering in LLVM's fat LTO
// pass, regardless of how different the versions are.
let versions_str: Vec<_> = versions.iter().map(|s| s.as_str()).collect();
problems.push(format!("{name}: {}", versions_str.join(", ")));
}
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pass currently treats any duplicate non-proc-macro crate name as a problem (unless allowlisted), but the module docs and the error message indicate only duplicates with the same “effective major” (or name-colliding versions) are problematic. This mismatch will either produce false positives (failing on benign cross-major duplicates) or under-enforce the intended rule—please align the implementation with the documented criteria (e.g., group versions by effective-major and only flag duplicates within the same group, or update the docs/message to match the actual policy).

Copilot uses AI. Check for mistakes.
Comment on lines +63 to +67
// Crates that are known to have multiple versions and are acceptable.
// These are typically different major versions (e.g., bitflags 1 vs 2)
// where cargo gives them distinct symbol names, or crates that are
// only used at build time. Add entries here only when the duplicate
// cannot be reasonably unified.
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The allowlist is keyed only by crate name, so it will also suppress duplicates within the same (effective) major for those crates (e.g., two different 2.x versions of bitflags), even though the surrounding comments justify these entries as cross-major coexistence. Consider making the allowlist version-aware (name + effective-major), or checking effective-major first and only skipping entries where the duplicates are known-safe (cross-major / build-only).

Copilot uses AI. Check for mistakes.
//! Check for duplicate crate versions that can cause nondeterministic builds.
//!
//! When multiple versions of the same crate (by package name) are linked into
//! the final binary, LLVM's fat LTO pass may order them nondeterministically
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no codegen option to fix this instead? I'm surprised something like codegen_units=1 doesn't handle this already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants