Updated at: 2023-11-03
C language, as a minimalist language, aligns with my philosophy. However, cross-platform compilation is inconvenient, such as compiling Linux binaries on macOS.
I've read the news that Uber has already used the Zig compiler in production, even though Zig hasn't reached version 1.0 yet. I tried compiling joker these past few days and it's truly impressive.
nami install zig
There are several ways to use zig cc:
This method has the least intrusion, for example, directly specify the CC variable in the make command.
make CC="zig cc -target x86_64-linux-gnu"
This method is suitable for situations with a small number of files.
zig cc -o joker -target x86_64-macos-none main.c run.c
This subcommand is an encapsulation of zig cc.
zig build-exe -lc --name joker -target aarch64-macos-none -O ReleaseSafe main.c run.c
zig cc also supports specifying the C standard (-std=c11). It also supports linking with the musl library, which is great. Although musl library's performance is not as good as glibc, its code implementation is clean and clear (KISS). The next version of joker will statically link with musl. For more parameters, you can check zig cc --help.