Compiling dwm with Zig

· jollygood's blog


Inspired by Loris Cro's blog post Maintain it With Zig1, I decided to try compiling dwm2 with Zig.

Why dwm? It is a C project that I use daily and I compile it from source, typically with gcc, when I update or change something. It is a good candidate for experimenting with Zig's C support.

If you are used to building C projects in the Linux terminal, it is very simple to compile dwm with Zig:

  1. Install Zig: download Zig3, unpack it and add zig to PATH
  2. Get a copy of the dwm source code: git clone https://git.suckless.org/dwm
  3. In the dwm repo, run make CC="zig cc"
  4. That is it! You have compiled dwm with Zig!

If you want to compile dwm with Zig by default:

  1. In dwm's config.mk, replace CC = cc with CC = zig cc
  2. Now you can simply run make and it uses the Zig compiler by default.

I was surprised of how simple it was to replace gcc with Zig for dwm. Very nice work by the Zig team!


In this post, I used dwm version 6.4 (commit 50ad171e) and Zig version 0.12.0-dev.903+7aa85691b.