Live data from Hacker News

Using Zig as cross-platform C toolchain

ruoyusun.com

41–42 of 42 posts

Re: Using Zig as cross-platform C toolchain

#41

Earlier quoted context omitted.

> Does it also work with C++? It wraps clang, so it supports whatever clang supports, C++ included. > Also, does it also work with build systems like CMake flawlessly? I haven't personally tried it, but I'd expect that if all else fails you could add a step in build.zig to run CMake and then link against whatever library you just built.

Does this include libc++ (compiled shared library of the STL complete with headers and debug symbols?) Although I hate most parts of the STL I still find myself using some parts of it (std::vector, std::string, , , etc.). Maybe I can link libc++ as an external library but then that's too much busywork needed for Zig to be a complete C++ dev environment out-of-the-box.

As an experiment a while back, I had tried in on a small project of mine that uses std::vector, std::string, and (though not a whole lot else). It built, ran, and passed my test suite.

Re: Using Zig as cross-platform C toolchain

#42
post #13

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. [0] https://devlog.hexops.com/2021/perfecting-glfw-for-zig-and-f...

I recently started testing a project with -fsanitize=integer as well. It'll report a few potential issues that -fsanitize=undefined won't, like left shifting a 1-bit off the end.
Post reply on HN