summaryrefslogtreecommitdiff
path: root/libssh2-sys
diff options
context:
space:
mode:
authorJim McGrath <jimmc2@gmail.com>2017-05-24 09:05:49 -0500
committerJim McGrath <jimmc2@gmail.com>2017-05-24 09:06:10 -0500
commita289f09366fa53802968f6ec4c52062ccfcba98b (patch)
tree2da9e77d8613e2a098e1eb1454946b4680761cc4 /libssh2-sys
parentdf91eb85554120331a502f534c494086e03a994d (diff)
downloadssh2-rs-a289f09366fa53802968f6ec4c52062ccfcba98b.zip
optionally use libssh2 from vcpkg for msvc abi builds
Diffstat (limited to 'libssh2-sys')
-rw-r--r--libssh2-sys/Cargo.toml3
-rw-r--r--libssh2-sys/build.rs34
2 files changed, 37 insertions, 0 deletions
diff --git a/libssh2-sys/Cargo.toml b/libssh2-sys/Cargo.toml
index 8277813..5b187d2 100644
--- a/libssh2-sys/Cargo.toml
+++ b/libssh2-sys/Cargo.toml
@@ -22,3 +22,6 @@ openssl-sys = "0.9"
[build-dependencies]
pkg-config = "0.3"
cmake = "0.1.2"
+
+[target.'cfg(target_env = "msvc")'.build-dependencies]
+vcpkg = "0.2"
diff --git a/libssh2-sys/build.rs b/libssh2-sys/build.rs
index 0b6906e..0ab9005 100644
--- a/libssh2-sys/build.rs
+++ b/libssh2-sys/build.rs
@@ -1,6 +1,9 @@
extern crate pkg_config;
extern crate cmake;
+#[cfg(target_env = "msvc")]
+extern crate vcpkg;
+
use std::env;
use std::fs::File;
use std::io::prelude::*;
@@ -8,6 +11,10 @@ use std::path::{PathBuf, Path};
use std::process::Command;
fn main() {
+ if try_vcpkg() {
+ return;
+ }
+
register_dep("Z");
register_dep("OPENSSL");
@@ -117,3 +124,30 @@ fn prepend(var: &str, val: PathBuf) {
v.extend(env::split_paths(&prefix));
env::set_var(var, &env::join_paths(v).unwrap());
}
+
+#[cfg(not(target_env = "msvc"))]
+fn try_vcpkg() -> bool { false }
+
+#[cfg(target_env = "msvc")]
+fn try_vcpkg() -> bool {
+ vcpkg::Config::new()
+ .emit_includes(true)
+ .probe("libssh2").map(|_| {
+
+ // found libssh2 which depends on openssl and zlib
+ vcpkg::Config::new()
+ .lib_name("libeay32")
+ .lib_name("ssleay32")
+ .probe("openssl").expect("configured libssh2 from vcpkg but could not \
+ find openssl libraries that it depends on");
+
+ vcpkg::Config::new()
+ .lib_names("zlib", "zlib1")
+ .probe("zlib").expect("configured libssh2 from vcpkg but could not \
+ find the zlib library that it depends on");
+
+ println!("cargo:rustc-link-lib=crypt32");
+ println!("cargo:rustc-link-lib=gdi32");
+ println!("cargo:rustc-link-lib=user32");
+ }).is_ok()
+}