I would like to use the nix crate in a project.
However, this project also has an acceptable alternative implementation for OSX and Windows, where I would like to use a different crate.
What is the current way of expressing that I only want nix in Linux platforms?
There's two steps you need to make a dependency completely target-specific.
First, you need to specify this in your Cargo.toml, like so:
[target.'cfg(target_os = "linux")'.dependencies]
nix = "0.5"
This will make Cargo only include the dependency when that configuration is active. However, this means you'll get a compile error on your extern crate when you try to build on other platforms! To remedy this, annotate it with a cfg attribute, like so:
#[cfg(target_os = "linux")]
extern crate nix;
Of course, you then have to ensure that you only use the nix crate in code that's also annotated with the same cfg attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With