Re:Zig Build System
by ptato on Friday April 14, 2023 @06:30AM
(#35567786)
Zig embeds clang to compile C code. This doesn't add a new dependency since Zig already depends on LLVM. If there is a future where the self-hosted Zig backend is good enough to not depend on LLVM anymore, there might be a reason to use a C compiler written in Zig (possibly https://github.com/Vexu/arocc)
[ Parent
| on HN ]
Re:Zig Build System
by richardwhiuk on Friday April 14, 2023 @06:46AM
(#35567898)
It adds a new dependency - the c language frontend - aka clang - surely the zig compiler emits LLVM IR, not C code?
Re:Zig Build System
by daurnimator on Friday April 14, 2023 @07:15AM
(#35568128)
zig supports importing C headers via the special built-in `@cImport`. That feature requires a C language front end to operate.
https://ziglang.org/documentation/0.10.1/#Import-from-C-Head...
Re:Zig Build System
by tristan957 on Friday April 14, 2023 @12:17PM
(#35571235)
Zig has a C backend that supports something like 99% of all Zig if I'm remembering the number correctly.
Zig has almost completely solved the bootstrap problem.
Re:Zig Build System
by trashburger on Friday April 14, 2023 @01:26PM
(#35572140)
This isn't quite correct. Yes, it can output C code; however the result is not very readable at all, and fails the DFSG on generated code. It _is_ useful for compiling Zig code to targets which aren't supported by LLVM, however.
Do you have a reference for this? Does it use a C backend that is part of LLVM, or is it something Zig-specific? What are its limitations? Can it compile libraries to C, or only entire applications?
I have wanted Rust and Zig to support compile-to-C for a while, so this is exciting news for me.
One thing that would particularly interest me is if functions intended to be inlined could be emitted into .h files.
Also worth noting that Zig embeds C stdlib source code (musl if I'm not mistaken). That means it is easier to cross compile C projects using zig since you don't need to install a cross toolchain. This is why some golang/rust projects use Zig when they need to cross compile.