diff --git a/Cargo.toml b/Cargo.toml index 02e6c23c..962bd737 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,11 +24,12 @@ default = ["zmq_has"] # this feature is a no-op and only present for backward-compatibility; # it will be removed in the next API-breaking release. zmq_has = [] +libsodium = ["zmq-sys/libsodium"] [dependencies] bitflags = "1.0" libc = "0.2.15" -zmq-sys = { version = "0.12.0", path = "zmq-sys" } +zmq-sys = { version = "0.12.1", path = "zmq-sys" } [dev-dependencies] trybuild = { version = "1" } diff --git a/zmq-sys/Cargo.toml b/zmq-sys/Cargo.toml index 14507b86..6a164d17 100644 --- a/zmq-sys/Cargo.toml +++ b/zmq-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zmq-sys" -version = "0.12.0" +version = "0.12.1" authors = [ "a.rottmann@gmx.at", "erick.tryzelaar@gmail.com", @@ -14,9 +14,11 @@ build = "build/main.rs" links = "zmq" [features] +libsodium = ["dep:libsodium-sys-stable"] [dependencies] libc = "0.2.15" +libsodium-sys-stable = { version = "1.0", optional = true } [build-dependencies] system-deps = "6" diff --git a/zmq-sys/build/main.rs b/zmq-sys/build/main.rs index d6c229bc..65ff87a0 100644 --- a/zmq-sys/build/main.rs +++ b/zmq-sys/build/main.rs @@ -1,3 +1,5 @@ +use std::env; + pub fn configure() { println!("cargo:rerun-if-changed=build/main.rs"); println!("cargo:rerun-if-env-changed=PROFILE"); @@ -6,8 +8,19 @@ pub fn configure() { // relying on `tweetnacl`. However since this `tweetnacl` [has never been // audited nor is ready for production](https://github.com/zeromq/libzmq/issues/3006), // we link against `libsodium` to enable `ZMQ_CURVE`. + let maybe_libsodium = if cfg!(feature = "libsodium") { + let lib_dir = env::var("DEP_SODIUM_LIB") + .expect("build metadata `DEP_SODIUM_LIB` required"); + let include_dir = env::var("DEP_SODIUM_INCLUDE") + .expect("build metadata `DEP_SODIUM_INCLUDE` required"); + + Some(zeromq_src::LibLocation::new(lib_dir, include_dir)) + } else { + None + }; + zeromq_src::Build::new() - .with_libsodium(None) + .with_libsodium(maybe_libsodium) .build(); }