Merge pull request #622 from mcgoo/vcpkg
try to find openssl libraries in a vcpkg ports tree
This commit is contained in:
commit
75d927b2bd
25
README.md
25
README.md
|
|
@ -70,7 +70,11 @@ automatically detected.
|
||||||
|
|
||||||
### Windows MSVC
|
### 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
|
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
|
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.
|
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
|
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
|
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
|
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`
|
(`C:\OpenSSL-Win64\certs` is a good place) and point the `SSL_CERT_FILE`
|
||||||
|
|
|
||||||
12
appveyor.yml
12
appveyor.yml
|
|
@ -20,10 +20,14 @@ environment:
|
||||||
BITS: 32
|
BITS: 32
|
||||||
OPENSSL_VERSION: 1_0_2L
|
OPENSSL_VERSION: 1_0_2L
|
||||||
OPENSSL_DIR: C:\OpenSSL
|
OPENSSL_DIR: C:\OpenSSL
|
||||||
|
- TARGET: x86_64-pc-windows-msvc
|
||||||
|
VCPKG_DEFAULT_TRIPLET: x64-windows
|
||||||
|
VCPKGRS_DYNAMIC: 1
|
||||||
install:
|
install:
|
||||||
# install OpenSSL
|
# install OpenSSL
|
||||||
- ps: Start-FileDownload "http://slproweb.com/download/Win${env:BITS}OpenSSL-${env:OPENSSL_VERSION}.exe"
|
- mkdir C:\OpenSSL
|
||||||
- Win%BITS%OpenSSL-%OPENSSL_VERSION%.exe /SILENT /VERYSILENT /SP- /DIR="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
|
- appveyor DownloadFile https://curl.haxx.se/ca/cacert.pem -FileName C:\OpenSSL\cacert.pem
|
||||||
|
|
||||||
# Install Rust
|
# Install Rust
|
||||||
|
|
@ -33,6 +37,10 @@ install:
|
||||||
- if defined MSYS2 set PATH=C:\msys64\mingw%BITS%\bin;%PATH%
|
- if defined MSYS2 set PATH=C:\msys64\mingw%BITS%\bin;%PATH%
|
||||||
- rustc -V
|
- rustc -V
|
||||||
- cargo -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
|
build: false
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@ libc = "0.2"
|
||||||
pkg-config = "0.3.9"
|
pkg-config = "0.3.9"
|
||||||
gcc = "0.3.42"
|
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
|
# We don't actually use metadeps for annoying reasons but this is still here for tooling
|
||||||
[package.metadata.pkg-config]
|
[package.metadata.pkg-config]
|
||||||
openssl = "1.0.1"
|
openssl = "1.0.1"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
extern crate pkg_config;
|
extern crate pkg_config;
|
||||||
|
#[cfg(target_env = "msvc")]
|
||||||
|
extern crate vcpkg;
|
||||||
extern crate gcc;
|
extern crate gcc;
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
@ -110,6 +112,7 @@ fn find_openssl_dir(target: &str) -> OsString {
|
||||||
}
|
}
|
||||||
|
|
||||||
try_pkg_config();
|
try_pkg_config();
|
||||||
|
try_vcpkg();
|
||||||
|
|
||||||
let mut msg = format!(
|
let mut msg = format!(
|
||||||
"
|
"
|
||||||
|
|
@ -235,6 +238,50 @@ fn try_pkg_config() {
|
||||||
std::process::exit(0);
|
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
|
/// Validates the header files found in `include_dir` and then returns the
|
||||||
/// version string of OpenSSL.
|
/// version string of OpenSSL.
|
||||||
fn validate_headers(include_dirs: &[PathBuf]) -> Version {
|
fn validate_headers(include_dirs: &[PathBuf]) -> Version {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue