sfackler / rust-openssl

OpenSSL bindings for Rust
1.4k stars 749 forks source link

windows installation now undocumented #1062

Open rbtcollins opened 5 years ago

rbtcollins commented 5 years ago

There used to be pretty clear docs on getting rust-openssl to work on Windows, but with the move of the README content to the crate root that was dropped for some reason. I don't know about other folk but for me at least I keep digging back in README.md history to figure out the installation steps...

sfackler commented 5 years ago

Does the vendored feature not work for your use case?

rbtcollins commented 5 years ago

I wasn't really aware of it, but having looked - no, its strictly harder than installing OpenSSL - perl is not a default windows feature, nor is make, let alone any deeper components that may be needed... vcpkg would be the way to abstract out building a vendored copy on Windows I suppose.

sfackler commented 5 years ago

Ah right.

I think adding documentation pointing to vcpkg is the right way to go here.

crusty-dave commented 5 years ago

There are still no clear instructions as to how to get this to work on Windows.

Note the following (I have it installed via vcpkg):

vcpkg install openssl The following packages are already installed: openssl[core]:x86-windows Starting package 1/1: openssl:x86-windows Package openssl:x86-windows is already installed Elapsed time for package openssl:x86-windows: 694 us

Total elapsed time: 954.5 us

The package openssl is compatible with built-in CMake targets:

find_package(OpenSSL REQUIRED)
target_link_libraries(main PRIVATE OpenSSL::SSL OpenSSL::Crypto)

Yet, I still get build failures:

C:/Users//.cargo/bin/cargo.exe build --color=always --all --all-targets Compiling openssl-sys v0.9.43 error: failed to run custom build command for openssl-sys v0.9.43 process didn't exit successfully: C:\Users\<omitted>\git\cic.c\srv\jaims\examples\srx-sim\target\debug\build\openssl-sys-800a40edcf70fa3c\build-script-main (exit code: 101) --- stdout cargo:rustc-cfg=const_fn cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR unset cargo:rerun-if-env-changed=OPENSSL_LIB_DIR OPENSSL_LIB_DIR unset cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR unset cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR OPENSSL_INCLUDE_DIR unset cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR unset cargo:rerun-if-env-changed=OPENSSL_DIR OPENSSL_DIR unset note: vcpkg did not find openssl as libcrypto and libssl: Aborted because VCPKGRS_DYNAMIC is not set note: vcpkg did not find openssl as ssleay32 and libeay32: Aborted because VCPKGRS_DYNAMIC is not set

--- stderr thread 'main' panicked at '

Could not find directory of OpenSSL installation, and this -sys crate cannot proceed without this knowledge. If OpenSSL is installed and this crate had trouble finding it, you can set the OPENSSL_DIR environment variable for the compilation process.

Make sure you also have the development packages of openssl installed. For example, libssl-dev on Ubuntu or openssl-devel on Fedora.

If you're in a situation where you think the directory should be found automatically, please open a bug at https://github.com/sfackler/rust-openssl and include information about your system as well as this message.

$HOST = x86_64-pc-windows-msvc $TARGET = x86_64-pc-windows-msvc openssl-sys = 0.9.43

It looks like you're compiling for MSVC but we couldn't detect an OpenSSL installation. If there isn't one installed then you can try the rust-openssl README for more information about how to download precompiled binaries of OpenSSL:

https://github.com/sfackler/rust-openssl#windows

