State of cross-compiling a non-trivial snap amd64 to armhf

I want to speed up builds for my WPE WebKit Mir Kiosk snap. A native build on a RasPi 4 with 4 GB RAM + 4 GB swap takes ~4+ hours (I know, it’s a whole browser). Launchpad remote builds are equally slow, not even accounting for wait time – but hey, free service so no complaints :smile: I have to debug a segmentation fault that only occurs in the armhf version of my snap, so any speedup would be a huge productivity boost.

The WPE WebKit folks advise to cross-build, but only do so with buildroot/yocto setups. I researched the current state of this in snapcraft and would like feedback if I’m missing something, or if I’m going in the completely wrong direction. Also, I can’t seem to have meson pick up the architecture-specific pkg-config, but that’s a different thing.

I gathered from various topics1 that I need to:

  1. specify architectures in snapcraft.yaml:
  - build-on: amd64
    run-on: armhf
  1. Install cross-compiler packages for my C/C++ parts:
      - on amd64 to armhf:
          - "gcc-8-arm-linux-gnueabihf:amd64"
          - "g++-8-arm-linux-gnueabihf:amd64"
 # make sure to quote this:
  1. Specify these compilers in the meson/cmake parts (resp. cross-build definition for meson):
plugin: meson
      - --cross-file=${SNAPCRAFT_PROJECT_DIR}/meson.cross # contains host/target architecture definitions, paths to compilers pkg-config etc. for the cross-building packages.
# […]
plugin: cmake
      - -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc-8
      - -DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++-8
  1. Ensure build/stage packages are pulled from the ARM archives:
stage-packages: # make sure to quote this:
  - "some-package:armhf"
  1. Run snapcraft without --target-arch as that’s unsupported for the meson/cmake plug-ins.

1: Cross compile snap on amd64 to arm - #9 by ijohnson / Stage-Packages with --target-arch - #2 by ijohnson / Specifying architecture on cross-compilations [quite old] / Snapcraft 3.x target-arch not working

Addendum: I managed to tell meson to use the cross-compilers + pkg-config for ARM, but it now fails to link against runtime dependencies because they’re from the host-arch gnome sdk snap:
/snap/gnome-3-34-1804-sdk/current/usr/lib/x86_64-linux-gnu/ file not recognized: File format not recognized

you could try setting UBUNTU_STORE_ARCH to armhf (in a build-environment entry or from an override scriptlet), not sure if snapcraft will respect it (or hand it through to the snap download command it calls) though, that should force it to download the armhf version if it works …

Didn’t know about that, but I added it to build-environment for the first part and it doesn’t seem to work :frowning_face: Though I guess the gnome sdk snap is downloaded before, since the extension is defined in the apps section? Or should I add the gnome-3-34-sdk snap as a build-snap in addition to the extension?

not sure, note that i was only guessing :slight_smile: perhaps you canset the env var outside of snapcraft …

1 Like

We are going to be working on improving the cross compilation story for core20, but do note that extensions are not part of this.

The cross compilation support is going to require a prescribed recipe (on … to …) and most of the work will be adding advanced grammar to keys that don’t have them and to provide consistent behavior with package selection and such.

This does not mean that extensions will never be supported, as having this native syntax will make it doable. If would require the publishers of the snaps use by the extension (in this case the desktop team) to provide a cross compilation SDK. Extensions after all, just extend snapcraft.yaml.

1 Like