Merge pull request #225 from semmaz/mingw-build-fix

Added support for building on Windows with MinGW
This commit is contained in:
Steven Fackler 2015-06-20 18:07:41 -04:00
commit bfff71b7d6
2 changed files with 41 additions and 2 deletions

View File

@ -29,7 +29,15 @@ rust-openssl to a separate installation.
### Windows ### Windows
Install OpenSSL from [here][1]. Cargo will not be able to find OpenSSL if it's On Windows, consider building with [mingw-w64](http://mingw-w64.org/).
Build script will try to find mingw in `PATH` environment variable to provide
Cargo with location where openssl libs from mingw-w64 package may be found.
If you followed guide [Building on Windows](https://github.com/rust-lang/rust#building-on-windows)
from rust repo, then you should have [MSYS2](http://msys2.github.io/) with
`mingw-w64-openssl` installed as part of `mingw-w64-x86_64-toolchain`
(or `mingw-w64-i686-toolchain`) package.
Alternatively, install OpenSSL from [here][1]. Cargo will not be able to find OpenSSL if it's
installed to the default location. You can either copy the `include/openssl` installed to the default location. You can either copy the `include/openssl`
directory, `libssl32.dll`, and `libeay32.dll` to locations that Cargo can find directory, `libssl32.dll`, and `libeay32.dll` to locations that Cargo can find
or pass the location to Cargo via environment variables: or pass the location to Cargo via environment variables:

View File

@ -18,13 +18,22 @@ 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") {
vec!("eay32", "ssl32") if get_mingw_in_path().is_some() && lib_dir.is_none() && include_dir.is_none() {
vec!("eay32", "ssleay32")
} else {
vec!("eay32", "ssl32")
}
} else { } else {
vec!("crypto", "ssl") vec!("crypto", "ssl")
} }
@ -62,3 +71,25 @@ fn build_old_openssl_shim(include_paths: &[PathBuf]) {
config.file("src/old_openssl_shim.c") config.file("src/old_openssl_shim.c")
.compile("libold_openssl_shim.a"); .compile("libold_openssl_shim.a");
} }
fn get_mingw_in_path() -> Option<Vec<String>> {
match env::var_os("PATH") {
Some(env_path) => {
let paths: Vec<String> = env::split_paths(&env_path).filter_map(|path| {
use std::ascii::AsciiExt;
match path.to_str() {
Some(path_str) => {
if path_str.to_ascii_lowercase().contains("mingw") {
Some(path_str.to_string())
} else { None }
},
None => None
}
}).collect();
if paths.len() > 0 { Some(paths) } else { None }
},
None => None
}
}