Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

rust

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?

like image 381
Andrei Oprisan Avatar asked May 17 '16 13:05

Andrei Oprisan


1 Answers

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
like image 183
malbarbo Avatar answered Sep 18 '22 12:09

malbarbo