Packaging a Snap with GNOME46 and Libadwaita 1.5+

Hey all,

We’ve got a Snap package for Graphs, and we recently released version 1.8 on Flathub. Unfortunately, we’ve got some troubles getting the Snap package to work so the latest update is delayed on this platform.

The main issue is simply that we are using the latest GNOME technologies, which includes Libadwaita 1.5 as a hard requirement. This is not available in the regular core22 package with the gnome42 sdk that exists out there. The build gives me this error:

:: ../src/meson.build:13:2: ERROR: Dependency lookup for libadwaita-1 with method 'pkgconfig' failed: Invalid version, need 'libadwaita-1' ['>= 1.5'] found '1.4.0'.

But just updating to core24 doesn’t work, and I haven’t been able to get gnome46-sdk to be included. So I was just wondering if it’s possible yet to use the latest version of GNOME with Snapcraft, and how that works?

Here is the manifest as used in the current stable Snap release, which does not work with GNOME46 (or Libadwaita 1.5 to be specific) clearly.

name: graphs
base: core22
adopt-info: graphs
grade: stable 
confinement: strict
compression: lzo
license: GPL-3.0
architectures:
  - build-on: amd64
  - build-on: arm64


slots:
  graphs:
    interface: dbus
    bus: session
    name: se.sjoerd.Graphs

parts:
  numpy:
    source: https://github.com/numpy/numpy.git
    source-tag: 'v1.25.2'
    plugin: python
    build-environment:
      - PATH: ${CRAFT_PART_INSTALL}/bin:${PATH}
      - PYTHONPATH: ""
    python-packages:
      - scipy==1.11.2
      - python-dateutil==2.8.2
      - pyparsing==3.0.9
      - Pillow==10.0.0
      - packaging==23.1
      - contourpy==1.1.0
      - kiwisolver==1.4.5
      - fonttools==4.41.1
      - cycler==0.11.0
      - matplotlib==3.8.0
      - numexpr==2.8.6
      - mpmath==1.3.0
      - sympy==1.12
    prime:
      - -usr/bin/activate
      - -usr/bin/activate.csh
      - -usr/bin/activate.fish
      - -usr/bin/Activate.ps1
      - -usr/bin/python
      - -usr/bin/python3
      - -usr/bin/python3.10
      - -usr/bin/pip
      - -usr/bin/pip3
      - -usr/bin/pip3.10
      - -pyvenv.cfg
      - -share
      - -include
      - -lib
      - -lib64
      - -usr/lib/python3/dist-packages/pip*
      - -usr/lib/python3/dist-packages/setuptools*
      - -usr/lib/python3/dist-packages/pkg_resources*
    organize: 
      bin: usr/bin
      lib/python3.10/site-packages: usr/lib/python3/dist-packages
      
  graphs:
    after: [ numpy ]
    plugin: meson
    source: .
    meson-parameters:
      - --prefix=/snap/graphs/current/usr
      - --buildtype=release
    build-environment:
      - PYTHONPATH: $CRAFT_STAGE/usr/lib/python3/dist-packages:$PYTHONPATH
      - GI_TYPELIB_PATH: /snap/gnome-42-2204-sdk/current/usr/lib/$CRAFT_ARCH_TRIPLET/girepository-1.0:/snap/gnome-42-2204-sdk/current/usr/lib/girepository-1.0
    build-snaps:
      - blueprint-compiler/latest/stable
    override-build: |
      craftctl default
      sed -e '1c#!/usr/bin/env python3' -i ${CRAFT_PART_INSTALL}/snap/graphs/current/usr/bin/graphs
      mkdir -p $CRAFT_PART_INSTALL/meta/gui
      cp -r $CRAFT_PART_INSTALL/snap/graphs/current/usr/share/icons $CRAFT_PART_INSTALL/meta/gui/
      for i in `find $CRAFT_PART_INSTALL/meta/gui/icons -name "*.svg" -o -name "*.png"`; do
        mv $i "`dirname $i`/snap.$CRAFT_PROJECT_NAME.`basename $i`"
      done
    organize:
      snap/graphs/current/usr: usr
    parse-info: [usr/share/appdata/se.sjoerd.Graphs.appdata.xml]
    
    
