Skip to content

Teach cargo rustc to handle multiple targets and workspaces better #15733

@LunNova

Description

@LunNova

Problem

cargo rustc is inconsistent about when it will run.

  1. cargo rustc in a workspace with multiple members will not run, erroring with error: manifest path './Cargo.toml' is a virtual manifest, but this command requires running against an actual package in this workspace

  2. cargo rustc -p some-member --lib will run, invoking rustc once if there's a lib target.

  3. cargo rustc -p some-member --all-targets will run, invoking rustc multiple times if there are multiple targets within that member.

  4. cargo rustc -p some-member --lib -- -L/some/dir will run, invoking rustc once with -L/some/dir as an argument

  5. cargo rustc -p some-member --all-targets -- -L/some/dir will not run, erroring with extra arguments to rustc can only be passed to one target, consider filtering

It's not clear why 1. and 5. are prohibited, the behavior here seems somewhat arbitrary compared with other commands like cargo check.
If we can already run rustc multiple times when a member has multiple targets, why can't we run it multiple times on multiple workspace members?
If we can already run rustc once with an additional flag when there is one target, why can't we run it with an additional flag when there are multiple targets?

Related: #2642. It's likely things have changed since then; it was raised in 2016.

Proposed Solution

  1. Teach cargo rustc to run on multiple members in a workspace.
  2. Teach cargo rustc to pass additional flags even when multiple targets are selected.

I don't think either of these would be a breaking change.

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-rustcS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions