Static cross-build for ARM


#1

Hi!

I’m a total beginner with Rust. I’d like to deploy https://crates.io/crates/btrfs-dedupe on an ARM device ( https://omnia.turris.cz/en/ ), 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.

Cheers,
Paul


#2

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
$ export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER=arm-linux-gnueabihf-gcc

# 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.


#3

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


#4

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.


#5

I’m getting this:

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

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

#6

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.


#7

…and published.


#8

Thank you, got it to build