Bala's Blog

Fat static binaries with Rust

September 15 2018
67 words, ~1 min. read
fat-binary,  rust,  linux 

The following steps were required on a Linux system to build a fat, static binary with Rust.

  1. Add rust toolchain with musl
$ rustup target add x86_64-unknown-linux-musl
  1. Build the application by providing the above musl target
$ cargo build --target=x86_64-unknown-linux-musl
  1. Verify build output
$  file target/x86_64-unknown-linux-musl/debug/<app>
target/x86_64-unknown-linux-musl/debug/<app>: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=071b24021cc31a5f6f136c5148f69c163bbd1733, not stripped
$ ldd target/x86_64-unknown-linux-musl/debug/<app>
        not a dynamic executable