The Pinephone’s triple for cross-compiling is
|Please add instructions for other distributions to this section if you know them!
First, you’ll need to install the gcc cross-compilation toolchain.
$ sudo pacman -S aarch64-linux-gnu-gcc
$ sudo apt install gcc-aarch64-linux-gnu
$ sudo xbps-install cross-aarch64-linux-gnu
Note: If you are trying to build an Arch Linux package with
makepkg, also make sure to
For each invocation of
make, be sure to pass the options
ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- like this:
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
If you are using a handwritten Makefile (not autogenerated by a meta-buildsystem such as meson, automake, etc.) then simply override
LD as you need.
$ ./configure --host=aarch64-linux-gnu
In order to cross-compile Rust applications for the Pinephone, you need to have a gcc cross-compiler installed and the Rust dependencies, usually the std crate, cross compiled for the target system. A more extensive explanation can be found on https://github.com/japaric/rust-cross. This instruction is based on it’s description.
The cross-compiler might have a different name depending on the operating system. Further along this instruction the name for the gcc cross-compiler will be used. Replace all occurences of
$gcc_name with the name on your distribution.
For how to install the gcc cross-compilation toolchain on your distribution, please see Cross-compiling
The necessary dependencies can easily be installed with rustup:
$ rustup target add aarch64-unknown-linux-gnu
OR it can be installed with multirust [Is this still accurate???]:
$ multirust add-target nightly aarch64-unknown-linux-gnu
When using rustc just add the two flags --target=aarch64-unknown-linux-gnu and -C linker=$gcc_name. Under Arch, this would look like:
$ rustc --target=aarch64-unknown-linux-gnu -C linker=aarch64-linux-gnu-gcc main.rs
To test it, run the program on your Pinephone
$ scp main user@ipadress:/home/user/Downloads $ ssh user@ipadress /home/user/Downloads/main Hello, world!
To cross-compile a project with cargo, open the folder of the project in a terminal. Then create a new folder and a file for cargo.
$ mkdir .cargo $ cat >.cargo/config <<EOF > [target.aarch64-unknown-linux-gnu] > linker = "$gcc_name" > EOF
Then you can compile it with
$ cargo build --target=aarch64-unknown-linux-gnu
To test it, copy the file on your Pinephone
$ scp target/aarch64-unknown-linux-gnu/debug/main user@ipadress:/home/user/Downloads
Then you can execute it by
$ ssh user@ipadress ./main -h Hello, world!
If you encounter an error saying
Cross compilation detected. Use PKG_CONFIG_ALLOW_CROSS=1 to override
just add that variable in front of your command e.g.
PKG_CONFIG_ALLOW_CROSS=1 cargo build --target=aarch64-unknown-linux-gnu