diff options
| author | Jim McGrath <[email protected]> | 2017-06-07 09:56:06 -0500 |
|---|---|---|
| committer | Jim McGrath <[email protected]> | 2017-06-07 09:56:06 -0500 |
| commit | 6b50d8940d056e3b717b69007bf18f9223ab7ba3 (patch) | |
| tree | 1c818c225769892576911e3d5ff2ea03082b40e1 /openssl-sys/build.rs | |
| parent | Merge pull request #647 from mcgoo/remove_unused_deps (diff) | |
| download | rust-openssl-6b50d8940d056e3b717b69007bf18f9223ab7ba3.tar.xz rust-openssl-6b50d8940d056e3b717b69007bf18f9223ab7ba3.zip | |
for msvc abi builds, allow use of openssl libs from vcpkg
Diffstat (limited to 'openssl-sys/build.rs')
| -rw-r--r-- | openssl-sys/build.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/openssl-sys/build.rs b/openssl-sys/build.rs index bd52d104..2064ac99 100644 --- a/openssl-sys/build.rs +++ b/openssl-sys/build.rs @@ -1,4 +1,6 @@ extern crate pkg_config; +#[cfg(target_env = "msvc")] +extern crate vcpkg; extern crate gcc; use std::collections::HashSet; @@ -98,6 +100,7 @@ fn find_openssl_dir(target: &str) -> OsString { } try_pkg_config(); + try_vcpkg(); let mut msg = format!(" @@ -213,6 +216,50 @@ fn try_pkg_config() { std::process::exit(0); } +/// Attempt to find OpenSSL through vcpkg. +/// +/// Note that if this succeeds then the function does not return as vcpkg +/// should emit all of the cargo metadata that we need. +#[cfg(target_env = "msvc")] +fn try_vcpkg() { + + // vcpkg will not emit any metadata if it can not find libraries + // appropriate for the target triple with the desired linkage. + + let mut lib = vcpkg::Config::new() + .emit_includes(true) + .lib_name("libcrypto") + .lib_name("libssl") + .probe("openssl"); + + if let Err(e) = lib { + println!("note: vcpkg did not find openssl as libcrypto and libssl : {:?}", + e); + lib = vcpkg::Config::new() + .emit_includes(true) + .lib_name("libeay32") + .lib_name("ssleay32") + .probe("openssl"); + } + if let Err(e) = lib { + println!("note: vcpkg did not find openssl as ssleay32 and libeay32: {:?}", + e); + return; + } + + let lib = lib.unwrap(); + validate_headers(&lib.include_paths); + + println!("cargo:rustc-link-lib=user32"); + println!("cargo:rustc-link-lib=gdi32"); + println!("cargo:rustc-link-lib=crypt32"); + + std::process::exit(0); +} + +#[cfg(not(target_env = "msvc"))] +fn try_vcpkg() {} + /// Validates the header files found in `include_dir` and then returns the /// version string of OpenSSL. fn validate_headers(include_dirs: &[PathBuf]) -> Version { |