Skip to content

Leverage the --workspace flag when running cargo command against cargo itself #11987

@weihanglo

Description

@weihanglo

Problem

After #11851 Cargo becomes a Cargo workspace. That means we can dogfood ourselves finally 🎉.

We left some TODOs in that pull request, one of them are making --workspace usable for cargo itself. That is, making cargo build and other subcommands happy with --workspace flag, instead of using -p flag everywhere in our CI workflow yaml.

Some workspace members are platform-dependant inside cargo workspace, i.e., cargo-credential-gnome-secret and friends. We don't really have a good programming way to get the list other than cargo metadata | jq .workspace_members[] -r | cut -d' ' -f1. As a consequence, we expands the list manually in a ugly way:

- run: cargo test -p cargo-test-support
- run: cargo test -p cargo-platform
- run: cargo test -p cargo-util
- run: cargo test -p home
- run: cargo test -p mdman
- run: cargo build -p cargo-credential-1password
- run: cargo build -p cargo-credential-gnome-secret
if: matrix.os == 'ubuntu-latest'
- run: cargo build -p cargo-credential-macos-keychain
if: matrix.os == 'macos-latest'
- run: cargo build -p cargo-credential-wincred
if: matrix.os == 'windows-latest'

We want to make running command like cargo test --workspace as easy as possible to reduce the friction in CI also in contributor experience.

Proposed Solution

In the long term, we could look into #5220 and also the comment here #11987 (comment).

An alternative workaround in the short term would be making those subcrates and dependencies platform specific via conditional compilation. For example, dependencies could be listed in target."cfg(not(windows))".dependencies section. And have a lib.rs doing nothing but delegating to unix/lib.rs or windows/lib.rs with #[cfg(…)], and one of them also does nothing.

Notes

I think at least the follow commands should be able to run with --workspace for cargo itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-building-cargo-itselfArea: issues with building cargoA-infrastructureArea: infrastructure around the cargo repo, ci, releases, etc.A-testing-cargo-itselfArea: cargo's testsC-enhancementCategory: enhancementE-mediumExperience: MediumS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions