Build apps for ARM devices from your PC (or old MacBook)

They are everywhere! We are surrounded! ARM processors are ruling the world. Take this escape pod with you!

TL;DR: #podman and #qemu are the best pieces of #FOSS for you.

For many years writing programs for ARM processors was boring! You had to learn assembly dedicated to this architecture and specifications form the vendor. With time devices get a little more powerful and you could hope to run limited versions of Python or nodeJS.

Nowadays ARM processors are as common as Intel/AMD x86. You will find them on small devices like RaspberryPi, on your smartphone or even on new Apple computers.

The question is: How can I build/ship my app on those devices without losing my mind?

Yes you can easily go crazy with building apps on ARM. There are many traps:

  • Die while waiting hours that your build finish and/or fails on the RPi
  • Heart attack when seeing the price of M1 based hardware
  • Insanity while trying to learn Rust and WebAssembly (ok this one is because I have PTSD from C and C++)

Don’t run away! I have a solution for you. And it’s based on lovely containers made with brilliant Free and Open Source Software: podman and qemu

Podman can leverage qemu multi-arch emulator and virtualizer to build and ship your app on any devices. The best of all is that qemu is available on Linux, Windows and MacOS. You can’t get wrong.

For this short demo I’ll use openSUSE Leap 15.3 and an existing app: the famous rancher-demo.

If you don’t have it already install podman.

sudo zypper in podman

Then verify that the binfmt_misc capability from the Linux kernel is activated.

mount | grep binfmt | wc -l
# if the result is 0 then run
sudo mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc

Set up the environment with qemu-user-static

sudo podman run --rm --privileged multiarch/qemu-user-static --reset -p yes

Let’s make a test! I’m on a x86_64 computer. What will happen if I download and run a arm64 OCI image?

uname -m
x86_64

podman run --override-arch arm64 --rm -t  --pull always opensuse/leap uname -m
[...]
aarch64

Magic? Yes! … Well no. Behing the hood it’s qemu who run the binary for us.

Now let’s build our app for ARM!

git clone https://github.com/chrisurwin/rancher-demo
cd rancher-demo
podman build --arch arm64 --override-arch arm64 -t rancher-demo:1 .
podman run --override-arch arm64 --rm -p 8080:8080 rancher-demo:1

Take a look at localhost:8080 with your favorite browser - also named Mozilla Firefox I’m pretty sure.

You are now ready to conquer the world with RaspberryPi with SLE Micro and Containers !

Written on August 13, 2021