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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With