Shrinking packaged size of simple C GTK3 app

I’m trying to create a snap out of a small C GTK3 app I’m maintaining. Apart from GTK3, it depends on libao and mpg123.

Here’s the current snapcraft file (in the upstream repo):

Running snapcraft in that repo results in a ~ 33 MiB snap file. Compared to that, I also tried Flatpak, and with the “freedesktop.org” platform (which ships with GTK3 and mpg123) the Flatpak size is ~ 120 KiB, and even the Windows build (where the GTK3 libs + dependencies must be included, although I do trim the icon theme a bit for the Windows build to be smaller) comes in at only 9.33 MiB.

Now, I do see the gnome-3-28-1804 on the snapcraft.io website, and it seems like that should be a thing I can depend on and make the snap smaller in size.

What changes do I need to make to the snapcraft file to make the snap not ship redundant bits that are already in GNOME 3.28?

The current best practice would be to use the gnome-3-28 Snapcraft extension in your project, which is described here:

This will cause the resulting snap to use the libraries found in that gnome-3-28-1804 snap that you discovered, and remove the need for some of the boilerplate you’d need to use it otherwise.

I’m using snapcraft, version 3.8. As you see when clicking on the Github link, I already have this in the snapcraft.yaml:

apps:
    wavbreaker:
        command: usr/bin/wavbreaker
        extensions: [gnome-3-28]

How does build-packages and stage-packages change in this case, do I need to list the GTK3-related packages? I tried adding gnome-3-28-1804 to the build-snaps: list, but that made the snap even bigger (~ 130 MiB or something like that?).

Also, multipass doesn’t work for me at the moment again (me mumbling something about reinventing the wheel), so I can’t really verify it…

(after reboot)

The package is now 27 MiB, I removed libgtk-3-dev and gettext from the build-packages: list, and all libs except libao4 and libmpg123-0 from the stage-packages: list. Snapcraft still complains about these libs (“The ‘wavbreaker’ package is missing libraries that are not included in the snap or base. They can be satisfied by adding the following entries to the existing stage-packages for this part”):

  • libatk-bridge2.0-0
  • libatk1.0-0
  • libatspi2.0-0
  • libcairo-gobject2
  • libcairo2
  • libdatrie1
  • libepoxy0
  • libfontconfig1
  • libfreetype6
  • libgdk-pixbuf2.0-0
  • libgraphite2-3
  • libgtk-3-0
  • libharfbuzz0b
  • libpango-1.0-0
  • libpangocairo-1.0-0
  • libpangoft2-1.0-0
  • libpixman-1-0
  • libpng16-16
  • libthai0
  • libwayland-client0
  • libwayland-cursor0
  • libwayland-egl1
  • libx11-6
  • libxau6
  • libxcb-render0
  • libxcb-shm0
  • libxcb1
  • libxcomposite1
  • libxcursor1
  • libxdamage1
  • libxdmcp6
  • libxext6
  • libxfixes3
  • libxi6
  • libxinerama1
  • libxkbcommon0
  • libxrandr2
  • libxrender1

My application doesn’t link to these libs (apart from GTK, of course) directly, they seem like indirect dependencies via the GTK libs, so why are these not in the gnome-3-28-1804 snap? (they probably are, but snapcraft might fail to recognize this?). It definitely isn’t intended that my snap depends on GTK from the GNOME snap, but ships the dependencies of GTK in its own package(??).

Looking at the snap contents (this is super easy with unsquashfs -l, so kudos for making that part super easy), I see that my snap ships the Humanity, Humanity-Dark and Adwaita icon themes (WHY?), so that’s probably where the size increase comes from.

The “gnome-3-28 extension” documentation you linked also says that it should drag in “gtk-common-themes”, which is cleary not the case, as Humanity and Adwaita still ship stuff in my snap.

Help?

Update: After cleaning the build VM in multipass manually (and without any changes compared to above, just removal of build-packages and stage-packages), the snap is now down to 344 KiB, and the unsquashfs -l output looks reasonable (only my app’s files + the libao + mpg123 dependencies, as expected).

Does that mean that the usage of multipass VM doesn’t really result in a clean build environment? I’m a bit confused…

Apart from that, there’s still the warning about The ‘wavbreaker’ package is missing libraries that are not included in the snap or base. They can be satisfied by adding the following entries to the existing stage-packages for this part", which clearly lists libraries that I expect the GNOME package to ship. Installing the snap and running it (in devmode) seems to work, maybe it’s just unnecessary warnings from snapcraft (can this be fixed?).

The application icon is still missing in gnome shell, is there any docs on how to expose the app icon (.desktop file)?

Snapcraft keeps the VM around and re-uses that VM for subsequent builds of the same snap. This improves build time immensely when you’re iterating on a snap, however it means that stuff from the previous snapcraft build can stick around.

You can get a clean environment by running snapcraft clean.