Skip to content

Instantly share code, notes, and snippets.

@radu-matei
Created July 1, 2021 01:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radu-matei/40f049a9f7802b4623b7dcc5f5620a48 to your computer and use it in GitHub Desktop.
Save radu-matei/40f049a9f7802b4623b7dcc5f5620a48 to your computer and use it in GitHub Desktop.

Cross compiling Rust to aarch64

Adding the Rust target and GCC toolchains:

$ sudo apt-get update
$ sudo apt-get install gcc-aarch64-linux-gnu --fix-missing
$ rustup target add aarch64-unknown-linux-gnu

Then, to build a workspace to

$ RUSTFLAGS="-C linker=aarch64-linux-gnu-gcc" cargo build --target aarch64-unknown-linux-gnu
# .cargo/config can be configured with the correct linker and target

Cross compiling OpenSSL

# instructions adapted from https://wiki.macchiatobin.net/tiki-index.php?page=OpenSSL+Installation+Guide
$ git clone https://github.com/openssl/openssl.git
$ export CROSS_COMPILE=aarch64-linux-gnu-
$ export ARCH=arm64
$ git checkout OpenSSL_1_0_2-stable
$ mkdir build
$ ./Configure linux-aarch64 --cross-compile-prefix=${CROSS_COMPILE} --prefix=<path-to-openssl-installation>/build shared
$ make depend
$ make -j5
$ make install

Cross-compiling a project that depends on the openssl-sys crate

$  export PKG_CONFIG_ALLOW_CROSS=1
$ export OPENSSL_STATIC=true
$ export OPENSSL_DIR=<path-to-openssl-installation>/build
$ RUSTFLAGS="-C linker=aarch64-linux-gnu-gcc" cargo build --target aarch64-unknown-linux-gnu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment