From 6b72784df4c3a5da9b53711ca6d16ad3e543e29e Mon Sep 17 00:00:00 2001 From: Jessica Hamilton Date: Sat, 22 Apr 2017 13:55:47 +1200 Subject: [PATCH] Allow overriding lib/include dirs when cross-compiling. --- libssh2-sys/build.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/libssh2-sys/build.rs b/libssh2-sys/build.rs index 0b6906e83..a7a52fb70 100644 --- a/libssh2-sys/build.rs +++ b/libssh2-sys/build.rs @@ -11,6 +11,21 @@ fn main() { register_dep("Z"); register_dep("OPENSSL"); + let target = env::var("TARGET").unwrap(); + let host = env::var("HOST").unwrap(); + + if target != host { + let lib_dir = env::var_os("TARGET_LIBSSH2_LIB_DIR").map(PathBuf::from); + let include_dir = env::var_os("TARGET_LIBSSH2_INCLUDE_DIR").map(PathBuf::from); + + if lib_dir.is_some() && include_dir.is_some() { + println!("cargo:rustc-link-search=native={}", lib_dir.unwrap().to_string_lossy()); + println!("cargo:include={}", include_dir.unwrap().to_string_lossy()); + println!("cargo:rustc-link-lib=dylib=ssh2"); + return; + } + } + if let Ok(lib) = pkg_config::find_library("libssh2") { for path in &lib.include_paths { println!("cargo:include={}", path.display()); @@ -25,8 +40,6 @@ fn main() { let mut cfg = cmake::Config::new("libssh2"); - let target = env::var("TARGET").unwrap(); - // Don't use OpenSSL on Windows, instead use the native Windows backend. if target.contains("windows") { cfg.define("CRYPTO_BACKEND", "WinCNG");