', C:\Users\.cargo\registry\src\github.com-1ecc6299db9ec823\openssl-sys-0.9.43\build\find_normal.rs:150:5 stack backtrace: 0: std::sys::windows::backtrace::set_frames at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\sys\windows\backtrace\mod.rs:94 1: std::sys::windows::backtrace::unwind_backtrace at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\sys\windows\backtrace\mod.rs:81 2: std::sys_common::backtrace::_print at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\sys_common\backtrace.rs:70 3: std::sys_common::backtrace::print at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\sys_common\backtrace.rs:58 4: std::panicking::default_hook::{{closure}} at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\panicking.rs:200 5: std::panicking::default_hook at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\panicking.rs:215 6: std::panicking::rust_panic_with_hook at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\panicking.rs:478 7: std::panicking::begin_panic at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\panicking.rs:412 8: build_script_main::find::find_openssl_dir at .\build\find_normal.rs:150 9: build_script_main::find::get_openssl::{{closure}} at .\build\find_normal.rs:13 10: core::option::Option::unwrap_or_else<std::ffi::os_str::OsString,closure> at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libcore\option.rs:386 11: build_script_main::find::get_openssl at .\build\find_normal.rs:13 12: build_script_main::main at .\build\main.rs:49 13: std::rt::lang_start::{{closure}}<()> at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\rt.rs:64 14: std::rt::lang_start_internal::{{closure}} at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\rt.rs:49 15: std::panicking::try::do_call<closure,i32> at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\panicking.rs:297 16: panic_unwind::__rust_maybe_catch_panic at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libpanic_unwind\lib.rs:92 17: std::panicking::try at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\panicking.rs:276 18: std::panic::catch_unwind at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\panic.rs:388 19: std::rt::lang_start_internal at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\rt.rs:48 20: std::rt::lang_start<()> at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\rt.rs:64 21: main 22: invoke_main at d:\agent_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78 23: __scrt_common_main_seh at d:\agent_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288 24: BaseThreadInitThunk 25: RtlUserThreadStart

Process finished with exit code 101

sfackler commented 5 years ago

note: vcpkg did not find openssl as libcrypto and libssl: Aborted because VCPKGRS_DYNAMIC is not set note: vcpkg did not find openssl as ssleay32 and libeay32: Aborted because VCPKGRS_DYNAMIC is not set

https://docs.rs/vcpkg/0.2.6/vcpkg/

eminence commented 5 years ago

Using vcpkg was actually amazing easy. Here's what I did:

And that was it!

crusty-dave commented 5 years ago

Still no joy here:

running "c:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\cl.exe" "/nologo" "/MD" "/O2" "/I" "include" "/W4" "/GS" "/Gy" "/EHsc" "/GR-" "/Zc:wchar_t" "/Zc:forScope" "/Zc:inline" "/Zc:rvalueCast" "/sdl" "/Wall" "/wd4127" "/wd4464" "/wd4514" "/wd4710" "/wd4711" "/wd4820" "/wd5045" "/Ox" "/DNDEBUG" "-c" "/Foc:\\staging\\workspace\\Windows\\release\\build\\ring-575ac4f8c1c28c07\\out\\aes.obj" "crypto/fipsmodule/aes/aes.c"
aes.c
c1: fatal error C1083: Cannot open source file: 'crypto/fipsmodule/aes/aes.c': No such file or directory

VCIDEINSTALLDIR: c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\
VCINSTALLDIR: c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\
**VCPKGRS_DYNAMIC: 1**
VCTOOLSINSTALLDIR: c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\
VCTOOLSREDISTDIR: c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Redist\MSVC\14.16.27012\
VCTOOLSVERSION: 14.16.27023
VISUALSTUDIOVERSION: 15.0
VS140COMNTOOLS: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\
VS150COMNTOOLS: c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\
VSCMD_ARG_APP_PLAT: Desktop
VSCMD_ARG_HOST_ARCH: x86
VSCMD_ARG_TGT_ARCH: x64
VSCMD_VER: 15.9.8
VSINSTALLDIR: c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\
WINDIR: C:\Windows
WINDOWSLIBPATH: C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.17763.0;C:\Program Files (x86)\Windows Kits\10\References\10.0.17763.0
WINDOWSSDKBINPATH: C:\Program Files (x86)\Windows Kits\10\bin\
WINDOWSSDKDIR: C:\Program Files (x86)\Windows Kits\10\
WINDOWSSDKLIBVERSION: 10.0.17763.0\
WINDOWSSDKVERBINPATH: C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\
WINDOWSSDKVERSION: 10.0.17763.0\
WINDOWSSDK_EXECUTABLEPATH_X64: C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\
WINDOWSSDK_EXECUTABLEPATH_X86: C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\

Note that I installed openssl via Jenkins to ensure the permissions would be correct:

c:\build-tools\vcpkg>.\vcpkg integrate install 
Applied user-wide integration for this vcpkg root.

All MSBuild C++ projects can now #include any installed libraries.
Linking will be handled automatically.
Installing new libraries will make them instantly available.

CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=c:/build-tools/vcpkg/scripts/buildsystems/vcpkg.cmake"

c:\build-tools\vcpkg>.\vcpkg install openssl-windows:x64-windows 
The following packages will be built and installed:
    openssl-windows[core]:x64-windows
