I put some effort into the original rustc Debian packaging to make this “just work”. So just to summarise the above thread into one place, here’s an example of cross-compiling for
aarch64-unknown-linux-gnu (using Debian “testing”):
Note the Debian name for this architecture is
arm64. In practice, you would combine the various
apt install invocations for a slight increase in overall speed - I’ve broken them out only for clarity.
dpkg --add-architecture arm64
# Important part here is "libstd-rust-dev:arm64"
apt install cargo rustc libstd-rust-dev:arm64
If you need to install something that uses gcc/g++ from build.rs then you’ll need a C cross-toolchain
apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
cargo to use the right linker when cross compiling. Note this is
~/.cargo/config, not in a specific project, and note cargo/rustc expect to link via
cat <<EOF >>~/.cargo/config
linker = "/usr/bin/aarch64-linux-gnu-gcc"
Note you might need extra native libraries, depending on crates in use. Eg,
apt install libssl-dev:arm64
cargo build --target aarch64-unknown-linux-gnu
target/aarch64-unknown-linux-gnu/debug/mytest: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=831ce6f2b01537416207ed67ed8ef09920144bbe, with debug_info, not stripped