* Provides a libc implementation (libSystem for macOS, musl and glibc, mingw for Windows, and WASI)
* 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: https://github.com/ziglang/glibc-abi-tool/
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.
Does it also work with C++? If so, it seems like a very good alternative compared to the MSVC + clang-cl toolchain in Windows (which you need to install gigabytes of libraries before doing any development).
Also, does it also work with build systems like CMake flawlessly? (I know that you can use Zig as a build system, but I would still want to leverage the ecosystem of C++ libraries compatible with CMake.)
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.
Crazy how often this catches undefined behavior. Compiling GLFW with Zig we've found like ~4 separate UB issues, one I described here[0]
Wish it could default to on with clang, but probably it'd break too many things. Really wonder how many severe issues we'd find just from turning this on by default everywhere, though.
GCC supports many of the same sanitizers as well, since they were originally developed for GCC. We use GNU's ubsan and asan in our automated test suite.
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.
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: https://github.com/pypa/manylinux). Gone are the days when you had to build a separate GCC cross-compiler for each platform you want to target.
Yes, for instance for ossia score, the sequencer I'm working on which does some runtime compiling of c++ through clang & llvmjit, I ship a sdk for each platform with all the libc, libc++ headers. What a pain it was !
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.
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.
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?
Apple does not allow to use their SDK on non-Apple hardware. So if you need to use MacOS headers and libraries, the hardware where the compiler runs must be from Apple. Apple has no problem if you run Linux on that and cross-compile from it to Mac.
At work we could not for that reason use the same compilation server setup to cross-compile for Linux, MacOS, Windows and ended up with a separated MacPro box for the compilation farm.
EDIT: cross-compilation from Windows works after one gets Windows SDK and Visual Studio libraries (the later is not free, but free alternatives often are sufficient). The biggest headache is that Windows headers assume a case-insensitive file system and includes, for example, windows.h when the file is Windows.h. One can either use case-insensitive mount option for ext4 or symlink relevant files to the proper case.
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.
Its caching system is also smart enough to handle #include dependencies, so for simple C/C++ projects, it can also function as a make alternative (without having to write a Makefile).
At first glance, yeah probably. But the advantage with zig is that it has c interoperability and the concept around the programmable build system (build.zig)
[+] [-] emidoots|4 years ago|reply
* Links MachO binaries for Apple Silicon via the custom zld linker it ships. LLVM cannot do this currently.
* Provides (deduplicated) libc headers for pretty much every platform, including macOS and glibc/musl. https://github.com/ziglang/zig/tree/master/lib/libc/include
* Provides a libc implementation (libSystem for macOS, musl and glibc, mingw for Windows, and WASI)
* 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: https://github.com/ziglang/glibc-abi-tool/
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.
[+] [-] cyber_kinetist|4 years ago|reply
Also, does it also work with build systems like CMake flawlessly? (I know that you can use Zig as a build system, but I would still want to leverage the ecosystem of C++ libraries compatible with CMake.)
[+] [-] formerly_proven|4 years ago|reply
This would be huge. How can I tell zig cc to use a particular glibc version though?
[+] [-] schemescape|4 years ago|reply
I gave it a try and was very impressed.
[+] [-] smeenai|4 years ago|reply
[+] [-] RodgerTheGreat|4 years ago|reply
[+] [-] slimsag|4 years ago|reply
Wish it could default to on with clang, but probably it'd break too many things. Really wonder how many severe issues we'd find just from turning this on by default everywhere, though.
[0] https://devlog.hexops.com/2021/perfecting-glfw-for-zig-and-f...
[+] [-] brandmeyer|4 years ago|reply
[+] [-] cube2222|4 years ago|reply
[+] [-] shp0ngle|4 years ago|reply
that’s… a great idea.
[+] [-] unknown|4 years ago|reply
[deleted]
[+] [-] haberman|4 years ago|reply
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.
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: https://github.com/pypa/manylinux). Gone are the days when you had to build a separate GCC cross-compiler for each platform you want to target.
[+] [-] jcelerier|4 years ago|reply
My scripts are the create-sdk-... Here if that can be useful to anyone: https://github.com/ossia/score/tree/master/ci and the SDKs are available at https://github.com/ossia/sdk
[+] [-] nicoburns|4 years ago|reply
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.
[+] [-] githubholobeat|4 years ago|reply
[+] [-] synergy20|4 years ago|reply
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?
[+] [-] _0w8t|4 years ago|reply
At work we could not for that reason use the same compilation server setup to cross-compile for Linux, MacOS, Windows and ended up with a separated MacPro box for the compilation farm.
EDIT: cross-compilation from Windows works after one gets Windows SDK and Visual Studio libraries (the later is not free, but free alternatives often are sufficient). The biggest headache is that Windows headers assume a case-insensitive file system and includes, for example, windows.h when the file is Windows.h. One can either use case-insensitive mount option for ext4 or symlink relevant files to the proper case.
[+] [-] faraaz98|4 years ago|reply
[+] [-] jedisct1|4 years ago|reply
[+] [-] extheat|4 years ago|reply
[+] [-] rbehrends|4 years ago|reply
Plus, it makes cross-compilation really easy.
[+] [-] faraaz98|4 years ago|reply
[+] [-] user-the-name|4 years ago|reply
In addition to being its own programming language and build system as well.