Starting package 1/1: openssl-windows:x64-windows
Building package openssl-windows[core]:x64-windows...
A suitable version of cmake was not found (required v3.14.0). Downloading portable cmake v3.14.0...
Downloading cmake...
  https://github.com/Kitware/CMake/releases/download/v3.14.0/cmake-3.14.0-win32-x86.zip -> c:\build-tools\vcpkg\downloads\cmake-3.14.0-win32-x86.zip
Extracting cmake...
A suitable version of 7zip was not found (required v18.1.0). Downloading portable 7zip v18.1.0...
Downloading 7zip...
  https://www.nuget.org/api/v2/package/7-Zip.CommandLine/18.1.0 -> c:\build-tools\vcpkg\downloads\7-zip.commandline.18.1.0.nupkg
Extracting 7zip...
A suitable version of nuget was not found (required v4.6.2). Downloading portable nuget v4.6.2...
Downloading nuget...
  https://dist.nuget.org/win-x86-commandline/v4.6.2/nuget.exe -> c:\build-tools\vcpkg\downloads\nuget.exe
A suitable version of git was not found (required v2.21.0). Downloading portable git v2.21.0...
Downloading git...
  https://github.com/git-for-windows/git/releases/download/v2.21.0.windows.1/PortableGit-2.21.0-32-bit.7z.exe -> c:\build-tools\vcpkg\downloads\PortableGit-2.21.0-32-bit.7z.exe
Extracting git...
-- Downloading http://strawberryperl.com/download/5.24.1.1/strawberry-perl-5.24.1.1-32bit-portable.zip...
-- Downloading https://www.openssl.org/source/openssl-1.0.2q.tar.gz...
-- Extracting source C:/build-tools/vcpkg/downloads/openssl-1.0.2q.tar.gz
-- Applying patch ConfigureIncludeQuotesFix.patch
-- Applying patch STRINGIFYPatch.patch
-- Applying patch EnableWinARM32.patch
-- Applying patch EmbedSymbolsInStaticLibsZ7.patch
-- Applying patch EnableWinARM64.patch
-- Downloading http://www.nasm.us/pub/nasm/releasebuilds/2.14/win32/nasm-2.14-win32.zip...
-- Downloading http://download.qt.io/official_releases/jom/jom_1_1_3.zip...
-- Configure x64-windows-rel
-- Configure x64-windows-rel done
-- Build x64-windows-rel
-- Build x64-windows-rel done
-- Configure x64-windows-dbg
-- Configure x64-windows-dbg done
-- Build x64-windows-dbg
-- Build x64-windows-dbg done
-- Installing: C:/build-tools/vcpkg/packages/openssl-windows_x64-windows/share/openssl-windows/copyright
-- Performing post-build validation
-- Performing post-build validation done
Building package openssl-windows[core]:x64-windows... done
Installing package openssl-windows[core]:x64-windows...
Installing package openssl-windows[core]:x64-windows... done
Elapsed time for package openssl-windows:x64-windows: 11.27 min

Total elapsed time: 11.27 min

The package openssl is compatible with built-in CMake targets:

    find_package(OpenSSL REQUIRED)

    target_link_libraries(main PRIVATE OpenSSL::SSL OpenSSL::Crypto)

I surely have something wrong in the build environment (it builds OK from my account, it fails from Jenkins). This has been stumping me for a long time, every couple of months I try to tackle it and then give up. (I have a script that will take manually built files and package them for now, but I would like to automate the whole bloody mess).

Thanks for all the help tidbits so far, -Dave

eminence commented 5 years ago

VSCMD_ARG_HOST_ARCH: x86 VSCMD_ARG_TGT_ARCH: x64

this looks like your machine is 32-bit (x86), but is cross compiling to a 64-bit target (x64). That sounds a little unusual. Can you confirm if that is actually expected for your environment?

crusty-dave commented 5 years ago

It should be x64, it looks like it downloaded the wrong version of cmake?

Downloading cmake... https://github.com/Kitware/CMake/releases/download/v3.14.0/cmake-3.14.0-win32-x86.zip -> c:\build-tools\vcpkg\downloads\cmake-3.14.0-win32-x86.zip

Thanks, -Dave

crusty-dave commented 5 years ago

I manually set it to the following:

VSCMD_ARG_HOST_ARCH=x64
VSCMD_ARG_TGT_ARCH=x64

However, when the build failed, it was set as follows:

