Skip to content

Commit

Permalink
Allow overriding lib/include dirs when cross-compiling.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicah committed Apr 22, 2017
1 parent 91c0d62 commit 6b72784
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions libssh2-sys/build.rs
Expand Up @@ -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());
Expand All @@ -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");
Expand Down

0 comments on commit 6b72784

Please sign in to comment.