why unix | RBL service | netrs | please | ripcalc | linescroll
hosted services

hosted services

how to cross compile with rust/cargo

Since x86_64 isn't aarch64 binaries compiled for Intel/AMD will not be compatible with ARM. The Pinebook Pro is aarch64, therefore we need to be able to compile binaries with ease for either.

compilers

First things first, lets ensure rust can handle a target. From the target platform you can get your "triple":

Intel:

$ gcc -v 2>&1 | grep ^Target
Target: x86_64-linux-gnu

Pinebook Pro:

$ gcc -v 2>&1 | grep ^Target    
Target: aarch64-unknown-linux-gnu

Lets install the Pinebook Pro's ... on the build system (using sudo):

$ sudo apt-get install gcc-aarch64-linux-gnu

We need to add the compiler target

$ rustup target add aarch64-unknown-linux-gnu

then add the following to ~/.cargo/config:

rustflags = [
"-C", "link-arg=-lgcc",
"-C", "prefer-dynamic",
]

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"

Now when you build something you do use the following to target aarch64 for the Pinebook Pro:

$ cargo build --target aarch64-unknown-linux-gnu

The same can be done for a Raspberry Pi, but with a different target:

$ gcc -v 2>&1 | grep ^Target
Target: arm-linux-gnueabihf