When using MSVC Rust on Windows, everything typically works out of the box, up until you decide to do some web stuff with hyper. Suddenly a new dependency, openssl, is failing to build and you have no idea how to fix it. Fortunately this guide is here to save you!
WARNING: OpenSSL 1.1 support was only added in openssl-sys = "0.9"
. Older versions only support up to OpenSSL 1.0.2. sfackler/rust-openssl#452
- First you will need to download and install OpenSSL itself. You can download an installer from http://slproweb.com/products/Win32OpenSSL.html. In particular you want the newest version and not the light version. Make sure it matches the version of Rust you have, if you're using
x86_64-pc-windows-msvc
you will want Win64, and if you're usingi9686-pc-windows-msvc
you will want Win32. For the purpose of example I have installedWin64 OpenSSL v1.0.2h
. - If all went well you should now have OpenSSL installed somewhere. For me it is
C:\OpenSSL-Win64
. Inside are three important folders,bin
include
andlib
. - You will want to set several environment variables, the values of which will depend on where you installed OpenSSL. For me I set them like so:
OPENSSL_LIB_DIR
=C:\OpenSSL-Win64\lib
OPENSSL_INCLUDE_DIR
=C:\OpenSSL-Win64\include
OPENSSL_LIBS
=libeay32:ssleay32
OPENSSL_DIR
=C:\OpenSSL-Win64
- Add
C:\OpenSSL-Win64\bin
toPATH
.
- Do a clean build of your project by doing
cargo clean
andcargo build
. - If you're still having issues with OpenSSL, find me so I can figure out what you did wrong.