I have a feature but this feature has different dependencies depending on the system that it is running on. I would hope I could do something like
[target.'cfg(all(target_os = "windows", feature = "myfeature"))'.dependencies]
but this did not work and I also tried
[target.'cfg(target_os = "windows")'.features]
but it looked to be a dead pr on the rust lang git.
The Doc's example is like:
[target.'cfg(windows)'.dependencies]
winhttp = "0.4.0"
[target.'cfg(unix)'.dependencies]
openssl = "1.0.1"
[target.'cfg(target_arch = "x86")'.dependencies]
native-i686 = { path = "native/i686" }
[target.'cfg(target_arch = "x86_64")'.dependencies]
native-x86_64 = { path = "native/x86_64" }
Maybe you can try this?
Specifying Dependencies - The Cargo Book (rust-lang.org)
This will set the dependency if they are on that system, but I want a way to set the dependency if they are on a system and if they picked a feature.
The only way I could do it now is if I made each feature its own crate then in the crate set the dependencies depending on the target. I would not want to do this because my project has a good amount of features.
Oh, that's beyond my ability. And I am curious abort the answer.
Ok this looks to be working
[features]
cool-feature = [
"dep:dependency",
"dependency?/dependency-feature"
]
[target.'cfg(target_os = "windows")'.dependencies]
dependency = { version = "1.0.0", optional = true }
If you dont specify a dependency for a target it looks like it just skips over it.
1 Like