Merge pull request #834 from sfackler/freebsd
Detect FreeBSD OpenSSL automatically
This commit is contained in:
commit
2c0dce4c39
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* OpenSSL is now automatically detected on FreeBSD systems.
|
||||||
|
|
||||||
## [v0.10.2] - 2018-01-11
|
## [v0.10.2] - 2018-01-11
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
|
extern crate cc;
|
||||||
extern crate pkg_config;
|
extern crate pkg_config;
|
||||||
#[cfg(target_env = "msvc")]
|
#[cfg(target_env = "msvc")]
|
||||||
extern crate vcpkg;
|
extern crate vcpkg;
|
||||||
extern crate cc;
|
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
@ -89,17 +89,15 @@ fn main() {
|
||||||
let libs_env = env("OPENSSL_LIBS");
|
let libs_env = env("OPENSSL_LIBS");
|
||||||
let libs = match libs_env.as_ref().and_then(|s| s.to_str()) {
|
let libs = match libs_env.as_ref().and_then(|s| s.to_str()) {
|
||||||
Some(ref v) => v.split(":").collect(),
|
Some(ref v) => v.split(":").collect(),
|
||||||
None => {
|
None => match version {
|
||||||
match version {
|
Version::Openssl101 | Version::Openssl102 if target.contains("windows") => {
|
||||||
Version::Openssl101 |
|
vec!["ssleay32", "libeay32"]
|
||||||
Version::Openssl102 if target.contains("windows") => vec!["ssleay32", "libeay32"],
|
}
|
||||||
Version::Openssl110 if target.contains("windows") => vec!["libssl", "libcrypto"],
|
Version::Openssl110 if target.contains("windows") => vec!["libssl", "libcrypto"],
|
||||||
_ => vec!["ssl", "crypto"],
|
_ => vec!["ssl", "crypto"],
|
||||||
}
|
},
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
let kind = determine_mode(Path::new(&lib_dir), &libs);
|
let kind = determine_mode(Path::new(&lib_dir), &libs);
|
||||||
for lib in libs.into_iter() {
|
for lib in libs.into_iter() {
|
||||||
println!("cargo:rustc-link-lib={}={}", kind, lib);
|
println!("cargo:rustc-link-lib={}={}", kind, lib);
|
||||||
|
|
@ -109,7 +107,7 @@ fn main() {
|
||||||
fn find_openssl_dir(target: &str) -> OsString {
|
fn find_openssl_dir(target: &str) -> OsString {
|
||||||
let host = env::var("HOST").unwrap();
|
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/openssl@1.1");
|
let homebrew = Path::new("/usr/local/opt/openssl@1.1");
|
||||||
if homebrew.exists() {
|
if homebrew.exists() {
|
||||||
return homebrew.to_path_buf().into();
|
return homebrew.to_path_buf().into();
|
||||||
|
|
@ -123,6 +121,11 @@ fn find_openssl_dir(target: &str) -> OsString {
|
||||||
try_pkg_config();
|
try_pkg_config();
|
||||||
try_vcpkg();
|
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!(
|
let mut msg = format!(
|
||||||
"
|
"
|
||||||
|
|
||||||
|
|
@ -228,9 +231,10 @@ fn try_pkg_config() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let lib = match pkg_config::Config::new().print_system_libs(false).find(
|
let lib = match pkg_config::Config::new()
|
||||||
"openssl",
|
.print_system_libs(false)
|
||||||
) {
|
.find("openssl")
|
||||||
|
{
|
||||||
Ok(lib) => lib,
|
Ok(lib) => lib,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("run pkg_config fail: {:?}", 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.
|
/// should emit all of the cargo metadata that we need.
|
||||||
#[cfg(target_env = "msvc")]
|
#[cfg(target_env = "msvc")]
|
||||||
fn try_vcpkg() {
|
fn try_vcpkg() {
|
||||||
|
|
||||||
// vcpkg will not emit any metadata if it can not find libraries
|
// vcpkg will not emit any metadata if it can not find libraries
|
||||||
// appropriate for the target triple with the desired linkage.
|
// appropriate for the target triple with the desired linkage.
|
||||||
|
|
||||||
|
|
@ -264,8 +267,10 @@ fn try_vcpkg() {
|
||||||
.probe("openssl");
|
.probe("openssl");
|
||||||
|
|
||||||
if let Err(e) = lib {
|
if let Err(e) = lib {
|
||||||
println!("note: vcpkg did not find openssl as libcrypto and libssl : {:?}",
|
println!(
|
||||||
e);
|
"note: vcpkg did not find openssl as libcrypto and libssl : {:?}",
|
||||||
|
e
|
||||||
|
);
|
||||||
lib = vcpkg::Config::new()
|
lib = vcpkg::Config::new()
|
||||||
.emit_includes(true)
|
.emit_includes(true)
|
||||||
.lib_name("libeay32")
|
.lib_name("libeay32")
|
||||||
|
|
@ -273,8 +278,10 @@ fn try_vcpkg() {
|
||||||
.probe("openssl");
|
.probe("openssl");
|
||||||
}
|
}
|
||||||
if let Err(e) = lib {
|
if let Err(e) = lib {
|
||||||
println!("note: vcpkg did not find openssl as ssleay32 and libeay32: {:?}",
|
println!(
|
||||||
e);
|
"note: vcpkg did not find openssl as ssleay32 and libeay32: {:?}",
|
||||||
|
e
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -516,12 +523,11 @@ fn determine_mode(libdir: &Path, libs: &[&str]) -> &'static str {
|
||||||
.map(|e| e.file_name())
|
.map(|e| e.file_name())
|
||||||
.filter_map(|e| e.into_string().ok())
|
.filter_map(|e| e.into_string().ok())
|
||||||
.collect::<HashSet<_>>();
|
.collect::<HashSet<_>>();
|
||||||
let can_static = libs.iter().all(|l| {
|
let can_static = libs.iter()
|
||||||
files.contains(&format!("lib{}.a", l)) || files.contains(&format!("{}.lib", l))
|
.all(|l| files.contains(&format!("lib{}.a", l)) || files.contains(&format!("{}.lib", l)));
|
||||||
});
|
|
||||||
let can_dylib = libs.iter().all(|l| {
|
let can_dylib = libs.iter().all(|l| {
|
||||||
files.contains(&format!("lib{}.so", l)) || files.contains(&format!("{}.dll", l)) ||
|
files.contains(&format!("lib{}.so", l)) || files.contains(&format!("{}.dll", l))
|
||||||
files.contains(&format!("lib{}.dylib", l))
|
|| files.contains(&format!("lib{}.dylib", l))
|
||||||
});
|
});
|
||||||
match (can_static, can_dylib) {
|
match (can_static, can_dylib) {
|
||||||
(true, false) => return "static",
|
(true, false) => return "static",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue