Home

#zig

#zig cc

Why would anyone use Zig over Rust

By Damien Sedgwick, on

The Hype

zig cc is labelled as a 'drop in replacement for CLANG and GCC' which means it it can be used for compiling C/C++ applications and it is particularly useful when needing cross compilation.

But Why

When languages cross compile for different platforms (C / C++ / Go / Rust) they are often bound by the host machines glibc version. This creates problems, what zig cc allows the user to do is cross compilation for any machine / os using whichever version of glibc that is required.

For example, if you compile a program on a newer Linux system and try to run it on an older one, it might fail because it was linked against a newer version of glibc that doesn't exist on the older system.

This is in part, why Uber have adopted to using Zig primarily for their build systems, not because of the language, but because of it's ability to cross compile Go without worrying about CGO / needing to link C libraries dynamically.

It also comes with it's own bundled version of LLVM (which is what it is using under the hood) this means you do not need to install separate cross-compilation toolchains for different targets. I think the whole thing is circa 40mb, which is pretty light in comparison to more traditional ways of compiling these applications (or so I have been reading).

Last Why

I feel like I needed to share what I had been reading as I wasn't aware of how or why Uber were interested in Zig but now I know, so do you and this is probably one of the reasons why Zig is getting so much attention.

Thanks for reading

If you liked this post, subscribe to my newsletter. Don't worry, I probably won't bother you too often.