10

Using Creating a basic webservice in Rust and Taking Rust everywhere with rustup as documentation, I have managed to successfully compile a 64 bit static binary with Rust:

rustup target add x86_64-unknown-linux-musl
cargo build --target=x86_64-unknown-linux-musl

But I can't seem to find out how to build a 32bit static binary.

I did find a i686-unknown-linux-musl target when running rustc --print target-list, only to find out it is not available when running rustup target list.

Am I missing something something or it is not possible yet?

kmdreko
  • 42,554
  • 6
  • 57
  • 106
Andrei Oprisan
  • 408
  • 3
  • 10

1 Answers1

10

The std binaries for i686-unknown-linux-musl is only available on Rust 1.10 or newer. You can create a static binary for i686 with the following commands:

$ rustup default stable # stable must at least 1.10
$ rustup target add i686-unknown-linux-musl
$ cargo build --target i686-unknown-linux-musl

The generated binaries can be found on target/i686-unknown-linux-musl/debug/ or target/i686-unknown-linux-musl/release/.

We can check that the generated binary is static linked with ldd:

$ ldd target/i686-unknown-linux-musl/debug/main
not a dynamic executable
malbarbo
  • 10,717
  • 1
  • 42
  • 57