Based on this post by Andrew Kelley.
wget https://ziglang.org/download/0.9.1/zig-linux-x86_64-0.9.1.tar.xz
tar xf zig-linux-x86_64-0.9.1.tar.xz
Example program:
#include <stdio.h>
int main() {
printf("hello\n");
return 0;
}
Add zig to your PATH
:
export PATH=$PATH:$PWD/zig-linux-x86_64-0.9.1
Now you can start compiling your program for different targets:
x86_64
using musl
(i.e. static binary)zig cc -o example-x86_64 example.c -target x86_64-linux-musl
file example-x86_64
example-x86_64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
aarch64
using musl
(i.e. static binary)zig cc -o example-aarch64 example.c -target aarch64-linux-musl
file example-aarch64
example-aarch64: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, stripped
mips
using musl
(i.e. static binary)zig cc -o example-mips example.c -target mips-linux-musl
file example-mips
example-mips: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), statically linked, stripped
And many more, see zig targets | jq .libc