Description
I've been using build scripts to enable features based on rust versions automatically, such that if you build with a version that added a new feature to the language or libstd, users of the crate can automatically get those without having to manually enable features.
But sometimes, the feature needs another crate as dependency. In that case, what you really want is an optional dependency, and for the feature to enable it. But the only way to enable a feature from a build script only enables the feature from rustc perspective, not cargo's.
So, say you have a Cargo.toml
with something like:
[dependencies]
foo = { version = "0.1", optional = true }
or
[features]
foo = ["bar"]
[dependencies]
bar = { version = "0.1", optional = true }
A build script that does:
fn main() {
println!("cargo:rustc-cfg=feature=\"foo\"");
}
won't make the optional dependency built in either case, which makes sense because it's all about rustc, but should, IMHO, be supported.