Static cross-build for ARM



I’m a total beginner with Rust. I’d like to deploy on an ARM device ( ), but that seems to imply cross-compiling. And it would be much easier if I could build a statically linked binary instead of having to set up a total crossbuild environment.

Is that possible? I think I saw a mention somewhere that cross-compiling for ARM is only possible with dynamic linking.



Is that possible?

Yes. You have to cross compile for the armv7-unknown-linux-musleabihf target.

instead of having to set up a total crossbuild environment.

You still need a cross linker though.

So basically, you’ll have to do something like this. (Assuming an Ubuntu host)

# cross linker
$ sudo apt-get install -qq gcc-arm-linux-gnueabihf

# cross compiled `std` crate
$ rustup target add armv7-unknown-linux-musleabihf

$ cargo new --bin hello && cd $_

# point Cargo to the right linker

# if C dependencies are involved
$ export CC_armv7_unknown_linux_musleabihf=arm-linux-gnueabihf-gcc

$ cargo build --target armv7-unknown-linux-musleabihf

The statically linked binary will be in target/armv7-unknown-linux-musleabihf/debug.


Thank you for the quick reply. I hit a problem with minilzo, I’ll have to poke it a bit more.


Heyho, maintainer of minilzo here. Until now I didn’t even know that minilzo was in use by anyone. If you can give more info regarding the problem I might be able to help out.


I’m getting this:

$ cargo build [--target armv7-unknown-linux-musleabihf]

   Compiling minilzo v0.1.0
   error[E0308]: mismatched types
   --> ~/.cargo/registry/src/
121 |             inlen as u64,
    |             ^^^^^^^^^^^^ expected u32, found u64
   error[E0308]: mismatched types
   --> ~/.cargo/registry/src/
161 |             inlen as u64,
    |             ^^^^^^^^^^^^ expected u32, found u64
   error: aborting due to 2 previous errors


Guess I never testes on non-64-bit machines. The fix should be easy. Once tests are green I’ll merge and release v0.1.1. This should get your build a bit further.


…and published.


Thank you, got it to build