How to build a 32-bit static binary with Rust and rustup?

Using Creating a basic web service in Rust and Taking Rust everywhere with rustup as documentation, I was able to successfully compile 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 not figure out how to build a 32-bit static binary.

I found the target i686-unknown-linux-musl when starting rustc --print target-list , only to find out that it is not available when starting rustup target list .

Am I missing something or haven’t succeeded yet?

+6
source share
1 answer

The std i686-unknown-linux-musl for i686-unknown-linux-musl are only available on Rust 1.10 or later. You can create static binary code 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 at target/i686-unknown-linux-musl/debug/ or target/i686-unknown-linux-musl/release/ .

We can verify that the generated binary is statically linked to ldd :

 $ ldd target/i686-unknown-linux-musl/debug/main not a dynamic executable 
+5
source

All Articles