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

The usage of weak dependencies pollutes Cargo.lock #11426

Closed
c410-f3r opened this issue Nov 26, 2022 · 5 comments
Closed

The usage of weak dependencies pollutes Cargo.lock #11426

c410-f3r opened this issue Nov 26, 2022 · 5 comments
Labels
A-features Area: features — conditional compilation A-lockfile Area: Cargo.lock issues C-bug Category: bug

Comments

@c410-f3r
Copy link

c410-f3r commented Nov 26, 2022

Feel free to close if duplicated or if it is a "feature" of Cargo.

Problem

A feature declared with optional weak dependencies will unnecessarily pollute Cargo.lock with all the declared non-activated items as well as their transients, which is crazy.

Take for example the rust_decimal crate. If declared as rust_decimal = { default-features = false, version = "1.0" }, then Cargo.lock will contain 5 dependencies but if declared as rust_decimal = { default-features = false, features = ["std"], version = "1.0" }, then Cargo.lock will contain +40 dependencies.

# Cargo.toml (https://github.com/paupino/rust-decimal/blob/master/Cargo.toml#L80)

# ...

std = ["arrayvec/std", "borsh?/std", "bytecheck?/std", "byteorder?/std", "bytes?/std", "rand?/std", "rkyv?/std", "serde?/std", "serde_json?/std"]

# ...
$ cargo tree

rust_decimal v1.27.0
    ├── arrayvec v0.7.2
    └── num-traits v0.2.15
        [build-dependencies]
        └── autocfg v1.1.0

Version

1.65.0
@c410-f3r c410-f3r added the C-bug Category: bug label Nov 26, 2022
@epage epage added A-features Area: features — conditional compilation A-lockfile Area: Cargo.lock issues labels Nov 26, 2022
@weihanglo
Copy link
Member

Is this kinda a duplicate of #10801?

@c410-f3r
Copy link
Author

It is, indeed.

@weihanglo weihanglo closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2022
@epage
Copy link
Contributor

epage commented Nov 26, 2022

@weihanglo I thought #10801 is about lock files including optional features of direct dependencies. Does it also include indirect dependencies?

Note that in this issue, the lock file for

  • rust_decimal = { default-features = false, version = "1.0" } contains 5 items
  • rust_decimal = { default-features = false, features = ["std"], version = "1.0" } contains 40+ items

The number of lock file entries when std isn't specified I think confirms that #10801 is only about direct dependencies and shows this issue is independent of #10801.

The key part here is weak dependencies. It seems we are resolving the lock file as if none of those weak dependencies were weak.

Re-opening for now so this doesn't get lost track of. If there was something I missed, we can always re-close.

@epage epage reopened this Nov 26, 2022
@weihanglo
Copy link
Member

weihanglo commented Nov 26, 2022

#10801 is

  • bar depends on foo with feature serialization enabled.
  • Feature serialization contains a weak dep feature time?/serde-well-known.
  • Indirect optional dep time ended up in the lockfile.

#11426 is

  • some_pkg depends on rust_decimal with feature std enabled.
  • Feature std contains weak dep features borsh?/std, bytecheck?/std
  • Those indirect optional deps ended up in the lockfile.

I didn't see the difference between them 🤔.

@epage
Copy link
Contributor

epage commented Nov 26, 2022

Somehow I had missed the weak dependency aspect of the other one. I've re-titled it to call that out. Of course, if there is another angle to that that I missed, let me know and we can fix it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-features Area: features — conditional compilation A-lockfile Area: Cargo.lock issues C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants