aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2018-02-11 09:14:13 -0800
committerGitHub <[email protected]>2018-02-11 09:14:13 -0800
commit2c0dce4c39a8d3889a57370fc23d1b65adb6d0bb (patch)
treebbbaecb5c7141de0940d30584b46ce07bdc139f2
parentMerge pull request #833 from CmdrMoozy/des_ede3 (diff)
parentDetect FreeBSD OpenSSL automatically (diff)
downloadrust-openssl-2c0dce4c39a8d3889a57370fc23d1b65adb6d0bb.tar.xz
rust-openssl-2c0dce4c39a8d3889a57370fc23d1b65adb6d0bb.zip
Merge pull request #834 from sfackler/freebsd
Detect FreeBSD OpenSSL automatically
-rw-r--r--CHANGELOG.md4
-rw-r--r--openssl-sys/build.rs54
2 files changed, 34 insertions, 24 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7991824d..210c0052 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
## [Unreleased]
+### Added
+
+* OpenSSL is now automatically detected on FreeBSD systems.
+
## [v0.10.2] - 2018-01-11
### Added
diff --git a/openssl-sys/build.rs b/openssl-sys/build.rs
index ff875be5..3d682962 100644
--- a/openssl-sys/build.rs
+++ b/openssl-sys/build.rs
@@ -1,7 +1,7 @@
+extern crate cc;
extern crate pkg_config;
#[cfg(target_env = "msvc")]
extern crate vcpkg;
-extern crate cc;
use std::collections::HashSet;
use std::env;
@@ -89,17 +89,15 @@ fn main() {
let libs_env = env("OPENSSL_LIBS");
let libs = match libs_env.as_ref().and_then(|s| s.to_str()) {
Some(ref v) => v.split(":").collect(),
- None => {
- match version {
- Version::Openssl101 |
- Version::Openssl102 if target.contains("windows") => vec!["ssleay32", "libeay32"],
- Version::Openssl110 if target.contains("windows") => vec!["libssl", "libcrypto"],
- _ => vec!["ssl", "crypto"],
+ None => match version {
+ Version::Openssl101 | Version::Openssl102 if target.contains("windows") => {
+ vec!["ssleay32", "libeay32"]
}
- }
+ Version::Openssl110 if target.contains("windows") => vec!["libssl", "libcrypto"],
+ _ => vec!["ssl", "crypto"],
+ },
};
-
let kind = determine_mode(Path::new(&lib_dir), &libs);
for lib in libs.into_iter() {
println!("cargo:rustc-link-lib={}={}", kind, lib);
@@ -109,7 +107,7 @@ fn main() {
fn find_openssl_dir(target: &str) -> OsString {
let host = env::var("HOST").unwrap();
- if host.contains("apple-darwin") && target.contains("apple-darwin") {
+ if host == target && target.contains("apple-darwin") {
let homebrew = Path::new("/usr/local/opt/[email protected]");
if homebrew.exists() {
return homebrew.to_path_buf().into();
@@ -123,6 +121,11 @@ fn find_openssl_dir(target: &str) -> OsString {
try_pkg_config();
try_vcpkg();
+ // FreeBSD ships with OpenSSL but doesn't include a pkg-config file :(
+ if host == target && target.contains("freebsd") {
+ return OsString::from("/usr");
+ }
+
let mut msg = format!(
"
@@ -228,9 +231,10 @@ fn try_pkg_config() {
return;
}
- let lib = match pkg_config::Config::new().print_system_libs(false).find(
- "openssl",
- ) {
+ let lib = match pkg_config::Config::new()
+ .print_system_libs(false)
+ .find("openssl")
+ {
Ok(lib) => lib,
Err(e) => {
println!("run pkg_config fail: {:?}", e);
@@ -253,7 +257,6 @@ fn try_pkg_config() {
/// 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.
@@ -264,8 +267,10 @@ fn try_vcpkg() {
.probe("openssl");
if let Err(e) = lib {
- println!("note: vcpkg did not find openssl as libcrypto and libssl : {:?}",
- e);
+ println!(
+ "note: vcpkg did not find openssl as libcrypto and libssl : {:?}",
+ e
+ );
lib = vcpkg::Config::new()
.emit_includes(true)
.lib_name("libeay32")
@@ -273,8 +278,10 @@ fn try_vcpkg() {
.probe("openssl");
}
if let Err(e) = lib {
- println!("note: vcpkg did not find openssl as ssleay32 and libeay32: {:?}",
- e);
+ println!(
+ "note: vcpkg did not find openssl as ssleay32 and libeay32: {:?}",
+ e
+ );
return;
}
@@ -516,12 +523,11 @@ fn determine_mode(libdir: &Path, libs: &[&str]) -> &'static str {
.map(|e| e.file_name())
.filter_map(|e| e.into_string().ok())
.collect::<HashSet<_>>();
- let can_static = libs.iter().all(|l| {
- files.contains(&format!("lib{}.a", l)) || files.contains(&format!("{}.lib", l))
- });
+ let can_static = libs.iter()
+ .all(|l| files.contains(&format!("lib{}.a", l)) || files.contains(&format!("{}.lib", l)));
let can_dylib = libs.iter().all(|l| {
- files.contains(&format!("lib{}.so", l)) || files.contains(&format!("{}.dll", l)) ||
- files.contains(&format!("lib{}.dylib", l))
+ files.contains(&format!("lib{}.so", l)) || files.contains(&format!("{}.dll", l))
+ || files.contains(&format!("lib{}.dylib", l))
});
match (can_static, can_dylib) {
(true, false) => return "static",
@@ -529,7 +535,7 @@ fn determine_mode(libdir: &Path, libs: &[&str]) -> &'static str {
(false, false) => {
panic!(
"OpenSSL libdir at `{}` does not contain the required files \
- to either statically or dynamically link OpenSSL",
+ to either statically or dynamically link OpenSSL",
libdir.display()
);
}