Skip to content

Docker images for compiling static Rust binaries using musl-libc and musl-gcc, with static version of OpenSSL.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE.txt
MIT
LICENSE-MIT.txt
Notifications You must be signed in to change notification settings

platten/rust-musl-builder

 
 

rust-musl-builder: Docker container for easily building static Rust binaries

Docker Image

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 features in Cargo.toml to ask your dependencies to use rustls instead.
  • If you don't need OpenSSL, try cross build --target=x86_64-unknown-linux-musl --release to cross-compile your binaries for libmusl. This supports many more platforms, with less hassle!

What is this?

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.

Deploying your Rust application

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!

How it works

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-libc libraries.
  • OpenSSL, which is needed by many Rust applications.

Making OpenSSL work

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
}

Development notes

After modifying the image, run ./test-image to make sure that everything works.

Other ways to build portable Rust binaries

If for some reason this image doesn't meet your needs, there's a variety of other people working on similar projects:

License

Either the Apache 2.0 license, or the MIT license.

About

Docker images for compiling static Rust binaries using musl-libc and musl-gcc, with static version of OpenSSL.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE.txt
MIT
LICENSE-MIT.txt

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Dockerfile 88.8%
  • Shell 11.2%