Extend a C/C++ Project with Zig (2021)
zig.news
zig.news
Tbh I doubt that this situation will improve now that they bit off even more from the compiler cake after having more than they can chew already.
Isn't the idea that bootstrapping the compiler let's people who only know zig contribute to the compiler? Might it be too premature to declare failure?
rm -rf src
Extremely fast and arguably safer than a broken compiler.The new compiler is a much better codebase and compiler bugs get fixed much more quickly and effectively.
https://github.com/ziglang/zig/issues/14172
I believe a 3rd party TLS package is available, but something to think about.
As I understand it, C/C++ interop and support in the build system is not going away; instead it might be accomplished via a separately maintained clang package. (Aside: for an example of this kind of thing can work, see ffmpeg[2] converted to use the Zig build system which pulls in nasm[3] as a Zig package; presumably the clang solution would be a bit more integrated than that, but it serves to show that it can be done).
Zig will still support compilation using LLVM, but instead of directly linking to LLVM and using LLVM's IRBuilder API, it will directly output LLVM bitcode instead[4]. The build system will then handle linking this into an executable, possibly by calling out to the LLVM linker.
The idea seems to be to reduce dependencies of the main executable, while keeping the build system flexible enough that it does not impact existing use cases.
I'm not affiliated with the Zig project in any way, so my understanding of this may be off. I'd recommend reading the GH issues and comments I've linked below to get a better idea of it.
[1]: https://github.com/ziglang/zig/issues/16270#issuecomment-161...
[2]: https://github.com/andrewrk/ffmpeg
- the Zig compiler will get a new integrated C frontend written in Zig
- ...and a new backend which can emit LLVM bitcode (so it's still possible to integrate with an external LLVM toolchain)
- C++ and ObjC compilation (or Clang's specific flavour of C) will be delegated to a package dependency which includes a clang toolchain, accessible through the build system
...so things will be shuffled around, but no functionality will be lost.
This talk on YouTube seems to suggest that not everything is all hunky dory with Zig as a C/C++ compiler (with reference to libc) but I cannot remember any details since it has been almost a year since the talk was published.
I wonder if things have changed? Does anyone know?
Zig can link against libcs without major issues.
If you use Meson/Ninja then I apologize in advance.