'How to avoid dependency on libssl.so.10 and libcrypto.so.10

My handy little rust binary is working just fine when compiled and run on pretty much every system except the Ubuntu 18.04 I need it to run on. Why, you might ask?

error while loading shared libraries: libcrypto.so.10: cannot open shared object file: No such file or directory

For what it's worth, I'm sure it was complaining about libssl.so.10 previously - not sure what I did to make that go away.

Anyway, I gather the traditional fix for this is to update libssl - for reasons I won't bother going into here, I can't do that in this case. I've also tried symlinking libcrypto.so.1.0.0 - that just results in complaints about missing versions.

So, I'm hoping there's a way I can bundle this dependency into the binary instead of relying on it being available on the runtime system. I'm not sure at all how to go about this; can anyone suggest?

[dependencies]
async-trait = "0.1.48"
clap = "3.0.0-beta.2"
futures = "0.3"
rusoto_credential = "0.46.0"
rusoto_core = { version="0.46.0" }
rusoto_lambda = "0.46.0"
rusoto_sts = "0.46.0"
serde = "0.9"
serde_json = "0.9"
serde_derive = "0.9"
tokio = { version = "1", features = ["full"] }


Solution 1:[1]

Just add the following to your dependencies:

openssl = { version = "0.10", features = ["vendored"] }

and voila:

$ ldd target/debug/ssltest
        linux-vdso.so.1 (0x00007fffa538c000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7ab1a67000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7ab1a44000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7ab1a3e000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7ab184c000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f7ab2a07000)

See openssl crate documentation.

If the vendored Cargo feature is enabled, the openssl-src crate will be used to compile and statically link to a copy of OpenSSL.

Solution 2:[2]

Find the feature for Rust TLS for each crate that uses openssl.

Turn off its default features and turn on the feature for Rust TLS and the other features you use.

[dependencies.rusoto_core]
default-features = false
features = ["rustls"]
version = "0.48"

[dependencies.rusoto_secretsmanager]
default-features = false
features = ["rustls"]
version = "0.48"

I'd also recommend checking out cargo chef: https://github.com/LukeMathWalker/cargo-chef

Before that we ran into GLIBC version not found issues on most rust builder images.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kmdreko
Solution 2 Adam Gering