Skip to content

Support multiple artifact dependency aliases to the same package#17067

Open
npmccallum wants to merge 5 commits into
rust-lang:masterfrom
npmccallum:master
Open

Support multiple artifact dependency aliases to the same package#17067
npmccallum wants to merge 5 commits into
rust-lang:masterfrom
npmccallum:master

Conversation

@npmccallum

@npmccallum npmccallum commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

This fills in a behavior described by RFC 3176 that was not implemented when artifact dependencies were initially added.

The RFC allows a package to be declared multiple times under different dependency names, with each declaration selecting a different artifact target. Cargo rejected several of those same-package artifact dependency forms as duplicate renamed dependencies. This PR allows the all-artifact cases while keeping the existing duplicate-name checks for mixed artifact/non-artifact dependency cases.

The series is split into reviewable commits:

  1. Add tests for the current duplicate-name behavior.
  2. Extract shared dependency-name helpers in the resolver.
  3. Allow artifact aliases when lowering build and unit graph edges.
  4. Report artifact alias names consistently in cargo metadata.
  5. Document the supported alias form and the lib = true restriction.

The lib = true case still requires Cargo to refer to the package library with one Rust extern crate name. Multiple artifact aliases that would give the library different extern names continue to be rejected.

Closes #12374

FYI @joshtriplett @Byron

@rustbot rustbot added A-dependency-resolution Area: dependency resolution and the resolver A-documenting-cargo-itself Area: Cargo's documentation Command-metadata S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 3, 2026
@rustbot

rustbot commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage, weihanglo

@npmccallum

Copy link
Copy Markdown
Contributor Author

@weihanglo are you able to review this? If not, maybe @ehuss could?

@weihanglo weihanglo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution. Unfortunately, I may not have sufficient bandwidth to do meaningful reviews within this week or next week. Feel free to reassign.

View changes since this review

@npmccallum

Copy link
Copy Markdown
Contributor Author

@rustbot reroll

@rustbot rustbot assigned epage and unassigned weihanglo Jun 24, 2026
@epage

epage commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Note that in general, there is a lot less review bandwidth at this time. Weihang has the most bandwidth and he said he wouldn't be available. We'll see when/if I have time.

@epage epage left a comment

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.

Only had a quick glance at the tests.

The fixes seem to be independent. Can you split them up into smaller commits / reviewable unit?

View changes since this review

Comment thread tests/testsuite/artifact_dep.rs Outdated
authors = []
resolver = "2"

[dependencies.bar]

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 this mimicking existing tests? I at least would prefer we only use inline tables for deps, not standard tables.

Comment thread tests/testsuite/unit_graph.rs Outdated

p.cargo("build --unit-graph -Zunstable-options -Z bindeps")
.masquerade_as_nightly_cargo(&["unit-graph", "bindeps"])
.with_stdout_contains(r#"[..]"index":0,"extern_crate_name":"bar"[..]"#)

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 this mimicking an existing pattern? We try to avoid the _contains functions

@rustbot

This comment has been minimized.

@npmccallum

Copy link
Copy Markdown
Contributor Author

I split this into smaller commits:

  1. current-behavior tests
  2. resolver naming helper
  3. build/unit-graph behavior
  4. metadata behavior
  5. docs

I also adjusted the tests from the inline comments to use inline dependency tables and a structured unit-graph stdout assertion.

@weihanglo

Copy link
Copy Markdown
Member

May have time for this, though let me pick up the RFC first.

Add regression coverage for the current invariant that multiple dependency
declarations to the same package are rejected when they would require
distinct dependency names.

This makes the existing behavior explicit before relaxing the
artifact-dependency cases tracked in rust-lang#12374.
Extract dependency-name calculation so artifact alias handling can use the same extern crate naming rules in build graph lowering and metadata output.
Permit all-artifact aliases to the same package to keep their dependency-specific names when lowering build and unit graph edges.

Mixed artifact and non-artifact dependencies still use the existing duplicate-name check so library dependencies have one extern crate name.
Use the shared dependency-name rules when emitting cargo metadata for artifact aliases to the same package.

Bin-only artifact aliases emit dependency-specific extern names, while lib aliases continue to require a single library dependency name.
Document declaring separate aliases when building artifacts from the same package for multiple target platforms.

Also call out that multiple lib=true aliases must agree on one library extern crate name.
@rustbot

rustbot commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@npmccallum

Copy link
Copy Markdown
Contributor Author

@joshtriplett This is my next highest priority if you have cycles. With this feature, arma can generate PMIs cross-architecture.

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

Labels

A-dependency-resolution Area: dependency resolution and the resolver A-documenting-cargo-itself Area: Cargo's documentation Command-metadata S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

artifact-dependencies doesn't support building binaries for multiple targets

4 participants