diff --git a/README.md b/README.md index 887b09d4b589fd5b7b810fa714a71681d102ff87..6ce18d045298619660ff8f97bda10022422df6a4 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 51d78ffc9eb087dc546f2a7fd82049824132eb1a..de43c462f2c2ee40bf260e68f2e83835f197ca95 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> { + match env::var_os("PATH") { + Some(env_path) => { + let paths: Vec = 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 + } +}