Build a package for arm64 on amd64

I have a ubuntu 18.04-amd64 and my snapcraft version is 2.43.1+18.4.1. I want to cross-build snap for an arm64. My yaml files is as below:

name: helloworld
version: "1.0.0"
grade: stable
summary: Print 'Hello World' to console output
description: |
  This App is a simple example to show how to make an App.
base: core18
confinement: strict

architectures:
  - build-on: amd64
    run-on:arm64

# define how apps & services are exposed to host system
apps:
  HelloWorld:
    command: HelloWorld
    # interfaces to connect to https://snapcraft.io/docs/supported-interfaces
    plugs: [desktop, unity7, home, opengl, x11, wayland, gsettings]
    

#  describes how to import, and potentially build, each required part of the snap:
parts:
  helloworld:
    plugin: dump
    source: ./generated/build
    after: [libsgl]



  libsgl:
    plugin: nil
    stage-packages:
      # Here for the plugins-- they're not linked in automatically.
      - libx11-xcb1
      - libglu1-mesa
      - libxrender1
      - libxi6
      - libegl1-mesa
      - fontconfig
      - libgl1-mesa-dri
      - libxkbcommon0
      - ttf-ubuntu-font-family
      - dmz-cursor-theme
      - adwaita-icon-theme
      - gnome-themes-standard
      - shared-mime-info
      - libgdk-pixbuf2.0-0
      - libgtk2.0-0
      - xdg-user-dirs
      - libxrandr2
      - libwayland-cursor0
      - libwayland-egl1
      - libpq5

when I run snapcraft it creates an arm snap for me but during building it is downloading amd64 packages which seems it is wrong. would you please explain why does it happen?

while cross building is technically possible, it will require you to hack up your host system a lot to teach it to fully support arm64 packages first ā€¦

then you need to have a cross compiler and need to patch the build systems of all the sources you build to make sure they understand cross compiling if they do not already ā€¦ and indeed all your compiler environment variables need to be adjusted to point to the right places ā€¦

if you can not do your build with https://snapcraft.io/build or use snapcrafts remote-build feature:

iā€™d really recommend getting arm64 hardware to build on ā€¦ cross building anything that has actual library dependencies is extremely painful and fragile ā€¦

2 Likes