for msvc abi builds, allow use of openssl libs from vcpkg

This commit is contained in:
Jim McGrath 2017-06-07 09:56:06 -05:00
parent 478957c0f6
commit 6b50d8940d
4 changed files with 82 additions and 4 deletions

View File

@ -70,7 +70,11 @@ automatically detected.
### Windows MSVC
On MSVC it's unfortunately not always a trivial process acquiring OpenSSL.
On MSVC it's unfortunately not always a trivial process acquiring OpenSSL. A couple of possibilities
are downloading precompiled binaries for OpenSSL 1.1.0, or installing OpenSSL 1.0.2 using vcpkg.
#### Installing OpenSSL 1.1.0 using precompiiled binaries
Perhaps the easiest way to do this right now is to download [precompiled
binaries] and install them on your system. Currently it's recommended to
install the 1.1.0 (non-light) installation if you're choosing this route.
@ -84,7 +88,24 @@ installation via an environment variable:
set OPENSSL_DIR=C:\OpenSSL-Win64
```
Note that this OpenSSL distribution does not ship with any root certificates.
Now you will need to [install root certificates.](#acquiring-root-certificates)
#### Installing OpenSSL 1.0.2 using vcpkg
Install [vcpkg](https://github.com/Microsoft/vcpkg), and install the OpenSSL port like this:
```Batchfile
vcpkg install openssl:x64-windows
set VCPKG_ROOT=c:\path\to\vcpkg\installation
cargo build
```
For more information see the vcpkg build helper [documentation](http://docs.rs/vcpkg).
To finsh setting up OpenSSL you will need to [install root certificates.](#acquiring-root-certificates)
#### Acquiring Root Certificates
Neither of the above OpenSSL distributions ship with any root certificates.
So to make requests to servers on the internet, you have to install them
manually. Download the [cacert.pem file from here], copy it somewhere safe
(`C:\OpenSSL-Win64\certs` is a good place) and point the `SSL_CERT_FILE`

View File

@ -20,10 +20,13 @@ environment:
BITS: 32
OPENSSL_VERSION: 1_0_2L
OPENSSL_DIR: C:\OpenSSL
- TARGET: x86_64-pc-windows-msvc
VCPKG_DEFAULT_TRIPLET: x64-windows
install:
# install OpenSSL
- ps: Start-FileDownload "http://slproweb.com/download/Win${env:BITS}OpenSSL-${env:OPENSSL_VERSION}.exe"
- Win%BITS%OpenSSL-%OPENSSL_VERSION%.exe /SILENT /VERYSILENT /SP- /DIR="C:\OpenSSL"
- mkdir C:\OpenSSL
- ps: if (Test-Path env:OPENSSL_VERSION) { Start-FileDownload "http://slproweb.com/download/Win${env:BITS}OpenSSL-${env:OPENSSL_VERSION}.exe" }
- if defined OPENSSL_VERSION Win%BITS%OpenSSL-%OPENSSL_VERSION%.exe /SILENT /VERYSILENT /SP- /DIR="C:\OpenSSL"
- appveyor DownloadFile https://curl.haxx.se/ca/cacert.pem -FileName C:\OpenSSL\cacert.pem
# Install Rust
@ -33,6 +36,10 @@ install:
- if defined MSYS2 set PATH=C:\msys64\mingw%BITS%\bin;%PATH%
- rustc -V
- cargo -V
- if defined VCPKG_DEFAULT_TRIPLET git clone https://github.com/Microsoft/vcpkg c:\projects\vcpkg
- if defined VCPKG_DEFAULT_TRIPLET c:\projects\vcpkg\bootstrap-vcpkg.bat
- if defined VCPKG_DEFAULT_TRIPLET set VCPKG_ROOT=c:\projects\vcpkg
- if defined VCPKG_DEFAULT_TRIPLET %VCPKG_ROOT%\vcpkg.exe install openssl
build: false

View File

@ -18,6 +18,9 @@ libc = "0.2"
pkg-config = "0.3.9"
gcc = "0.3.42"
[target.'cfg(target_env = "msvc")'.build-dependencies]
vcpkg = "0.2"
# We don't actually use metadeps for annoying reasons but this is still here for tooling
[package.metadata.pkg-config]
openssl = "1.0.1"

View File

@ -1,4 +1,6 @@
extern crate pkg_config;
#[cfg(target_env = "msvc")]
extern crate vcpkg;
extern crate gcc;
use std::collections::HashSet;
@ -98,6 +100,7 @@ fn find_openssl_dir(target: &str) -> OsString {
}
try_pkg_config();
try_vcpkg();
let mut msg = format!("
@ -213,6 +216,50 @@ fn try_pkg_config() {
std::process::exit(0);
}
/// Attempt to find OpenSSL through vcpkg.
///
/// Note that if this succeeds then the function does not return as vcpkg
/// should emit all of the cargo metadata that we need.
#[cfg(target_env = "msvc")]
fn try_vcpkg() {
// vcpkg will not emit any metadata if it can not find libraries
// appropriate for the target triple with the desired linkage.
let mut lib = vcpkg::Config::new()
.emit_includes(true)
.lib_name("libcrypto")
.lib_name("libssl")
.probe("openssl");
if let Err(e) = lib {
println!("note: vcpkg did not find openssl as libcrypto and libssl : {:?}",
e);
lib = vcpkg::Config::new()
.emit_includes(true)
.lib_name("libeay32")
.lib_name("ssleay32")
.probe("openssl");
}
if let Err(e) = lib {
println!("note: vcpkg did not find openssl as ssleay32 and libeay32: {:?}",
e);
return;
}
let lib = lib.unwrap();
validate_headers(&lib.include_paths);
println!("cargo:rustc-link-lib=user32");
println!("cargo:rustc-link-lib=gdi32");
println!("cargo:rustc-link-lib=crypt32");
std::process::exit(0);
}
#[cfg(not(target_env = "msvc"))]
fn try_vcpkg() {}
/// Validates the header files found in `include_dir` and then returns the
/// version string of OpenSSL.
fn validate_headers(include_dirs: &[PathBuf]) -> Version {