aboutsummaryrefslogtreecommitdiff
path: root/openssl-sys
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2017-08-11 22:44:46 -0700
committerGitHub <[email protected]>2017-08-11 22:44:46 -0700
commit75d927b2bd2c3d6ad72dcf325e921ff6c916ccf6 (patch)
treebcc5e5421d882d35dd69517f124019e888c8e928 /openssl-sys
parentRelease v0.9.16 (diff)
parentmsvc/vcpkg dynamic builds now require explicit opt-in (diff)
downloadrust-openssl-75d927b2bd2c3d6ad72dcf325e921ff6c916ccf6.tar.xz
rust-openssl-75d927b2bd2c3d6ad72dcf325e921ff6c916ccf6.zip
Merge pull request #622 from mcgoo/vcpkg
try to find openssl libraries in a vcpkg ports tree
Diffstat (limited to 'openssl-sys')
-rw-r--r--openssl-sys/Cargo.toml3
-rw-r--r--openssl-sys/build.rs47
2 files changed, 50 insertions, 0 deletions
diff --git a/openssl-sys/Cargo.toml b/openssl-sys/Cargo.toml
index 7fd9a2d8..c8f55ac2 100644
--- a/openssl-sys/Cargo.toml
+++ b/openssl-sys/Cargo.toml
@@ -18,6 +18,9 @@ libc = "0.2"
pkg-config = "0.3.9"
gcc = "0.3.42"
+[target.'cfg(target_env = "msvc")'.build-dependencies]
+vcpkg = "0.2"
+
# We don't actually use metadeps for annoying reasons but this is still here for tooling
[package.metadata.pkg-config]
openssl = "1.0.1"
diff --git a/openssl-sys/build.rs b/openssl-sys/build.rs
index a76b8ee5..4b0a8555 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;
@@ -110,6 +112,7 @@ fn find_openssl_dir(target: &str) -> OsString {
}
try_pkg_config();
+ try_vcpkg();
let mut msg = format!(
"
@@ -235,6 +238,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 {