paupino/rust-decimal

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

xkikeg opened this issue · 2 comments

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?

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.

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