Docker image for cross compilation?

I came across this as well:

https://ownyourbits.com/2018/06/27/running-and-building-arm-docker-containers-in-x86/

They are newer instructions but the idea is mostly the same. You install/build a static binary of qemu and pass it into the container after which you can do stuff as if you were on arm.

The only problem I can see is to get any decent performance with qemu, kvm access is required which means the container needs to be run --privileged which is dangerous.

As soon as I figure out a good cross compilation workflow that doesn’t require emulator hackery and works consistently, I will containerise it and post it here.

All those links are just further explanation of what’s happening behind the scenes in the emulated “local arm” containers. No need to dive that deep.

The true solution is cross compiling. Emulation has its cost, but for simplicity sometimes it helps to pretend like we’re compiling locally. This way you can install build dependencies just like you’d install on your x86 development workflow.

If your targets are all c++ and you can use bazel https://bazel.build, I’ve created a bazel crosstool for aarch64 (I’ve tested on nano/tx1/tx2) and added it to my repo: https://github.com/curtismuntz/bazel_compilers. I wrote about it here: https://murt.is/articles/2019-05/jetson-bazel-crosstool.html

This solution:

  • doesn't require heavy system installed deps (it will download and compile everything from source)
  • can cross compile even very complex C++ targets very quickly
  • builds everything deterministically and hermetically

I use it to cross compile for example, in one of my projects here: https://github.com/curtismuntz/witness