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

feat: implement workspace feature unification #15157

Merged
merged 2 commits into from
Feb 11, 2025

Conversation

aliu
Copy link
Contributor

@aliu aliu commented Feb 8, 2025

What does this PR try to resolve?

Adds workspace feature unification for #14774

How should we test and review this PR?

In a workspace that has dependencies with different activated features depending on the packages being built, add the resolver.feature-unification = "workspace" option to .cargo/config.toml. Build the entire workspace with --workspace and then build individual packages, ensuring no dependencies are being recompiled.

Additional information

Originally, the RFC and tracking issue mention some more complex changes required in cargo's dependency/feature resolution phases in order to support workspace feature unification. However, it seems like it also works by just modifying the list of PackageIdSpecs passed to the workspace resolver to include all workspace members, and then using the original list of specs when generating the build units. I'm wondering if I missed something because this change feels a bit too simple...

I tested it on a fairly large workspace containing about 100 packages and didn't see any recompilations when building with different sets of packages. I also added an integration test that verifies the correct features are enabled. If there are any other test cases I should include, please let me know and I'll try to add it.

@rustbot
Copy link
Collaborator

rustbot commented Feb 8, 2025

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @weihanglo (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added A-configuration Area: cargo config files and env vars A-workspaces Area: workspaces S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 8, 2025
@epage
Copy link
Contributor

epage commented Feb 8, 2025

A couple of high level comments

  • This will need to start as unstable. We generally have tests to make sure the feature is correctly gated
  • We prefer for PRs to add tests in a commit before the feature, with the tests passing. Then the commit that adds the feature updates the tests to still pass
  • We should have tests for any relevant cases from the RFC, e.g. cargo install is called out

@weihanglo
Copy link
Member

To add, for cargo install, according to the RFC, the field should not apply the behavior to cargo install.

This field will not apply to cargo install to match the behavior of resolver.incompatible-rust-versions.

src/cargo/core/workspace.rs Outdated Show resolved Hide resolved
src/cargo/ops/cargo_compile/mod.rs Outdated Show resolved Hide resolved
tests/testsuite/feature_unification.rs Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

For adding new unstable configurations, see

We usually also add an unstable doc whenever we add a new unstable feature. The doc draft has been written in the RFC. Feel free to copy and adjust. If you feel writing doc is too much a burden, let us know we can do it in a follow-up PR.

@aliu
Copy link
Contributor Author

aliu commented Feb 9, 2025

Thank you @epage and @weihanglo for the quick feedback! This is my first PR to cargo, so apologies if I didn't get some things right regarding the process, etc. I will try to address the comments and push an update today.

@aliu
Copy link
Contributor Author

aliu commented Feb 9, 2025

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 9, 2025
@aliu aliu force-pushed the feature-unification branch from d14e1df to f5ebb8a Compare February 11, 2025 03:18
@rustbot rustbot added A-unstable Area: nightly unstable support Command-fix Command-install labels Feb 11, 2025
@aliu aliu force-pushed the feature-unification branch 2 times, most recently from 2ee949b to fdf0feb Compare February 11, 2025 05:15
@aliu aliu force-pushed the feature-unification branch from fdf0feb to a471adb Compare February 11, 2025 06:10
@aliu
Copy link
Contributor Author

aliu commented Feb 11, 2025

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. labels Feb 11, 2025
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Looks awesome! Thank you for the contribution.

@weihanglo weihanglo added this pull request to the merge queue Feb 11, 2025
Merged via the queue into rust-lang:master with commit 321f14e Feb 11, 2025
21 checks passed
@weihanglo
Copy link
Member

@aliu if you want to continue working on #14774, feel free to @rustbot claim it

@aliu aliu deleted the feature-unification branch February 11, 2025 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-configuration Area: cargo config files and env vars A-unstable Area: nightly unstable support A-workspaces Area: workspaces Command-fix Command-install 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.

4 participants