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

Disabled optional weak dependencies like "borsh" are pulled in with default-features #588

Closed
xkikeg opened this issue Apr 28, 2023 · 2 comments

Comments

@xkikeg
Copy link

xkikeg commented Apr 28, 2023

I have a crate that just specifies

rust_decimal = "1.29"

That will end up having optional feature dependencies in the Cargo.lock

[[package]]
name = "rust_decimal"
version = "1.29.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26bd36b60561ee1fb5ec2817f198b6fd09fa571c897a5e86d1487cfc2b096dfc"
dependencies = [
 "arrayvec",
 "borsh",
 "bytecheck",
 "byteorder",
 "bytes",
 "num-traits",
 "rand",
 "rkyv",
 "serde",
 "serde_json",
]

This matches the std feature of rust_decimal (regardless of "?" sign)

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

How can I remove those unnecessary dependencies?

@paupino paupino changed the title Optional dependencies like "borsh" is pulled in with default-features Disabled optional weak dependencies like "borsh" are pulled in with default-features Apr 28, 2023
@paupino
Copy link
Owner

paupino commented Apr 28, 2023

That's definitely a little unexpected.

Looking at it, this looks good:

rust_decimal = { version = "1.29", default-features = false }

This is still ok:

rust_decimal = { version = "1.29", default-features = false, features = [ "serde" ] }

However if we include std then it includes the other dependencies, regardless of them being activated:

rust_decimal = { version = "1.29", default-features = false, features = [ "std" ] }

Doing cargo tree, it does appear to resolve correctly:

± % cargo tree -e features 
dectest v0.1.0 (/Users/paulmason/dev/tmp/dectest)
└── rust_decimal feature "std"
    ├── rust_decimal v1.29.1
    │   ├── arrayvec v0.7.2
    │   └── num-traits feature "i128"
    │       └── num-traits v0.2.15
    │           [build-dependencies]
    │           └── autocfg feature "default"
    │               └── autocfg v1.1.0
    └── arrayvec feature "std"
        └── arrayvec v0.7.2

I did a bit of digging around and see that there is an open cargo issue tracking this behavior here: rust-lang/cargo#10801. The good news is that it looks like it has a PR to fix it open.

@xkikeg
Copy link
Author

xkikeg commented Apr 28, 2023

Thanks for clarification! It's just a nice-to-have fix, so let me wait some time on the cargo fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants