Compiling emacsql-sqlite on Windows with Zig
I have both Clang and the Microsoft Visual Studio C tools installed on my Windows 10 system, meaning I can compile fairly complicated applications in C, Rust, and so on. I needed to install emacsql-sqlite as a dependency of Magit Forge. However, all I got was an error about a missing stdio.h.
I read a while ago about cross-compiling Rust with Zig and how Zig is a drop-in replacement for GCC/Clang. I installed Zig back then but never tried it. This seemed like a good opportunity to rectify that. I copied the command emacsql-sqlite was running, but replaced clang with zig cc. That produced a working executable with nary a hitch. Colour me impressed!
I wanted to integrate this into emacsql-sqlite itself. Unfortunately, the list of arguments to the
executable isn’t generated in a way that can be extended, so there’s no way to add
cc at the
beginning. I tried implementing it as advice but couldn’t intercept
call-process in the right way,
and it seemed brittle in any case. I ended up editing the library locally for my use case. I might
submit a PR eventually, but I need to think about the best approach for the general case.
It would be easier if I could write a wrapper for zig cc like in Bash, but…