snapcraft icon indicating copy to clipboard operation
snapcraft copied to clipboard

build-on is/isn't mandatory/optional?

Open waveform80 opened this issue 6 months ago • 5 comments

Bug Description

Snapcraft is complaining that the build-on key under platforms must be specified. This is strange as I've successfully built this snap with (presumably) older versions of snapcraft successfully, and the snapcraft documentation still clearly states:

If the platform name is a valid debian architecture, then build-on and build-for can be omitted

I'm guessing either the docs are wrong, or snapcraft's behaviour is ...

To Reproduce

Attempt to run snapcraft pack locally on the rpi-imager snapcraft.yaml

Environment

Snapcraft 8.9.2 running under Ubuntu 24.04.2 on an arm64 system, with LXD

snapcraft.yaml

name: rpi-imager
base: core24
adopt-info: imagewriter
summary: Raspberry Pi Imager
website: https://www.raspberrypi.com/software/
source-code: https://github.com/r41k0u/rpi-imager
issues: https://github.com/waveform80/imager-snap
icon: images/rpi-imager.png
license: Apache-2.0
description: |
  Raspberry Pi Imager is an easy to use application for installing Raspberry Pi
  OS, or other operating systems, to an SD card ready to use with your
  Raspberry Pi.

  Usage is as simple as:

  1. Pick the Raspberry Pi board you want to use.

  2. Pick the operating system you want to write.

  3. Pick the storage you want to write it to (SD card, hard drive, SSD, etc.)

  4. Click "NEXT", confirm you wish to overwrite your storage and wait!

  The application also verifies that the operating system has been written
  correctly after writing has finished. With certain operating system images,
  the imager also supports customizing the first boot configuration (you will
  be prompted for more information after selecting "NEXT" in this case).
compression: lzo
grade: stable
confinement: strict
platforms:
  amd64: {}
  arm64: {}
  armhf: {}
  # This isn't going to work until the gnome content snap supports it
  #riscv64: {}
  # Can't build ppc64el anymore as gnome content snap stopped supporting it
  # in Core 24
  #ppc64el: {}
  # Can't build s390x as upstream is little-endian specific
  #s390x: {}

apps:
  rpi-imager:
    command: usr/local/bin/rpi-imager
    command-chain:
      - bin/desktop-launch
    desktop: usr/local/share/applications/org.raspberrypi.rpi-imager.desktop
    environment:
      DISABLE_WAYLAND: 1
    extensions: [gnome]
    plugs:
      - x11
      - opengl
      - network
      - desktop
      - desktop-legacy
      - home
      - removable-media  # required to re-write first-boot configuration
      - mount-observe    # required to report mounts on target media
      - network-manager  # required to grab image
      - network-control
      - cifs-mount
      - udisks2          # required for writing to sd card
      - hardware-observe # required to find card with lsblk
      - wayland          # required for theming on wayland
      - gsettings        # required for theming on wayland

