Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
4 tasks done
weihanglo opened this issue Apr 17, 2023 · 8 comments
Closed
4 tasks done
Labels
A-building-cargo-itself Area: issues with building cargo A-infrastructure Area: infrastructure around the cargo repo, ci, releases, etc. A-testing-cargo-itself Area: cargo's tests C-enhancement Category: enhancement E-medium Experience: Medium S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@weihanglo
Copy link
Member

weihanglo commented Apr 17, 2023

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.

@weihanglo weihanglo added A-building-cargo-itself Area: issues with building cargo A-workspaces Area: workspaces C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` A-testing-cargo-itself Area: cargo's tests labels Apr 17, 2023
@epage
Copy link
Contributor

epage commented Apr 17, 2023

I feel like I'm missing the distinction between #11526 and #5220, they look like duplicates to me. I also feel that conceptually, conditional workspace members are a bad idea and both should be rejected. As the syntax is laid out, I read it as cargo resolving differently depending on the platform which means the lockfile is no longer cross-platform.

For me, I'd like a variant of #9406 which is instead package.required-target which behaves like <build-target>.required-features in that we automatically skip those packages if we aren't building for the right target. We could also skip resolving any target-specific dependencies that do not match package.required-target or package.forced-target, helping in cases like #7058 (and the related minimal lockfile issues).

#9406 and required-target remind me of rust-lang/rfcs#3374 and required-features.

That said, I see this as short-term and long-term. Longer-term, we should do something like this but we likely don't want to wait on design and stablizxation, so we should do conditional builds in the short term.

@weihanglo weihanglo added C-enhancement Category: enhancement and removed C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` labels Apr 17, 2023
@weihanglo
Copy link
Member Author

Totally valid. I was waiting for a response from #11526 but no. Closed.

And yep, clarified the short-term and long-term fixes in the PR descriptions. Thanks for the reply!

bors added a commit that referenced this issue Apr 18, 2023
fix: Allow win/mac credential managers to build on all platforms

### What does this PR try to resolve?

This is a step towards #11987 by making two of the platform-specific credential managers build on all platforms using `cfg`.

I haven't done `gnome-secret` yet because that is more of an oddball in that it isn't just platforms-specific but dependent on what is installed on that platform.

### How should we test and review this PR?

```console
$ cargo check --workspace --exclude cargo-credential-gnome-secret
```

Note that the commits are broken down so you can view the movements of code separate from the functionality being changed.

### Additional information

Other information you want to mention in this PR, such as prior arts,
future extensions, an unresolved problem, or a TODO list.
-->
<!-- homu-ignore:end -->
@weihanglo weihanglo added S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review A-infrastructure Area: infrastructure around the cargo repo, ci, releases, etc. and removed A-workspaces Area: workspaces labels Apr 24, 2023
@heisen-li
Copy link
Contributor

I'll try to solve the cargo test --workspace for cargo itself.

@weihanglo weihanglo added the E-medium Experience: Medium label May 27, 2023
@NanthR
Copy link

NanthR commented Jun 11, 2023

Hey, I wanted to work on this. I just had a couple of questions before I get started.

package.required-target which behaves like <build-target>.required-features

When you say target, this is talking about platform targets, correct?

@weihanglo
Copy link
Member Author

weihanglo commented Jun 11, 2023

When you say target, this is talking about platform targets, correct?

Yes. Please read relevant issues to track their progress.

This pull request is more like blocked on other pull requests or features. For exammple, I don't think there is an easy way to skip cargo-credential-gnome-secret without explicit exclusion, like cargo test --workspace --exclude "cargo-credential-gnome-secret". I don't think there is much we can do at this moment. Maybe only focus on reducing CI yaml? Anyway, feel free to drop your idea.

@NanthR
Copy link

NanthR commented Jun 11, 2023

Ok. Thanks. I was just thinking of adding an option to the package field to set the required platforms and having that be the filter of whether a package needs to be built. I read through the previous suggestions, and from my understanding, this is what seems to be the expected solution?

@weihanglo
Copy link
Member Author

Thanks for being interested in this! However required-targets is just one of the proposed solutions out there. We haven't decided on a proper way to solve this issue.

Note that this is labeled as A-infrastructure, meaning that it focuses on making cargo the project infra better with existing functionality in cargo. If we want to resolve this issue with new features, please discuss in their own issues respectively, or open a new issue for a new feature proposal.

Sorry for the confusion 😔.

@weihanglo weihanglo added S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. and removed S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review labels Jun 11, 2023
bors added a commit that referenced this issue Jul 11, 2023
chore(ci): Automatically test new packages by using `--workspace`

### What does this PR try to resolve?

This is a part of #11987 that was unblocked by #12321 and #11993

### How should we test and review this PR?

Relying on CI to verify this

I'd prefer to move the `cargo test --workspace` step earlier but we run out of disk space if we do (we currently only have 661 MB of headroom of windows-gnu)

See the individual commits for smaller chunks and explanations for why changes were made.
bors added a commit that referenced this issue Jul 11, 2023
chore(ci): Automatically test new packages by using `--workspace`

### What does this PR try to resolve?

This is a part of #11987 that was unblocked by #12321 and #11993

### How should we test and review this PR?

Relying on CI to verify this

I'd prefer to move the `cargo test --workspace` step earlier but we run out of disk space if we do (we currently only have 661 MB of headroom of windows-gnu)

See the individual commits for smaller chunks and explanations for why changes were made.
bors added a commit that referenced this issue Jul 11, 2023
chore(ci): Automatically test new packages by using `--workspace`

### What does this PR try to resolve?

This is a part of #11987 that was unblocked by #12321 and #11993

### How should we test and review this PR?

Relying on CI to verify this

I'd prefer to move the `cargo test --workspace` step earlier but we run out of disk space if we do (we currently only have 661 MB of headroom of windows-gnu)

See the individual commits for smaller chunks and explanations for why changes were made.
@weihanglo
Copy link
Member Author

weihanglo commented Nov 27, 2023

This should be resolved by [lints] stabilization and conditional compilation for cargo-credential-* crates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-building-cargo-itself Area: issues with building cargo A-infrastructure Area: infrastructure around the cargo repo, ci, releases, etc. A-testing-cargo-itself Area: cargo's tests C-enhancement Category: enhancement E-medium Experience: Medium S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

4 participants