"So, a clang wrapper?" is a common thought, so here's how Zig differs from clang out of the box:<p>* Links MachO binaries for Apple Silicon via the custom zld linker it ships. LLVM cannot do this currently.<p>* Provides (deduplicated) libc headers for pretty much every platform, including macOS and glibc/musl. <a href="https://github.com/ziglang/zig/tree/master/lib/libc/include" rel="nofollow">https://github.com/ziglang/zig/tree/master/lib/libc/include</a><p>* Provides a libc implementation (libSystem for macOS, musl and glibc, mingw for Windows, and WASI)<p>* Deals with lots of the deep depths of hell, like enabling you to target any version of glibc out of the box by building symbol mappings: <a href="https://github.com/ziglang/glibc-abi-tool/" rel="nofollow">https://github.com/ziglang/glibc-abi-tool/</a><p>And that doesn't mention the most important part, IMO, which is that it lets you cross compile _out of the box_. No fiddling with sysroots, system packages, etc. to get a cross compiling toolchain working.
TIL about clang's -fsanitize=undefined, and immediately discovered and corrected a handful of subtle bugs lurking in one of my projects. Thanks, Zig, and thanks, Clang.
There's a great article about using Zig as a cross-platform C toolchain for compiling CGo, to bring easy cross-platform compilation to it, which is usually a pain: <a href="https://dev.to/kristoff/zig-makes-go-cross-compilation-just-work-29ho" rel="nofollow">https://dev.to/kristoff/zig-makes-go-cross-compilation-just-...</a>
I recently learned that Clang supports this kind of cross-compiling out of the box. <a href="https://mcilloni.ovh/2021/02/09/cxx-cross-clang/" rel="nofollow">https://mcilloni.ovh/2021/02/09/cxx-cross-clang/</a><p>The main difference is that Clang does not ship with headers/libraries for different platforms, as Zig appears to do. You need to give Clang a "sysroot" -- a path that has the headers/libraries for the platform you want to compile for.<p>If you create a bunch of sysroots for various architectures, you can do some pretty "easy" cross-compiling with just a single compiler binary. Docker can be a nice way of packaging up these sysroots (especially combined with Docker images like manylinux: <a href="https://github.com/pypa/manylinux" rel="nofollow">https://github.com/pypa/manylinux</a>). Gone are the days when you had to build a separate GCC cross-compiler for each platform you want to target.
Zig's cross-compilation tooling and C interop is really impressive. I love to see projects that put so much emphasis on solving real-world practical problems like this and implement it so well.<p>It makes me wonder whether cross-language tooling could be made to work more broadly. It would be awesome if you could have one compiler that would seamlessly compile zig/C/C++/Rust, and perhaps Fortran/ADA too.
"...an absolute joy to work with" I agree. I used zig to make a game in WASM and had a blast. I also had some spare Arduino Nanos laying around and so I build a simple firmware in zig to test it. It worked great, so you can use zig for your embedded projects as well.
I'm almost sold, I checked zig briefly at its home page in the past and never used it. the cross platform build(similar to golang and rust) for c is very interesting.<p>what about the mac-os(or linux,etc) native libraries on windows where you're building the demo code? The 60MB zig compiler and native clang on Windows will not have them, how is that done? Is it totally on clang side?
Zig can also target WebAssembly (standalone and WASI), so you don't need to download and install yet another LLVM toolchain, or fiddle with libclang_rt.builtins-wasm32.a.