Skip to content

Commit 8c27615

Browse files
committed
Add tutorial page explaining how to crosscompile on Linux to different arches
1 parent 2b88927 commit 8c27615

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

docs-src/tutorial/cross-linux-arch.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
layout: default
3+
---
4+
5+
# Crosscompiling on Linux
6+
7+
It's a good idea to test your application on arches other than what you have (usually x86_64), e.g. to ensure what your application also works on ARMv7/AArch64, which is used in some portable devices (e.g. the Librem phone).
8+
This guide assumes that you use Debian/Ubuntu for your CI work, as it's somewhat simple to get crosscompiling working on these.
9+
10+
First we have to add the architecture we want to crosscompile to. Refer to [Debian's supported architectures page](https://wiki.debian.org/SupportedArchitectures) to see supported architectures.
11+
12+
~~~bash
13+
> sudo dpkg --add-architecture armhf
14+
~~~
15+
16+
This will install some base packages for `armhf`. Replace `armhf` with whatever arch you want to test (and be mindful to also replace it in the following commands!).
17+
18+
Next we have to install `gcc` for that arch to act as linker for Rust and `libgtk-3-dev` which we need to link our application against. We also need to install pkg-config in order for our build process to be able to discover gtk3.
19+
20+
~~~bash
21+
> sudo apt-get install -y gcc-arm-linux-gnueabihf
22+
> sudo apt-get install -y libgtk-3-dev:armhf
23+
> sudo apt-get install pkg-config
24+
~~~
25+
26+
Next up we have to add support for our target to Rust. Assuming you're using rustup it's as easy as:
27+
28+
~~~bash
29+
> rustup target add armv7-unknown-linux-gnueabihf
30+
~~~
31+
32+
Following that we have to set some environment variables:
33+
34+
~~~bash
35+
> export PKG_CONFIG_ALLOW_CROSS=1 PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig/ CARGO_BUILD_TARGET=armv7-unkown-linux-gnueabihf CARGO_TARGET_ARMV7_UNKOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc
36+
~~~
37+
38+
the first two environment variables set the location of our `pkg-config` binary and allow crosscompiling with it. The third one sets what Rust target we're building for. The triplet has to match the one you've added previously with `rustup target add ...`. Finally, we have to set the linker for our crosstarget. Note that you can also set this in cargo's config file, but at least for CI work it's more convinient to work with environment variables. Refer to [cargo's documentation](https://doc.rust-lang.org/cargo/reference/config.html) for more info on that.
39+
40+
We're now all setup! Now it should be as easy as running `cargo build` to build your application.

docs-src/tutorial/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ In this part we'll go deeper into the mechanisms of the `Gtk-rs` crates. If you'
2020
* [Upcast and downcast](upcast_downcast).
2121
* [Glade](glade).
2222
* [Cross compiling from linux to windows](cross).
23+
* [Cross compiling to different arches on linux](cross-linux-arch).
2324

2425
## Generating GNOME crate Rust API using `gir`
2526

0 commit comments

Comments
 (0)