It is one of those days again:
error: failed to run custom build command for `openssl-sys v0.9.58` ... 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.
I want to compile crates including OpenSSL, but the OpenSSL dir is not found. I remember that I fixed this problem once, and for saving me some minutes the next time I write down how to do that now.
Most straight-forward solutions include setting the OPENSSL_DIR variable into some cellar. Ok, that’s for Homebrew folks; but I go with MacPorts which installs its packages somewhere else.
First, make sure openssl is installed:
$ sudo port install openssl $ port installed | grep openssl openssl @1.1.1h_0 (active)
Then you can inspect where ports put the files (there’s quite a lot documentation, so opening it in less makes exploring easier):
$ port contents openssl | less
You’ll see header files in
/opt/local/include/openssl/ and runtime libraries in
/opt/local/lib/. Fortunately, the documentation of the openssl-crate explains which variables we can set to find these paths. This is what we need in the environment:
export OPENSSL_INCLUDE_DIR=/opt/local/include export OPENSSL_LIB_DIR=/opt/local/lib
Note that the include dir does not contain the
With these environment variables set,
cargo build builds everything like a charm.