Afnan Enayet
Afnan Enayet

Reputation: 3

Toggle optional build dependencies and build dependencies using features

I know that Rust allows you to specify optional dependencies in the Cargo.toml manifest, and that you can trigger these dependencies with features. As an example:

[dependencies]
foo = "1.0"
bar = "1.0"

[features]
myfeature = ["foo", "bar"]

I'm trying to figure if there's a way I can have this apply for build dependencies as well, because I haven't found any documentation indicating that this is possible.

What I want to do is this:

[dependencies]
foo = "1.0"

[build-dependencies]
bar = "1.0"

[features]
myfeature = ["foo", "bar"]

The context for this is that I want to add the build-info and build-info-build crates to my project, but it adds to the compile time considerably, so I'd like to have a feature and only enable it for release builds.

Upvotes: 0

Views: 1264

Answers (1)

Afnan Enayet
Afnan Enayet

Reputation: 3

Turns out that this works, my mistake was making the feature name identical to one of the crates, ex: if you have

[dependencies]
foo = "1.0"

[build-dependencies]
bar = "1.0"

[features]
foo = ["foo", "bar"]

this doesn't seem to work. With a different name it works fine.

Upvotes: 0

Related Questions