VSCMD_ARG_HOST_ARCH: x86
VSCMD_ARG_TGT_ARCH: x64

Everything else looks OK:

PLATFORM: x64
PROCESSOR_ARCHITECTURE: AMD64
PROCESSOR_IDENTIFIER: Intel64 Family 6 Model 63 Stepping 2, GenuineIntel
PROCESSOR_LEVEL: 6
PROCESSOR_REVISION: 3f02
PROFILE: release

RUST_BIN: \rust-toolchain01\rustup\x86_64-pc-windows-msvc\1.34.0\bin
SERVICE_ID: jenkinsslave-c__staging
SYSTEMDRIVE: C:
SYSTEMROOT: C:\Windows
TARGET: x86_64-pc-windows-msvc
crusty-dave commented 5 years ago

I found the following

VCPKG_DEFAULT_TRIPLET=x64-windows

but while installing 64-bit openssl, it still looks to be installing 32-bit packages, I guess I will have to wait to see what it actually builds this time.

crusty-dave commented 5 years ago

I guess I am giving up for another month or so, this is very frustrating...

   Compiling ring v0.13.5
   Compiling miniz_oxide_c_api v0.2.1
   Compiling regex-syntax v0.6.6
   Compiling serde_test v0.8.23
   Compiling crc v1.8.1
   Compiling unreachable v1.0.0
   Compiling humantime v1.2.0
   Compiling yaml-rust v0.4.3
   Compiling lru-cache v0.1.2
   Compiling scheduled-thread-pool v0.2.0
   Compiling miniz_oxide v0.2.1
   Compiling hash_ring v0.1.7
   Compiling iovec v0.1.2
   Compiling textwrap v0.11.0
   Compiling rand_xorshift v0.1.1
   Compiling rand_hc v0.1.0
   Compiling rand_isaac v0.1.1
   Compiling rustc_version v0.2.3
   Compiling lock_api v0.1.5
   Compiling log v0.3.9
   Compiling crossbeam-queue v0.1.2
   Compiling tokio-executor v0.1.7
   Compiling crossbeam-channel v0.3.8
   Compiling encoding v0.2.33
   Compiling idna v0.1.5
error: failed to run custom build command for `ring v0.13.5`
process didn't exit successfully: `c:\staging\workspace\JIMS\jims-validator-win\jaims\Windows\release\build\ring-223915c6fb20e8f4\build-script-build` (exit code: 101)

VCIDEINSTALLDIR: c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\
VCINSTALLDIR: c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\
VCPKGRS_DYNAMIC: 1
VCPKG_DEFAULT_TRIPLET: x64-windows
VCPKG_ROOT: \build-tools\vcpkg
VCTOOLSINSTALLDIR: c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\
VCTOOLSREDISTDIR: c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Redist\MSVC\14.16.27012\
VCTOOLSVERSION: 14.16.27023
VISUALSTUDIOVERSION: 15.0
VS140COMNTOOLS: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\
VS150COMNTOOLS: c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\
VSCMD_ARG_APP_PLAT: Desktop
VSCMD_ARG_HOST_ARCH: x86
VSCMD_ARG_TGT_ARCH: x64
VSCMD_VER: 15.9.11

TARGET = Some("x86_64-pc-windows-msvc")
HOST = Some("x86_64-pc-windows-msvc")
CC_x86_64-pc-windows-msvc = None
CC_x86_64_pc_windows_msvc = None
HOST_CC = None
CC = None
CFLAGS_x86_64-pc-windows-msvc = None
CFLAGS_x86_64_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
DEBUG = Some("false")
running "c:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\cl.exe" "/nologo" "/MD" "/O2" "/I" "include" "/W4" "/GS" "/Gy" "/EHsc" "/GR-" "/Zc:wchar_t" "/Zc:forScope" "/Zc:inline" "/Zc:rvalueCast" "/sdl" "/Wall" "/wd4127" "/wd4464" "/wd4514" "/wd4710" "/wd4711" "/wd4820" "/wd5045" "/Ox" "/DNDEBUG" "-c" "/Foc:\\staging\\workspace\\JIMS\\jims-validator-win\\jaims\\Windows\\release\\build\\ring-575ac4f8c1c28c07\\out\\aes.obj" "crypto/fipsmodule/aes/aes.c"
aes.c
c1: fatal error C1083: Cannot open source file: 'crypto/fipsmodule/aes/aes.c': No such file or directory
crusty-dave commented 5 years ago

