Is Possible to Disable Default Features with Features?

I want to disable the default features in feature arm. This look quite ugly.

[dependencies]
darwinia-cli = { default-features = false, path = "cli" }

[features]
default = [
	"darwinia-cli/default",
]
arm = [
	"darwinia-cli/cli",
	"darwinia-cli/db",
]

[workspace]
members = [
	"cli",
]

Or there's another way?

# how to disable the default features?
cargo build --features darwinia-cli/cli,darwinia-cli/db

Or?

# this work perfectly, but I can not get the binary.
# crate `cli/Cargo.toml` is a lib type.
cargo build --manifest-path cli/Cargo.toml --no-default-features --features cli,db

AFAIK the default feature is just another feature that just so happens to have the name default i.e. there are no special rules.
What this means for you is that it depends on how the features were designed to work together, since features can be mutually exclusive, one feature can require another, and features can be mandatory in order for a crate to compile at all.

There is a special rule, when you depend on a dependency by default the default feature is active, to not request it you need to foobar = { version = "...", default-features = false }.

1 Like

Having a feature disable another feature isn't really supported in the model. The whole concept is that features are additive throughout the tree, what you call "quite ugly" is the correct way to do this, and IMO is conceptually simpler to understand than having arm = ["!default"] or something (what would it mean if I depend on features = ["arm", "default"]?).

4 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.