Don't ignore environment variables if building with mingw

This commit is contained in:
Simon Mazur 2015-06-15 19:13:30 +03:00
parent c532c1992e
commit 27b0e4d7af
1 changed files with 22 additions and 20 deletions

View File

@ -18,16 +18,18 @@ fn main() {
build_old_openssl_shim(&info.include_paths); build_old_openssl_shim(&info.include_paths);
return; return;
} }
if let Some(mingw_paths) = get_mingw_in_path() {
for path in mingw_paths {
println!("cargo:rustc-flags=-L native={}", path);
}
}
} }
let libs_env = env::var("OPENSSL_LIBS").ok(); let libs_env = env::var("OPENSSL_LIBS").ok();
let libs = match libs_env { let libs = match libs_env {
Some(ref v) => v.split(":").collect(), Some(ref v) => v.split(":").collect(),
None => if target.contains("windows") { None => if target.contains("windows") {
if let Some(mingw_paths) = check_mingw_path() { if get_mingw_in_path().is_some() && lib_dir.is_none() && include_dir.is_none() {
for path in mingw_paths {
println!("cargo:rustc-flags=-L native={}", path);
}
vec!("eay32", "ssleay32") vec!("eay32", "ssleay32")
} else { } else {
vec!("eay32", "ssl32") vec!("eay32", "ssl32")
@ -70,24 +72,24 @@ fn build_old_openssl_shim(include_paths: &[PathBuf]) {
.compile("libold_openssl_shim.a"); .compile("libold_openssl_shim.a");
} }
fn check_mingw_path() -> Option<Vec<String>> { fn get_mingw_in_path() -> Option<Vec<String>> {
use std::ascii::AsciiExt; match env::var_os("PATH") {
Some(env_path) => {
let paths: Vec<String> = env::split_paths(&env_path).filter_map(|path| {
use std::ascii::AsciiExt;
let mut paths = vec![]; match path.to_str() {
Some(path_str) => {
if let Some(env_path) = env::var("PATH").ok() { if path_str.to_ascii_lowercase().contains("mingw") {
for path in env::split_paths(&env_path) { Some(path_str.to_string())
if let Some(path_str) = path.to_str() { } else { None }
if path_str.to_ascii_lowercase().contains("mingw") { },
paths.push(path_str.to_string()); None => None
} }
} }).collect();
}
}
if paths.len() > 0 { if paths.len() > 0 { Some(paths) } else { None }
Option::Some(paths) },
} else { None => None
Option::None
} }
} }