diff --git a/README.md b/README.md index 14eb79add23d0641b3698277924649ddabc2a0ce..5066c22f03058483c839e90e71ff45d5ecfbe39a 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/appveyor.yml b/appveyor.yml index dd351e5c3b34eff4f578e5a254edc4da0b68070b..42a1aefecb872380511b5e28b1c25da0e6882a0c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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 diff --git a/openssl-sys/Cargo.toml b/openssl-sys/Cargo.toml index c419f6a49082ee51ece45546250b797491330236..918797e588f456a081d0a567db96ea794c846f8f 100644 --- a/openssl-sys/Cargo.toml +++ b/openssl-sys/Cargo.toml @@ -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" diff --git a/openssl-sys/build.rs b/openssl-sys/build.rs index bd52d104ea9f5c5158af5ad3feb548db85664b35..2064ac99505a3d374ceb9dae42554630432ff1d1 100644 --- a/openssl-sys/build.rs +++ b/openssl-sys/build.rs @@ -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 {