I have a dependency in my Cargo file that needs to be different by platform, specifically, the default features. Here's what I am trying to do:
[package]
name = "..blah.."
version = "..blah.."
authors = ["..blah.."]
[target.'cfg(target_os = "macos")'.dependencies]
hyper = { version = "0.9", default-features = false, features = ["security-framework"] }
[target.'cfg(target_os = "linux")'.dependencies]
hyper = { version = "0.9", default-features = true }
But this doesn't seem to do what I want. On my Mac it appears to be using the bottom target line as if I just specified hyper = "0.9"
. If I do cargo build
as specified, I get errors with regard to openssl:
cargo:warning=#include <openssl/ssl.h>
However, if I build it like this:
[dependencies]
hyper = { version = "0.9", default-features = false, features = ["security-framework"] }
Then it builds fine. This indicates to me that the cfg
for "macos" isn't working.
How do I make this work, or more specifically, how do I solve the problem where I need my dependency to use different features by platform?
It does not look like it is possible with Rust 1.13.0 and Cargo 0.13.0-nightly. See Cargo issues 3195 and 1197.
As a workaround, you can tell Cargo to use Homebrew's OpenSSL:
export OPENSSL_INCLUDE_DIR=`brew --prefix openssl`/include
export OPENSSL_LIB_DIR=`brew --prefix openssl`/lib
export DEP_OPENSSL_INCLUDE=`brew --prefix openssl`/include
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