Need help with rust-musl-cross?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

messense
136 Stars 24 Forks Other 76 Commits 6 Opened issues

Description

Docker images for compiling static Rust binaries using musl-cross

Services available

!
?

Need anything else?

Contributors list

# 8,754
Rust
weixin-...
wechat
wechat-...
53 commits
# 25,454
sentry
gatsbyj...
pcre
Perl
2 commits
# 11,748
Rust
sentry
error-m...
crash-r...
2 commits
# 34,272
Django
Qt
schemat...
cpp17
1 commit
# 109,019
Rust
C
Shell
Amazon ...
1 commit

rust-musl-cross

Docker images for compiling static Rust binaries using musl-cross-make, inspired by rust-musl-builder

Docker Image Build

Prebuilt images

Currently we have the following prebuilt Docker images on Docker Hub.

| Rust toolchain | Cross Compile Target | Docker Image Tag | |----------------|-------------------------------------|---------------------| | stable | aarch64-unknown-linux-musl | aarch64-musl | | stable | arm-unknown-linux-musleabi | arm-musleabi | | stable | arm-unknown-linux-musleabihf | arm-musleabihf | | stable | armv5te-unknown-linux-musleabi | armv5te-musleabi | | stable | armv7-unknown-linux-musleabi | armv7-musleabi | | stable | armv7-unknown-linux-musleabihf | armv7-musleabihf | | stable | i586-unknown-linux-musl | i586-musl | | stable | i686-unknown-linux-musl | i686-musl | | stable | mips-unknown-linux-musl | mips-musl | | stable | mipsel-unknown-linux-musl | mipsel-musl | | stable | x86_64-unknown-linux-musl | x86_64-musl |

To use

armv7-unknown-linux-musleabihf
target for example, first pull the image:
docker pull messense/rust-musl-cross:armv7-musleabihf

Then you can do:

alias rust-musl-builder='docker run --rm -it -v "$(pwd)":/home/rust/src messense/rust-musl-cross:armv7-musleabihf'
rust-musl-builder cargo build --release

This command assumes that

$(pwd)
is readable and writable. It will output binaries in
armv7-unknown-linux-musleabihf
. At the moment, it doesn't attempt to cache libraries between builds, so this is best reserved for making final release builds.

How it works

rust-musl-cross
uses musl-libc, musl-gcc with the help of musl-cross-make to make it easy to compile, and the new rustup
target
support. It includes static versions of several 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:

extern crate openssl_probe;

fn main() { openssl_probe::init_ssl_cert_env_vars(); //... your code }

Use beta/nightly Rust

Currently we install stable Rust by default, if you want to switch to beta/nightly Rust, you can do it by extending from our Docker image, for example to use beta Rust for target

x86_64-unknown-linux-musl
:
FROM messense/rust-musl-cross:x86_64-musl
RUN rustup update beta && \
    rustup target add --toolchain beta x86_64-unknown-linux-musl

Strip binaries

You can use the

musl-strip
command inside the image to strip binaries, for example:
docker run --rm -it -v "$(pwd)":/home/rust/src messense/rust-musl-cross:armv7-musleabihf musl-strip /home/rust/src/target/release/example

License

Licensed under The MIT License

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.