FYI: there seems to be nothing wrong with the openssl installation, it is just ring...

C:\build-tools\vcpkg>.\vcpkg integrate install
Applied user-wide integration for this vcpkg root.

All MSBuild C++ projects can now #include any installed libraries.
Linking will be handled automatically.
Installing new libraries will make them instantly available.

CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/build-tools/vcpkg/scripts/buildsystems/vcpkg.cmake"

C:\build-tools\vcpkg>.\vcpkg install openssl:x64-windows

The following packages will be built and installed:
    openssl[core]:x64-windows
  * openssl-windows[core]:x64-windows
Additional packages (*) will be modified to complete this operation.
Starting package 1/2: openssl-windows:x64-windows
Building package openssl-windows[core]:x64-windows...
A suitable version of cmake was not found (required v3.14.0). Downloading portable cmake v3.14.0...
Downloading cmake...
  https://github.com/Kitware/CMake/releases/download/v3.14.0/cmake-3.14.0-win32-x86.zip -> C:\build-tools\vcpkg\downloads\cmake-3.14.0-win32-x86.zip
Extracting cmake...
A suitable version of 7zip was not found (required v18.1.0). Downloading portable 7zip v18.1.0...
Downloading 7zip...
  https://www.nuget.org/api/v2/package/7-Zip.CommandLine/18.1.0 -> C:\build-tools\vcpkg\downloads\7-zip.commandline.18.1.0.nupkg
Extracting 7zip...
A suitable version of nuget was not found (required v4.6.2). Downloading portable nuget v4.6.2...
Downloading nuget...
  https://dist.nuget.org/win-x86-commandline/v4.6.2/nuget.exe -> C:\build-tools\vcpkg\downloads\nuget.exe
A suitable version of git was not found (required v2.21.0). Downloading portable git v2.21.0...
Downloading git...
  https://github.com/git-for-windows/git/releases/download/v2.21.0.windows.1/PortableGit-2.21.0-32-bit.7z.exe -> C:\build-tools\vcpkg\downloads\PortableGit-2.21.0-32-bit.7z.exe
Extracting git...
-- Downloading http://strawberryperl.com/download/5.24.1.1/strawberry-perl-5.24.1.1-32bit-portable.zip...
-- Downloading https://www.openssl.org/source/openssl-1.0.2q.tar.gz...
-- Extracting source C:/build-tools/vcpkg/downloads/openssl-1.0.2q.tar.gz
-- Applying patch ConfigureIncludeQuotesFix.patch
-- Applying patch STRINGIFYPatch.patch
-- Applying patch EnableWinARM32.patch
-- Applying patch EmbedSymbolsInStaticLibsZ7.patch
-- Applying patch EnableWinARM64.patch
-- Downloading http://www.nasm.us/pub/nasm/releasebuilds/2.14/win32/nasm-2.14-win32.zip...
-- Downloading http://download.qt.io/official_releases/jom/jom_1_1_3.zip...
-- Configure x64-windows-rel
-- Configure x64-windows-rel done
-- Build x64-windows-rel
-- Build x64-windows-rel done
-- Configure x64-windows-dbg
-- Configure x64-windows-dbg done
-- Build x64-windows-dbg
-- Build x64-windows-dbg done
-- Installing: C:/build-tools/vcpkg/packages/openssl-windows_x64-windows/share/openssl-windows/copyright
-- Performing post-build validation
-- Performing post-build validation done
Building package openssl-windows[core]:x64-windows... done
Installing package openssl-windows[core]:x64-windows...
Installing package openssl-windows[core]:x64-windows... done
Elapsed time for package openssl-windows:x64-windows: 9.877 min
Starting package 2/2: openssl:x64-windows
Building package openssl[core]:x64-windows...
-- Installing: C:/build-tools/vcpkg/packages/openssl_x64-windows/share/openssl//usage
-- Performing post-build validation
-- Performing post-build validation done
Building package openssl[core]:x64-windows... done
Installing package openssl[core]:x64-windows...
Installing package openssl[core]:x64-windows... done
Elapsed time for package openssl:x64-windows: 2.133 s

Total elapsed time: 9.913 min

The package openssl is compatible with built-in CMake targets:

    find_package(OpenSSL REQUIRED)
    target_link_libraries(main PRIVATE OpenSSL::SSL OpenSSL::Crypto)
