However, rustls now works well with most of the Rust ecosystem, including reqwest, tokio and many others.
- See if you can switch away from OpenSSL, typically by using
featuresinCargo.tomlto ask your dependencies to userustlsinstead. - If you don't need OpenSSL, try
cross build --target=x86_64-unknown-linux-musl --releaseto cross-compile your binaries forlibmusl. This supports many more platforms, with less hassle!
This image allows you to build static Rust binaries using openssl. These images can be distributed as single executable files with no dependencies, and they should work on any modern Linux system.
With a bit of luck, you should be able to just copy your application binary from target/x86_64-unknown-linux-musl/release, and install it directly on any reasonably modern x86_64 Linux machine. In particular, you should be able make static release binaries using TravisCI and GitHub, or you can copy your Rust application into an Alpine Linux container. See below for details!
rust-musl-builder uses musl-libc, musl-gcc, and the new rustup target support. It includes static versions of the following libraries:
- The standard
musl-libclibraries. - OpenSSL, which is needed by many Rust applications.
If your application uses OpenSSL, you will also need to take a few extra steps to make sure that it can find OpenSSL's list of trusted certificates, which is stored in different locations on different Linux distributions. You can do this using openssl-probe as follows:
fn main() {
openssl_probe::init_ssl_cert_env_vars();
//... your code
}After modifying the image, run ./test-image to make sure that everything works.
If for some reason this image doesn't meet your needs, there's a variety of other people working on similar projects:
- messense/rust-musl-cross shows how to build binaries for many different architectures.
- japaric/rust-cross has extensive instructions on how to cross-compile Rust applications.
- clux/muslrust also supports libcurl.
- golddranks/rust_musl_docker. Another Docker image.
Either the Apache 2.0 license, or the MIT license.