Skip to content

Conversation

@Jackhr-arch
Copy link

@Jackhr-arch Jackhr-arch commented Dec 20, 2025

I am not a native English user, please forgive my flaws in description.

What does this PR try to resolve?

it changes the parts of the resolver that generate Cargo.lock to not include weak dependencies.

This changes the logic when resolver checking features. Instead of add weak feature as strong one, now resolver keeps the weak dependency features until the very dependency is checked. Then it combines the weak features with the original ones.

E.g.

[features]
fa = ["da/daf", "db", "dc?/dcf", "dd?/ddf"]
fb = ["da", "db?/dbf"]
fc = ["da?/daf", "dc"]
default = ["fa", "fb", "fc"]

Now resolver acts like:

feature dep:da dep:db dep:dc dep:dd weak dep feat
fa with "daf" enabled disabled disabled "dc?/dcf","dd?/ddf"
fb with "daf" with "dbf" disabled disabled "db?/dbf"
fc with "daf" with "dbf" enabled disabled "da?/daf"

then it works on weak dependency features.

weak dep feat dep:da dep:db dep:dc dep:dd
dc?/dcf with "daf" with "dbf" with "dcf"
(here reslover enabled the weak feat)
disabled
dd?/dcf with "daf" with "dbf" with "dcf" disabled
db?/dcf with "daf" with "dbf" with "dcf" disabled
(here reslover ignore the weak feat)
da?/dcf with "daf" with "dbf" with "dcf" disabled

Relate to #10801

How to test and review this PR?

I've enabled some tests in crates/resolver-tests relating to Weak dependencies and looks they work fine.

Here is an example repo https://github.com/Jackhr-arch/cargo-weak-dep-feat-example

@rustbot rustbot added A-dependency-resolution Area: dependency resolution and the resolver S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 20, 2025

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

@Jackhr-arch Jackhr-arch marked this pull request as draft December 21, 2025 14:52
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 21, 2025
@Jackhr-arch Jackhr-arch marked this pull request as ready for review December 21, 2025 14:59
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 21, 2025
@Jackhr-arch

This comment has been minimized.

@epage
Copy link
Contributor

epage commented Dec 22, 2025

I won't be up for reviewing the core part of this, so my comments are a pre-review.

Please clean up commits for how they should be reviewed and merged.

r? @Eh2406

@rustbot rustbot assigned Eh2406 and unassigned weihanglo Dec 22, 2025
// Maybe `cargo tree` should print a note about why?
p.cargo("tree -e features -i bar --features bar?/feat")
.with_stdout_data("")
.with_status(101)
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically, this is a breaking change though we'll have to evaluate our willingness to accept this

Copy link
Author

Choose a reason for hiding this comment

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

Due to the new resolver is gated, cargo now restore its old behavior. I reverted this change.

Copy link
Author

Choose a reason for hiding this comment

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

The root cause is that I remove the non-activated weak dependency from root crate, too.

Now weak direct dependency is always included in Cargo.lock, with its test disabled_weak_direct_dep.

Previous change to tree and other tests is removed permanently.

&version_prefs,
ResolveVersion::with_rust_version(ws.lowest_rust_version()),
Some(ws.gctx()),
version,
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this redundant with line 512?

Copy link
Author

Choose a reason for hiding this comment

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

You are right, I missed this. Now it's fixed.

@est31
Copy link
Member

est31 commented Dec 23, 2025

I haven't done a review of the approach, I wonder whether this supports the weak_namespaced_v4 test from my earlier PR, or if it fails similarly (see ehuss comment and discussion immediately below).

@Jackhr-arch
Copy link
Author

I wonder whether this supports the weak_namespaced_v4 test from my earlier PR

It passed. I port 4 tests from your pull request, and deferred_v5 failed. I'm trying to fix this.

…eeded

Signed-off-by: Jackhr-arch <63526062+Jackhr-arch@users.noreply.github.com>
Signed-off-by: Jackhr-arch <63526062+Jackhr-arch@users.noreply.github.com>
Signed-off-by: Jackhr-arch <63526062+Jackhr-arch@users.noreply.github.com>
Co-authored-by: @est31
Signed-off-by: Jackhr-arch <63526062+Jackhr-arch@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-dependency-resolution Area: dependency resolution and the resolver 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.

6 participants