apps:
  graphs:
    command: usr/bin/graphs
    desktop: usr/share/applications/se.sjoerd.Graphs.desktop
    common-id: se.sjoerd.Graphs
    environment:
      PYTHONPATH: $SNAP/usr/lib/python3/dist-packages:$PYTHONPATH
      GI_TYPELIB_PATH: $SNAP/usr/lib/$CRAFT_ARCH_TRIPLET/girepository-1.0:$GI_TYPELIB_PATH
    extensions: [gnome]

Is this a thing that’s already possible? I’d like to keep shipping the Snap package as well, as we do have quite some users that we may not release with the official Flatpak. But sustained support for the Snap variant does require Snap to follow the GNOME technologies and have that properly documented.

You can add a libadwaita part to the snap and build the necessary version. If the version of libadwaita you need also needs a newer gtk, you may have to add a gtk part as well. A rough example to get you started, adjust source tag and or commits as needed:

  gtk4:
    source: https://gitlab.gnome.org/GNOME/gtk.git
    source-tag: 4.11.3
    source-depth: 1
    plugin: meson
    meson-parameters:
      - --prefix=/usr
      - -Dbuildtype=release
      - -Doptimization=3
      - -Ddebug=false
      - -Dbroadway-backend=false
      - -Dx11-backend=true
      - -Dwayland-backend=true
      - -Dwin32-backend=false
      - -Dmacos-backend=false
      - -Dintrospection=disabled
      - -Dgtk_doc=false
      - -Ddemos=false
      - -Dbuild-examples=false
      - -Dbuild-tests=false
      - -Dmedia-gstreamer=disabled
      - -Ddemos=false
      - -Dbuild-testsuite=false
      - -Dbuild-examples=false
      - -Dbuild-tests=false
      - -Dprint-cups=enabled
    organize:
      usr/lib/gtk-4.0: usr/lib/$CRAFT_ARCH_TRIPLET/gtk-4.0
    build-packages:
      - libxkbcommon-dev
      - libcups2-dev
      - libcolord-dev
      - libxrandr-dev
      - libxcursor-dev
      - libisocodes-dev
      - libxcomposite-dev
      - libxdamage-dev
      - libxfixes-dev
      - libxi-dev
      - libxkbfile-dev
      - libxml2-utils
      - libstemmer-dev
      - libsystemd-dev
      - libappstream-dev
      - gperf
      - xsltproc
    stage:
      - -usr/bin/wayland-scanner
      - -usr/lib/*/libwayland-client.so.0.20.0
      - -usr/lib/*/libwayland-server.so.0.20.0
  libadwaita:
    after: [ gtk4 ]
    source: https://gitlab.gnome.org/GNOME/libadwaita.git
    source-commit: '5c3245dbb7bb6febfa4656616bd2506041ba7d5f'
    source-depth: 1
    plugin: meson
    meson-parameters:
      - --prefix=/usr
      - -Dbuildtype=release
      - -Doptimization=3
      - -Ddebug=false
      - -Dintrospection=disabled
      - -Dvapi=true
      - -Dtests=false
      - -Dexamples=false
      - -Dgtk_doc=false
    build-environment:
      - PKG_CONFIG_PATH: $CRAFT_STAGE/usr/lib/$CRAFT_ARCH_TRIPLET/pkgconfig:$PKG_CONFIG_PATH
    build-packages:
      - sassc

Apologies for the late reply, but thank you for your response! I hope to have some time free this weekend to give it a look. Now I remember this being a thing as well with an earlier release. Typically we upgrade to the latest versions of GNOME and Libadwaita, roughly around the x.1 release of GNOME. So sometimes we are ahead of Snaps here.

Will get back to this thread if I can’t figure it out, but just wanted to say thanks for the reply this will definitely help.

1 Like