ritchie46
ritchie46

Reputation: 14730

Cargo conditional dependency feature

I want to include features of a dependencies dependent on the activation of the feature in my library. If I compile with feature "serde", I want to install ndarray with "serde" support. And the default should be the default ndarray install.

I' want something like this Cargo.toml


[features]
include-serde = ["ndarray-with-serde"]

[dependencies]
ndarray = { version = "0.x" }
ndarray-with-serde = { version = "0.x", features=["serde"] }

Is this possible at the moment?

Upvotes: 5

Views: 1276

Answers (1)

ritchie46
ritchie46

Reputation: 14730

You can add the features of a crate after a /.

[features]
myfeature = ["library_foo/bar", "libary_foo/ham"]

[dependencies]
library_foo = { version = "0.x" }

The snippet above install features "bar" and "ham" from "library_foo" when "myfeature" is activated.

Upvotes: 3

Related Questions