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:
- Install Zig: download Zig3, unpack it and add
zig
toPATH
- Get a copy of the dwm source code:
git clone https://git.suckless.org/dwm
- In the dwm repo, run
make CC="zig cc"
- That is it! You have compiled dwm with Zig!
If you want to compile dwm with Zig by default:
- In dwm's
config.mk
, replaceCC = cc
withCC = zig cc
- 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
.