Cross compile questions in 2020

I searched whole forum and I saw several topics about this question. Some are posted on 2017, I think they are outdated. So I open a new topic about it.

I found several options about cross compile as follows.

  1. remote build.
    This is not what I want because I do not want my code open public to other people.
  2. Set up a buildroot project.
    Everything will be compiled from source. It is not what I want. Source may have a different version compared to ubuntu uses.
  3. build on raspi 3
    This is not possible because not every one has raspi.

I use architectures option, but that no help. It still use host gcc to compile rather than gcc-arm-linux-gnueabi
Here is my yaml:

name: my-snap-name # you probably want to 'snapcraft register <name>'
base: core18 # the base snap is the execution environment for this snap
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: Single-line elevator pitch for your amazing snap # 79 char long summary
description: |
  This is my-snap's description. You have a paragraph or two to tell the
  most important story about your snap. Keep it under 100 words though,
  we live in tweetspace and your description wants to look good in the snap
  store.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots
apps:
  hello-world-cli:
    command: hello

architectures:
  - build-on: amd64
    run-on: armhf
parts:
  cli:
    plugin: cmake
    source: https://github.com/ubuntu-core/snapcraft-examples.git
    source-subdir: 01-hello-world-cli/src

Is there an easy way to do this? Or can anyone tell me how remote-build is implemented?

How about building in a VM? E.g. QEMU

I found snapcraft version 3 will call multipass first. VM is good, but I hope snapcraft do it , not myself.

I don’t think multipass will set up VMs with a foreign architecture for you.

How about Docker + qemu-user-static? I’ve done something similar for a project and it worked well: https://github.com/ppd/solvespace-snapcraft-docker

Thank you very much, I will try it.

Here’s a nice guide: https://ownyourbits.com/2018/06/27/running-and-building-arm-docker-containers-in-x86/

Combine that with https://snapcraft.io/docs/build-on-docker and there you go. Just use your ARM containers you built or had Docker Hub build for you and run them with qemu-user installed on your host.