crusty-dave commented 5 years ago

It is also unclear to me what I am supposed to do with this information from the openssl build?

CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/build-tools/vcpkg/scripts/buildsystems/vcpkg.cmake"

crusty-dave commented 5 years ago

With help from @tmfink, I was able to get my Jenkins build working.

It turns out that when running as a service, Jenkins was getting a default profile under Windows\System32. It seemed like there might have been some permissions issues.

I created a new directory under \Users for the service account that we were using for Jenkins and pointed CARGO_HOME to it. Now ring is finding the files correctly and building, so all is good - at least for now.

Thanks for the help with this, there were issues that I needed to solve with vcpkg first before I was able to get this far.

kjeremy commented 5 years ago

The instructions from https://github.com/sfackler/rust-openssl/issues/1062#issuecomment-489441940 worked for me when building tonic but only with dynamic linking. I could not get the static lib recognized.

I also could not get the VCPKGRS_DYNAMIC variable recognized from git bash and had to run cargo from cmd.exe

quonic commented 4 years ago

It seems once I get openssl installed with vcpkg, run the integrate command, then set the following env vars it all works. (Using my paths as an example)

$env:OPENSSL_DIR="C:\\Dev\\vcpkg\\installed\\x64-windows"
$env:OPENSSL_LIB_DIR="C:\\Dev\\vcpkg\\installed\\x64-windows\\lib"
$env:OPENSSL_INCLUDE_DIR="C:\\Dev\\vcpkg\\installed\\x64-windows\\include"

or if I set VCPKGRS_DYNAMIC to 1.

From what I can tell the needed steps are to grab vcpkg, run the bootstrap-vcpkg.bat, install the 64bit version of openssl, vcpkg integrate install, then set the VCPKGRS_DYNAMIC env var to 1 for your user account or system. If setting VCPKGRS_DYNAMIC doesn't work, then the three OPENSSL env vars will need to be set accordingly.

crusty-dave commented 4 years ago

Does rust-openssl work with openssl 1.1.1d?

I am trying to build it on Windows by manually providing the environment variables (in this case I cannot use vcpkg), but even though the path exists, the build fails:

error: failed to run custom build command for `openssl-sys v0.9.53`

Caused by:
  process didn't exit successfully: `C:\Users\me\git\my-proj\srv\project\name\../../../test/Windows\debug\build\openssl-sys-50137a38667263ad\build-script-main` (exit code: 101)
--- stdout
cargo:rustc-cfg=const_fn
cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR
X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR = "c:/Users/me/git/my-proj/ext/OpenSSL/openssl-1.1.1d"
cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR
X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR = "c:/Users/me/git/my-proj/ext/OpenSSL/openssl-1.1.1d/include/openssl"

--- stderr
thread 'main' panicked at 'OpenSSL library directory does not exist: "c:/Users/me/git/my-proj/ext/OpenSSL/openssl-1.1.1d"', C:\Users\me\.cargo\registry\src\github.com-1ecc6299db9ec823\openssl-sys-0.9.53\build/main.rs:52:9

directory contents (*.lib):

 Directory of c:\Users\me\git\my-proj\ext\OpenSSL\openssl-1.1.1d

12/14/2019  03:54 PM           991,470 libcrypto.lib
12/14/2019  03:54 PM        19,146,930 libcrypto_static.lib
12/14/2019  03:56 PM           119,882 libssl.lib
12/14/2019  03:57 PM         3,762,994 libssl_static.lib

Resolved above issue: Apparently the directory check didn't like the quoted path.

OPENSSL_DIR=c:/Users/me/git/my-proj/ext/OpenSSL/openssl-1.1.1d
OPENSSL_INCLUDE_DIR=c:/Users/me/git/my-proj/ext/OpenSSL/openssl-1.1.1d/include
OPENSSL_LIB_DIR=c:/Users/me/git/my-proj/ext/OpenSSL/openssl-1.1.1d
X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR=c:/Users/me/git/my-proj/ext/OpenSSL/openssl-1.1.1d/include
X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR=c:/Users/me/git/my-proj/ext/OpenSSL/openssl-1.1.1d

Plus the include path was one level too deep.

Charles-Schleich commented 4 years ago

Also struggling here, managed to get it to work. I have installed vcpkg, then ran vcpkg install openssl then set setx VCPKGRS_DYNAMIC 1