parts:
  desktop-qt6:
    source: https://github.com/r41k0u/snapcraft-desktop-helpers.git
    source-subdir: qt
    plugin: make
    make-parameters: ["FLAVOR=qt6"]
    build-packages:
      - build-essential
      - qt6-base-dev
      - dpkg-dev
    stage-packages:
      - dmz-cursor-theme
      - light-themes
      - adwaita-icon-theme
      - gnome-themes-extra
      - shared-mime-info
      - libqt6gui6t64
      - libgtk2.0-0t64
      - libgdk-pixbuf2.0-0
      - libqt6svg6 # for loading icon themes which are svg
      - locales-all
      - xdg-user-dirs
      - fcitx-frontend-qt6
  qt6-gtk-platform:
    plugin: nil
    stage-packages:
      - qt6-gtk-platformtheme
    build-packages:
      - libglib2.0-bin
    override-prime: |
      craftctl default
      glib-compile-schemas "$CRAFT_PRIME"/usr/share/glib-2.0/schemas
      if [ "$CRAFT_ARCH_BUILD_FOR" == "amd64" ]; then
        ARCH="x86_64-linux-gnu"
      elif [ "$CRAFT_ARCH_BUILD_FOR" == "armhf" ]; then
        ARCH="arm-linux-gnueabihf"
      elif [ "$CRAFT_ARCH_BUILD_FOR" == "arm64" ]; then
        ARCH="aarch64-linux-gnu"
      #elif [ "$CRAFT_ARCH_BUILD_FOR" == "ppc64el" ]; then
      #  ARCH="powerpc64le-linux-gnu"
      else
        ARCH="${CRAFT_ARCH_BUILD_FOR}-linux-gnu"
      fi
      mv usr/lib/${ARCH}/libproxy/libpxbackend-1.0.so usr/lib/${ARCH}
      rm -r usr/lib/${ARCH}/libproxy
  imagewriter:
    plugin: cmake
    cmake-parameters:
      - -DENABLE_CHECK_VERSION=OFF
      - -DQt6_ROOT=
    source: https://github.com/raspberrypi/rpi-imager.git
    source-subdir: src
    source-type: git
    override-pull: |
      craftctl default
      # Upstream no longer tag releases; manually set version and checkout
      craftctl set version="1.9.3"
      git fetch
      git checkout ebd2a01c66237ce4a8c4ce3a5cdae6dcc307cc0f
      # Strip out the embedded source
      if [ -d "$CRAFT_PART_SRC"/embedded ]; then
        rm -fr "$CRAFT_PART_SRC"/embedded
      fi
      # Patch the required Qt version
      patch -p1 < "$CRAFT_PROJECT_DIR"/qt-6.4.patch
      # Point the icon to the right place
      sed -i -e \
        's|^Icon=rpi-imager|Icon=/usr/local/share/icons/hicolor/128x128/apps/rpi-imager.png|' \
        "$CRAFT_PART_SRC"/src/linux/org.raspberrypi.rpi-imager.desktop
    stage-packages:
      - util-linux
      - qml6-module-qtquick
      - qml6-module-qtquick-controls
      - qml6-module-qtquick-layouts
      - qml6-module-qtquick-templates
      - qml6-module-qtquick-window
      - qml6-module-qtqml-workerscript
      - dosfstools
      - fdisk
      - libqt6widgets6t64
    build-packages:
      - cmake
      - pkg-config
      - devscripts
      - libgnutls28-dev
      - libdrm-dev
      - qt6-base-dev
      - qt6-base-dev-tools
      - qt6-declarative-dev
      - qt6-tools-dev-tools
      - qt6-tools-dev
      - libqt6svg6-dev

Relevant log output

Bad snapcraft.yaml content:
- field 'build-on' required in 'platforms.amd64' configuration
- field 'build-on' required in 'platforms.arm64' configuration
- field 'build-on' required in 'platforms.armhf' configuration

Additional context

No response

waveform80 avatar Jun 04 '25 11:06 waveform80

Hi @waveform80,

The platform needs to be empty, not an empty dictionary.

valid:

platforms:
  amd64:

valid:

platforms:
  amd64: null

invalid:

platforms:
  amd64: {}

You are right that Snapcraft use to support empty dictionaries. Platform parsing has changed quite a bit over the last year. I just tried with a random older version of Snapcraft, 8.2.1 and your example works.

@lengau, would you consider this a regression that we should fix or should we be more clear in the documentation? I'm leaning towards a doc fix.

mr-cal avatar Jun 04 '25 19:06 mr-cal

Thank you for reporting your feedback to us!

The internal ticket has been created: https://warthogs.atlassian.net/browse/SNAPCRAFT-1157.

This message was autogenerated

I'm fairly sure I had those empty dictionaries there because leaving them empty used to fail on something.

Hmm, on a vaguely related subject: could this be the reason I can no longer trigger new builds of this snap on the snapstore? I hit "Trigger new build", it spins for a bit, and then nothing happens (no error, but no new builds starting either). I'm wondering if the store machinery is just rejecting the request out of hand because it can no longer even parse the snapcraft yaml? This is a wild guess ... but in the absence of any error message it's the best I can come up with.

waveform80 avatar Jun 05 '25 11:06 waveform80

Hmm, on a vaguely related subject: could this be the reason I can no longer trigger new builds of this snap on the snapstore? I hit "Trigger new build", it spins for a bit, and then nothing happens (no error, but no new builds starting either). I'm wondering if the store machinery is just rejecting the request out of hand because it can no longer even parse the snapcraft yaml? This is a wild guess ... but in the absence of any error message it's the best I can come up with.

Nope, it's not that

waveform80 avatar Jun 05 '25 11:06 waveform80

@lengau, would you consider this a regression that we should fix or should we be more clear in the documentation? I'm leaning towards a doc fix.

After discussing with @lengau and @cmatsuoka, we're going to leave this behavior as-is and update the documentation.

mr-cal avatar Jun 05 '25 18:06 mr-cal