Skip to content

Support multiple artifact dependency aliases to the same package#17067

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

Support multiple artifact dependency aliases to the same package#17067
npmccallum wants to merge 2 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.
Today, Cargo still rejects several of those same-package artifact dependency
forms as duplicate renamed dependencies. This PR closes that gap while keeping
the existing duplicate-name checks for non-artifact dependency cases.

The branch is split into two commits to make the behavior change easier to
review:

  1. test(bindeps): cover same-package duplicate-name behavior

    This commit adds regression tests for the current invariants and does not
    change Cargo behavior. In particular, it locks down the cases where ordinary
    duplicate renamed dependencies, or mixed artifact/non-artifact dependencies,
    must continue to be rejected.

  2. feat(bindeps): support artifact aliases to the same package

    This commit implements the RFC behavior for all-artifact dependency aliases
    to the same package, and updates the affected tests to assert the new
    intended behavior. It keeps artifact environment variables scalar and
    dependency-name-specific, and shares the lib-edge naming logic between build
    graph lowering and cargo metadata so the two paths stay consistent.

Validation performed locally on both commits:

  • cargo fmt --check
  • cargo test -p cargo --lib
  • cargo test -p cargo --test testsuite

Closes #12374

FYI @joshtriplett @Byron

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.
Implement the RFC 3176 model for resolving rust-lang#12374.
A package can now be declared multiple times under different dependency
names, with each alias selecting its own artifact target.

This keeps artifact environment variables scalar and
dependency-name-specific, instead of adding target-list syntax or
list-valued environment variables.

Build graph lowering and cargo metadata share one lib-edge naming helper.
All-artifact aliases keep their concrete names, while mixed
artifact/non-artifact edges continue to use the existing duplicate-name
check.

The tests cover build dependencies, normal dependencies, same-target
sharing, cargo metadata, unit graph output, and the explicit-alias
workflow documented for bindeps.

Closes rust-lang#12374.
@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

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

3 participants