Still failing to build, with the following error.

error: failed to run custom build command for `openssl-sys v0.9.54`

Caused by:
  process didn't exit successfully: `C:\Users\Charlie\thoghtexpress\browser-native-launcher\target\debug\build\openssl-sys-e03a14a35d1c34dc\build-script-main` (exit code: 101)
--- stdout
cargo:rustc-cfg=const_fn
cargo:rerun-if-env-changed=I686_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR
I686_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR unset
cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
OPENSSL_LIB_DIR unset
cargo:rerun-if-env-changed=I686_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR
I686_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR unset
cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
OPENSSL_INCLUDE_DIR unset
cargo:rerun-if-env-changed=I686_PC_WINDOWS_MSVC_OPENSSL_DIR
I686_PC_WINDOWS_MSVC_OPENSSL_DIR unset
cargo:rerun-if-env-changed=OPENSSL_DIR
OPENSSL_DIR unset
note: vcpkg did not find openssl as libcrypto and libssl: Could not find library in Vcpkg tree C:\Users\Charlie\code\vcpkg\installed\x86-windows\bin\libcrypto.dll
note: vcpkg did not find openssl as ssleay32 and libeay32: Could not find library in Vcpkg tree C:\Users\Charlie\code\vcpkg\installed\x86-windows\lib\libeay32.lib

--- stderr
thread 'main' panicked at '

Could not find directory of OpenSSL installation, and this `-sys` crate cannot
proceed without this knowledge. If OpenSSL is installed and this crate had
trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
compilation process.

Make sure you also have the development packages of openssl installed.
For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.

If you're in a situation where you think the directory *should* be found
automatically, please open a bug at https://github.com/sfackler/rust-openssl
and include information about your system as well as this message.

$HOST = i686-pc-windows-msvc
$TARGET = i686-pc-windows-msvc
openssl-sys = 0.9.54

It looks like you're compiling for MSVC but we couldn't detect an OpenSSL
installation. If there isn't one installed then you can try the rust-openssl
README for more information about how to download precompiled binaries of
OpenSSL:

https://github.com/sfackler/rust-openssl#windows

', C:\Users\Charlie\.cargo\registry\src\github.com-1ecc6299db9ec823\openssl-sys-0.9.54\build\find_normal.rs:150:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

warning: build failed, waiting for other jobs to finish...
error: build failed

However, this is because openssl-sys looks for libcrypto and libssl which are named libcrypto-1_1 and libssl-1_1 in the install directory for vcpkg. \vcpkg\installed\x86-windows\bin\

Renaming them to libcrypto and libssl results in a successful build, but we shouldn't have to rename files to get libraries to build.
Is there a better way to solve this problem ?

sfackler commented 4 years ago

You need to update your openssl-sys version to pick up https://github.com/sfackler/rust-openssl/commit/03b8b29e4c638ea05415520aff6a3a75f1200ad7#diff-e9f0c58bb4bf8069bc30ffead1ff6b2e

arthmis commented 3 years ago

Hello, would it not be possible to add some notes on the readme on ways to use vcpkg to install openssl?

runapp commented 3 years ago

It's still open... A link to either or both of the vcpkg comments above in README would be enough to save several minutes for each one trying to install it on Windows.

Zageron commented 3 years ago

Ran into this, doesn't work in gitbash at all.

martinfiers commented 3 years ago

For what it's worth, what I had to do is install vcpkg (regular installation), and then do this:

vcpkg integrate install
vcpkg.exe install openssl:x64-windows-static-md

That seemed to help in my case.

andyblarblar commented 3 years ago

For what it's worth, what I had to do is install vcpkg (regular installation), and then do this:

vcpkg integrate install
vcpkg.exe install openssl:x64-windows-static-md

That seemed to help in my case.

This worked right off the bat for me. Simply linking to these commands in the readme would make a huge difference for consumers of dependents of this crate, as the compile error takes a bit of digging to solve (and for me at least, the old vcpkg instructions were actually wrong, as I did not need to point to any sort of authentication roots to build).

tejasvi commented 2 years ago

To summarize, following can be shown during compile error:

git clone https://github.com/Microsoft/vcpkg --depth=1
vcpkg/bootstrap-vcpkg.bat
vcpkg/vcpkg.exe integrate install
vcpkg/vcpkg.exe install openssl:x64-windows-static