aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2015-06-20 18:07:41 -0400
committerSteven Fackler <[email protected]>2015-06-20 18:07:41 -0400
commitbfff71b7d6d74e390f3184c725388d8c1d17befa (patch)
tree845d24c38ca78581e6420289aac946964c040258
parentMerge pull request #226 from jethrogb/topic/crypto_iv_slice (diff)
parentMention mingw in README (diff)
downloadrust-openssl-bfff71b7d6d74e390f3184c725388d8c1d17befa.tar.xz
rust-openssl-bfff71b7d6d74e390f3184c725388d8c1d17befa.zip
Merge pull request #225 from semmaz/mingw-build-fix
Added support for building on Windows with MinGW
-rw-r--r--README.md10
-rw-r--r--openssl-sys/build.rs33
2 files changed, 41 insertions, 2 deletions
diff --git a/README.md b/README.md
index 887b09d4..6ce18d04 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,15 @@ rust-openssl to a separate installation.
### 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`
directory, `libssl32.dll`, and `libeay32.dll` to locations that Cargo can find
or pass the location to Cargo via environment variables:
diff --git a/openssl-sys/build.rs b/openssl-sys/build.rs
index 51d78ffc..de43c462 100644
--- a/openssl-sys/build.rs
+++ b/openssl-sys/build.rs
@@ -18,13 +18,22 @@ fn main() {
build_old_openssl_shim(&info.include_paths);
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 = match libs_env {
Some(ref v) => v.split(":").collect(),
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 {
vec!("crypto", "ssl")
}
@@ -62,3 +71,25 @@ fn build_old_openssl_shim(include_paths: &[PathBuf]) {
config.file("src/old_openssl_shim.c")
.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
+ }
+}