~1 min (157 words)
Rust and OpenSSL and static linking
Today I learned
While the default linking is dynamic for Rust and using OpenSSL you can change the default and use static linking as well. For my use case I had a different setup on the build machine and the target deployment (yes, no docker here). So I needed to statically link OpenSSL instead.
Turns out you can very easily change that in Rust via:
OPENSSL_STATIC=yes OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu OPENSSL_INCLUDE_DIR=/usr/include/ cargo build
The first OPENSSL_STATIC
param tells cargo to use static binding for OpenSSL.
Whilst the second param OPENSSL_LIB_DIR
is used to specify OpenSSL's library folder.
Last but not least we have OPENSSL_INCLUDE_DIR
for telling cargo where to find the OpenSSL header files.
And that's it.
Of course, in most cases you probably want dynamic linking (and get a smaller executable) but in some cases this helps a lot.