Skip to content

implement package feature unification - #15684

Merged
epage merged 5 commits into
rust-lang:masterfrom
mladedav:dm/unification-package
Jul 2, 2025
Merged

epage merged 5 commits into
rust-lang:masterfrom
mladedav:dm/unification-package

Conversation

@mladedav

@mladedav mladedav commented Jun 19, 2025 •

Copy link
Copy Markdown
Contributor

View all comments

What does this PR try to resolve?

Implements another part of feature unification (#14774, rfc). The workspace option was implemented in #15157, this adds the package option.

How to test and review this PR?

The important change is changing WorkspaceResolve so it can contain multiple ResolvedFeatures. Along with that, it also needs to know which specs those features are resolved for. This was used in several other places:

  • cargo fix --edition (from 2018 to 2021) - I think it should be ok to disallow using cargo fix --edition when someone already uses this feature.
  • building std - it should be safe to assume std is not using this feature so I just unwrap there. I'm not sure if some attempt to later feature unification would be better.
  • cargo tree - I just use the first feature set. This is definitely not ideal, but I'm not entirely sure what's the correct solution here. Printing multiple trees? Disallowing this, forcing users to select only one package?

Based on comments in #15157 I've added tests first with selected feature unification and then changed that after implementation. I'm not sure if that's how you expect the tests to be added first, if not, I can change the history.

I've expanded the test checking that this is ignored for cargo install although it should work the same way even if it is not ignored (selected and package are the same thing when just one package is selected).

@rustbot

rustbot commented Jun 19, 2025

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

@rustbot rustbot added A-configuration Area: cargo config files and env vars A-documenting-cargo-itself Area: Cargo's documentation Command-fix Command-tree S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 19, 2025
@mladedav
mladedav force-pushed the dm/unification-package branch from ad48f18 to e94564d Compare June 19, 2025 21:41
Comment thread src/doc/src/reference/unstable.md Resolved
Comment thread tests/testsuite/feature_unification.rs Resolved
Comment thread src/cargo/ops/fix/mod.rs Resolved
Comment thread src/cargo/ops/fix/mod.rs Resolved
Comment thread src/cargo/ops/resolve.rs Resolved
Comment thread src/cargo/ops/tree/mod.rs Resolved
@mladedav mladedav changed the title implement projects feature unification implement package feature unification Jun 19, 2025
@mladedav
mladedav force-pushed the dm/unification-package branch from e94564d to c6090d5 Compare June 19, 2025 21:53
@epage

epage commented Jun 19, 2025

Copy link
Copy Markdown
Contributor

Thanks for moving this forward!

@mladedav
mladedav force-pushed the dm/unification-package branch from c6090d5 to e5a3134 Compare June 20, 2025 20:13
@epage

epage commented Jun 20, 2025

Copy link
Copy Markdown
Contributor

Feel free to edit the commits as needed

Comment thread tests/testsuite/feature_unification.rs Resolved
@mladedav
mladedav force-pushed the dm/unification-package branch 3 times, most recently from b10f5d9 to 2457810 Compare June 23, 2025 06:59
@mladedav

Copy link
Copy Markdown
Contributor Author

I've also just added a test with weak dependencies, which works. I tried to also add namespaced dep: features, but those seem to not be unified (#15694) so I'm ignoring that, but I guess that might also go towards the feature unification's unresolved questions.

@epage

epage commented Jun 24, 2025

Copy link
Copy Markdown
Contributor

Just need to double check on one question (#15684 (comment)) but otherwise, this looks good. Thanks for your work on this and patience through the review feedback!

@mladedav
mladedav force-pushed the dm/unification-package branch 2 times, most recently from cd1cff4 to 20021a9 Compare June 27, 2025 11:33
@mladedav

Copy link
Copy Markdown
Contributor Author

Thanks for your work on this and patience through the review feedback!

Honestly, this has been a blast. I wouldn't say I needed pretty much any patience with how fast you were reacting to each iteration. Thanks for the time and reviews!

Comment on lines +1150 to +1088
#[cargo_test]
fn package_feature_unification_grandchild_cli_features() {
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
resolver = "2"
members = ["parent", "child", "grandchild"]
"#,
)
.file(
"grandchild/Cargo.toml",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Whats the intention of this test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried to cover what you were talking about regarding turning on features of non-selected dependency crates inside a workspace. I thought it would be different in some cases based on feature-unification but it's consistent.

Do you want me to remove this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are three cases for foo in foo/bar

  1. A workspace member
  2. A direct dep of a workspace member
  3. An indirect dep of a workspace member

In #15684 (comment), I was talking about (2) while this test covers (1).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, I tried to cover the first two cases in the original package_feature_unification_cli_features.

Here I tried specifically to get close to 3 but since that does not work in the general case, I tried to get closer to it by the indirect dependency being part of the workspace, but either not being selected or being excluded.

I was unsure about how some of the scenarios would (or wouldn't) work but arguably since all of the cases work the same way regardless of feature-unification, it might not belong here as it's more of a general features test. Or it might as it should be the same for all of them.

So I can either leave this as is, move it somewhere or just remove it completely.

And if you want the other cases covered more than they are in the other test, feel free to tell me.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right, I tried to cover the first two cases in the original package_feature_unification_cli_features.

Ok, that looks to be the case "check -p a -F a/a,outside/b".

So I can either leave this as is, move it somewhere or just remove it completely.

Unsure but we should at least make the name more clear that this is focused on activating features for specific packages only within a workspace, contracted with package_feature_unification_cli_features which focused on a combination of workspace members and registry dependencies while having a similar name of package_feature_unification_grandchild_cli_features.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've renamed the second one to feature_unification_of_cli_features_within_workspace. I didn't come up with anything more descriptive yet reasonable than package_feature_unification_cli_features for the first one so I've left that as is.

@mladedav
mladedav force-pushed the dm/unification-package branch from 20021a9 to f7b58c2 Compare July 1, 2025 21:06
@epage

epage commented Jul 1, 2025

Copy link
Copy Markdown
Contributor

@mladedav looks like there is a conflict?

@mladedav
mladedav force-pushed the dm/unification-package branch from f7b58c2 to e4a616b Compare July 1, 2025 22:02
@mladedav

mladedav commented Jul 1, 2025

Copy link
Copy Markdown
Contributor Author

Right, I've rebased this on top of master now

@epage

epage commented Jul 2, 2025

Copy link
Copy Markdown
Contributor

Thanks!

@epage
epage added this pull request to the merge queue Jul 2, 2025
Merged via the queue into rust-lang:master with commit e416238 Jul 2, 2025
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 2, 2025
@mladedav
mladedav deleted the dm/unification-package branch July 2, 2025 20:20
bors added a commit to rust-lang/rust that referenced this pull request Jul 12, 2025
Update cargo

14 commits in 930b4f62cfcd1f0eabdb30a56d91bf6844b739bf..eabb4cd923deb73e714f7ad3f5234d68ca284dbe
2025-06-28 14:58:43 +0000 to 2025-07-09 22:07:55 +0000
- feat: Implementation and tests for `multiple-build-scripts` (rust-lang/cargo#15704)
- perf: Speed up TOML parsing by upgrading toml (rust-lang/cargo#15736)
- Mark cachelock tests that rely on interprocess blocking behaviour as unsupported on AIX. (rust-lang/cargo#15734)
- feat(publish): Stabilize multi-package publishing (rust-lang/cargo#15636)
- Update to Rust 2024 (rust-lang/cargo#15732)
- Clarify package ID specifications in SBOMs are fully qualified (rust-lang/cargo#15731)
- chore(deps): update cargo-semver-checks to v0.42.0 (rust-lang/cargo#15730)
- test: Switch config tests to use snapshots (rust-lang/cargo#15729)
- implement package feature unification (rust-lang/cargo#15684)
- chore: Upgrade dependencies (rust-lang/cargo#15722)
- Report valid file name when we can't find a build target for `name = "foo.rs"` (rust-lang/cargo#15707)
- chore(release): Publish build-rs on release (rust-lang/cargo#15708)
- Override `Cargo.lock` checksums when doing a dry-run `publish` (rust-lang/cargo#15711)
- test(rustfix): Update for nightly (rust-lang/cargo#15717)

r? ghost
@rustbot rustbot added this to the 1.90.0 milestone Jul 12, 2025
github-merge-queue Bot pushed a commit that referenced this pull request Sep 16, 2026
### What does this PR try to resolve?

Fixes a bug introduced by #15684
where the incorrect list of package specs was being returned from
`resolve_ws_with_opts` depending on the feature unification mode. This
resulted in things like `cargo tree` producing the wrong output under
workspace feature unification mode.
#16584 attempted to address this
but it didn't fix the root cause of the issue.

I also cleaned up some of the logic in `resolve_ws_with_opts` so it's
less confusing.

Fixes #16583.

### How to test and review this PR?

Verify that the changes to `resolve_ws_with_opts` look correct. Feature
unification tests should pass for each individual commit.
@weihanglo weihanglo added the Z-feature-unification Nightly: resolver.feature-unifiication label Sep 17, 2026
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-documenting-cargo-itself Area: Cargo's documentation A-workspaces Area: workspaces Command-fix Command-tree Z-feature-unification Nightly: resolver.feature-unifiication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants