Is it possible to make the list of default features platform dependent in your Cargo.toml? I'd like to use features to select platform-dependent dependencies.
I'd imagine something like this:
[features]
# on Unix
default = ["feature-a"]
# not on Unix
default = ["feature-b"]
feature-a = ["dep-a"]
feature-b = ["dep-b"]
[dependencies]
dep-a = { version = "*", optional = true }
dep-b = { version = "*", optional = true }
I've tried:
Using
[target.'cfg(unix)'.features]does not work, it is ignored:[target.'cfg(unix)'.features] default = ["feature-a"] # -- snip --Using a
build.rsscript to enable features based oncfgconditions only partially works. Dependency resolution is done before runningbuild.rs, so this won't import optional dependencies for features enabled in it. This example won't importdep-a:fn main() { #[cfg(unix)] println!("cargo:rustc-cfg=feature=\"feature-a\""); // -- snip -- }
Can this be achieved within Rust itself, without external scripts?