Imagine that I'm working on MyCrate
, which depends on crate A
, which has a default feature X
.
If I compile MyCrate
with --no-default-features
, crate A
is still built with feature X
enabled.
This is annoying, but it's possible to work around by using a Cargo.toml like:
[dependencies.A]
version = "*"
default-features = false
However, this solution does not work when A
depends on another crate B
which has its own default features. In this case, it does not seem possible to disable B
's default features. In other words, it seems impossible to disable the default features of an indirect dependency.
My particular motivating case is libc unnecessarily depends on libstd when used through cargo.
This is why Cargo allows you to reexport features from dependencies in the main crate itself. Dependencies are intended to be a private implementation detail instead of a public interface, and if you'd like the feature to be exported then you must explicitly opt-in to doing so.
@alexcrichton:
So is every crate supposed to include [dependencies.*] default-features = false
just so that an end user can choose to opt out of some nested feature? That seems rather obtuse.
Yeah, that's the intention. Making something a default
feature means it will be turned on almost all the time, so it's not necessarily meant for all optional pieces of functionality.
Most helpful comment
@alexcrichton:
So is every crate supposed to include
[dependencies.*] default-features = false
just so that an end user can choose to opt out of some nested feature? That seems rather obtuse.