Best (Easiest) Way To Compile For Arm (Raspberry Pi)?

Hey Everyone,

I have a raspberry pi with ubuntu core 18. With --target-arch not working, I have been using to build my snap from my git repo, which I can then install on my RPI via sudo snap install…

This is fine, except it takes approximately 8 minutes for an armhf snap to build. So every time I make a change, I have to wait 8 minutes to be able to install and test it.

The reason I need to be able to test this on a pi and not my local multipass vm is because I’m creating a snap that uses the gpio pins.

Ubuntu Core won’t allow snapcraft to be installed because of confinement, and I’m not interested in hacking the confinement stuff because I want to be able to test the snap as it would be in a production ubuntu core environment.

I have considered building an arm emulating vm on qemu that I could install snapcraft on for compilation, but that is just so much to learn and understand - I don’t want to get into it.

Is there an easy solution to getting an arm vm running on my mac for this compilation purpose?

Should I just buy a whole separate arm machine that I can install Ubuntu Server on, just to compile an arm snap?

My typical workflow for this kind of thing if you only have one ARM machine with Ubuntu Core on it is:

  • install the classic snap
  • enter the classic environment with sudo classic
  • install whatever tools you need to build your snap, i.e. git, gcc, etc.
  • install snapcraft either from the deb (i.e. apt install snapcraft) OR if you need a newer version of snapcraft, install it via the docker unsquashfs trick: - note that you will need to change the code a bit as that Dockerfile only works with amd64, and needs a small patch to work for other architectures. See my dockerfile here: and here for a complete example

Ideally though, the best case scenario would be to have another ARM machine (or even just another SD card since you’ve got a RPi) and install Ubuntu Server on that one and run snapcraft normally there, as this workflow will not work if your snap uses base: core18. If you can get away with base: core then you can still use the above method, just calling snapcraft in the classic environment with --destructive-mode.

Thanks, I ended up getting a second SD card for testing instances on a pure ubuntu core machine. For development, I did manage to install classic on ubuntu core 18 (even though it installs classic for 16, it still works on 18).

I was then able to sudo apt install snapcraft and start compiling and testing my snaps on the RPI (via SSH)

I’m still working from my macos dev machine, but when it comes time to test, I scp copy the snap’s directory over to the ubuntu machine, and then compile and run on the ubuntu machine, via SSH.

This makes testing directly on the ubuntu machine really fast, I only have the extra step of copying the files via SCP which only takes around 10 seconds. On the ubuntu machine I just have to run

sudo snap install --dangerous *.snap

I do have to delete the snap’s directory from the ubuntu machine before each subsequent copy, or I get permissions issues.