Help Needed: Can't build arm64 snap with github actions

I am trying to build snap for yazi, with the following snapcraft.yaml and github wokflow. But I only get amd64 build, not arm64.

After various trials, I only managed to build arm64 on amd64, not arm64 on arm64. Where I have gone wrong?

name: yazi
base: core24
adopt-info: yazi
summary: Blazing fast terminal file manager written in Rust, based on async I/O.
description: |
  Yazi is a terminal file manager written in Rust, based on non-blocking async I/O.
  It aims to provide an efficient, user-friendly, and customizable file management experience.
license: MIT
grade: stable
confinement: classic

platforms:
  amd64:
  arm64:
  
apps:
  yazi:
    command: yazi
    environment:
      PATH: $SNAP/bin:$PATH

parts:
  yazi:
    plugin: rust
    source: https://github.com/sxyazi/yazi.git
    override-build: |
      craftctl default
      craftctl set version=$(git describe --tags --abbrev=0)
      cargo install fd-find --root $CRAFT_PART_INSTALL
      cargo install ripgrep --root $CRAFT_PART_INSTALL
      cargo install zoxide --root $CRAFT_PART_INSTALL
      git clone --depth 1 https://github.com/junegunn/fzf.git fzf
      fzf/install --bin && mv fzf/bin/fzf $CRAFT_PART_INSTALL/bin/
jobs:
  build-snap-package:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        arch: [amd64, arm64]
        
    steps:
      - uses: actions/checkout@v4
      - uses: snapcore/action-build@v1
      - uses: actions/upload-artifact@v4
        with:
          name: snap-${{matrix.arch}}
          # path: ${{ steps.build-snap.outputs.snap }}
          path: yazi*.snap
          retention-days: 2

Hey!

I’d love to see the Yazi snap public! I almost ended up making my own because I couldn’t find it, but just stumbled across this.

What are the issues you’re seeing? Could you post the logs?

EDIT: Okay, I think I can see why this doesn’t work. You must be ending up with files in the arm64 snap that are actually amd64 binaries?

One way around this is to use snapcraft remote-build with a token in your CI, which uses Canonical’s build farm to build the snap on multiple architectures (you can actually build any of the supported snapcraft architectures this way).

Something like this (though I’ve just typed this into Discourse so there may be some small errors):

jobs:
  build-snap-package:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        arch: [amd64, arm64]
        
    steps:
      - uses: actions/checkout@v4

      - name: Setup LXD
        uses: canonical/setup-lxd@0.1.2

      - Setup snapcraft
        run: |
          sudo snap install snapcraft --classic
          
          # Setup launchpad credentials
          mkdir -p ~/.local/share/snapcraft/provider/launchpad ~/.local/share/snapcraft
          echo "${{ secrets.LP_TOKEN }}" > ~/.local/share/snapcraft/launchpad-credentials

          git config --global user.email "some@email.com"
          git config --global user.name "Yazi CI"

      - name: Build snap for arch 
        run: |
          # Modify the `platforms` to use a single arch only, but run this in a matrix so they
          # all get hit
          yq -i '.platforms |= {env(arch): {"build-on": env(arch)}}' snapcraft.yaml
          
          # Now run a remote-build, targeting just the single arch specified
          snapcraft remote-build --launchpad-accept-public-upload
          
          echo "snap=${name}_${version}_${arch}.snap" >> "$GITHUB_OUTPUT"
        env:
          arch: ${{ matrix.arch }}

      - uses: actions/upload-artifact@v4
        with:
          name: snap-${{matrix.arch}}
          path: ${{ steps.build-snap.outputs.snap }}
          retention-days: 2

You can get the LP credentials by running snapcraft remote-build locally, then looking inside ~/.local/share/snapcraft/launchpad-credentials.

There are a couple of small pieces missing (like getting the remote build logs) here, but it’s based on a wider system we built over at snapcrafters: GitHub - snapcrafters/ci: Repository for shared CI tools and actions (specifically ci/release-to-candidate/action.yaml at main · snapcrafters/ci · GitHub)