TIL: Ninja & MSYS2 Clang


Continuing my quest of compiling SFML with all the flavors of Clang on Windows, I tried out the build system Ninja for the first time. It’s well-known, has its own CMake generator for a very long time and compared to a normal Visual Studio build it’s quite fast.

cmake -GNinja .. -DCMAKE_INSTALL_PREFIX=<your install path>

There honestly isn’t too much to say about it. You can grab the executable from GitHub, put it in your PATH and it’s ready to go.

MSYS2 MinGW-w64 Clang

After trying Clang with MSVC and Clang without MSVC (but Clang-cl), the only remaining combination is Clang without Clang-cl, which I assume means using the GNU Linker ld. For building SFML we need to use the MinGW extlibs and not the UCRT ones.

MSYS2 isn’t really something new, but I haven’t used it much. Some time ago, I used MSYS (without the 2) in order to get GNU Autotools support on Windows, when building a C library for which nobody had written a CMakeLists.txt yet. Similar to Cygwin MSYS2 provides an Unix shell and all sorts of Unix tools, for all those who can’t live without their Linux terminal hackering and from a time where WSL2 wasn’t a thing yet.

Since MSYS2 uses pacman coming from ArchLinux, the whole system is based on rolling releases, which makes it your job to keep it up-to-date as much as possible. Since I hadn’t updated my MSYS2 setup in a while, I couldn’t update pacman itself anymore, due to the introduction of zstd (pretty cool compression algorithms) compressed packages, which the old package manager didn’t support yet. After a complete uninstall and reinstall of MSYS2, things started to work correctly again.

Now in order to create Windows compatible binaries, you can’t just install the normal Clang or CMake, but you need to grab the mingw-w64-x86_64-xyz packages.

pacman -S mingw-w64-x86_64-clang mingw-w64-x86_64-cmake mingw-w64-x86_64-make

After installing the packages, I had to restart my shell and I had to use the mingw64 shell in the msys2 directory, otherwise the mingw-w64-xyz commands weren’t recognized. With that settled, the final step was to tell CMake to use the Clang compiler instead of GCC:

cmake .. -G"MinGW Makefiles" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++

Now I should be able to cover any Clang setup on Windows and maybe I can try and extend SFML’s existing GitHub Action CI to also build Clang on Windows, with and without MSVC.

Leave a Comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.