Compiling GIMP plugins for Windows has never been so easy with msys2

  • Post category:IT
  • Post comments:0 commentaire
  • Post last modified:12 juin 2021
  • Temps de lecture :7 min de lecture

If you are a GIMP for Windows enthusiastic user, you may know how difficult it can be to get plugins working for the Windows version. There is no more a GIMP registry and whereas building GIMP plugins from source is very easy under Linux with gimptool, it has been for years rather difficult for Windows.

As the author of the Fourier GIMP plugin, I have experiences in 2002 a lot of different compiling techniques and development environments but none of them was either easy or maintained through the years.  And although GIMP API is pretty stable (I have nearly not modified my plugins’ code since the original version in 2002), the binaries are not, and I need to recompile my plugins each 2-3 years. And each time I nearly have to re-learn everything…

A spark of hope is coming from the msys2 environment and the gimp development package available in its package registry. If you don’t know msys2 it is a Software Distribution and Building Platform for Windows, with the aim to work as closely as possible with native Windows, unlike Cygwin. It integrates also nicely mingw-w64 (Minimalist GNU for Windows) compiler for Windows that compiles code to native Windows executables without the need of an additional adaptation layer or DLL. It also comes with a GitHub action that helps to integrate it in a continuous integration pipe.

Use msys2 to compile GIMP plugins

First thing is to install msys2. You may use the installer available on the msys2 website, or use that ships also msys2 ( scoop install msys2 ).

Then you will need a compiler toolchain and the gimp library. There is two different toolchains to build 32bits or 64bits application. The 32bits one is called mingw-w64-i686  and the 64bits one mingw-w64-x86_64 . You will need to prefix all the packages with the one you want to use and to repeat the operations if you want both. msys2 package system use pacman package manager (Arch Linux package manager). Do not forget to also install extra libraries your plugin may need.

In msys2 shell:

Then to build your plugin, there are two little tricks to use gimptool:

  • first, you must start msys2 with the build system you want to use msys2 -mingw32  for 32bits or msys2 -mingw64 for 64bits
  • then, for an unknown reason, gimptool adds surrounding simple quotes to your file name and you will get a file not found error (at least at the time I am writing this article, this may be fixed later) ; to cope with that, we will pile the resulting command to sh that will handle this. We can also adds extra library and compiler options that your plugin may need, for instance for the fourier plugin: echo $(gimptool-2.0 -n --build fourier.c) -lfftw3 -O3 | sh

If you want to integrate in a script, you may call msys2 -c   followed by the command line you want, and add --noconfirm  to pacman to avoid interactive questions.

Result for 32 bits for fourier plugin:

And for 64 bits for fourier plugin:

If you want to compile for a specific GIMP version you can provide the version in the pacman command : pacman -S mingw-w64-x86_64-gimp<strong>=2.10.24</strong>

And if you want to get the version that was used, you can also ask pacman : pacman -Q mingw-w64-i686-gimp | cut -d ' ' -f 2

Many thanks to the msys2 team and the gimp package maintainer (Christoph Reiter) and other upstream packages maintainers for providing a such simple GIMP plugin development environment.

Create a GitHub action to build automatically

Since all this is pretty simple and scriptable, this may be easily integrated into a CI chain. I have tested it with GitHub actions, but it should be easily adapted to any other CI.

GitHub provides a Windows build environment (windows-latest) with quite an interesting list of development tools (including Visual Studio Enterprise compiler). And msys2 provides a GitHub action to improve this environment for msys2 with package caching and many other things I am not using.

Also to build 32bits and 64bits at once, you may use the strategy matrix feature. It should be possible to add multiple GIMP version builds with this feature by adding a gimpversion field to be used in pacman.

Full working example in ; it simply:

  • set-up msys2 environment and need packages (toolchain, gimp development library)
  • build the plugin  (with the | sh trick  explained above)
  • package the resulting plugin and dependencies
  • upload the files in a GitHub artifact with GIMP version in the name  (artifacts are available in the Action workflow; they will be deleted after the retention period, so you will need to download them and create a release)


Laisser un commentaire

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.