I'm not all that familiar with the Zig tool chain. Am I understanding correctly that this is a regular C compiler used as a component of the Zig compiler chain allowing compilation of C files alongside Zig? Or does Zig generate C and therefore need a C compiler under the hood? Looking at the documentation suggests it is the former, not the latter.
Aro – Zig's new C compiler
11–20 of 130 posts
Re: Aro – Zig's new C compiler
#12The dlang D compiler includes a full C compiler, so you can mix and match C and D code. You can import C code from D, and D code from C. dmd hello.c ./hello hello world This helps enormously in binding to existing C libraries.
Last I tried, I found some compiler options and commands to do it, but they were badly explained, I tried for hours and it just didn't work at all, so I gave up.
Re: Aro – Zig's new C compiler
#13The dlang D compiler includes a full C compiler, so you can mix and match C and D code. You can import C code from D, and D code from C. dmd hello.c ./hello hello world This helps enormously in binding to existing C libraries.
Is it possible to do what Zig does and cross compile to any OS/arch, from any OS/arch? Last I tried, I found some compiler options and commands to do it, but they were badly explained, I tried for hours and it just didn't work at all, so I gave up.
I am currently adding AArch64 support to DMD's code generator. dmd doesn't run on my Raspberry Pi (yet!), so I use sshfs to access the Pi's filesystem from Ubuntu, compile programs on Ubuntu, transfer the .o file to the Pi, link it on the Pi, and run it on the Pi.
I'm sorry you're having trouble with this, so I recommend posting on the D forums, and people are there to help!
Re: Aro – Zig's new C compiler
#14I'm not all that familiar with the Zig tool chain. Am I understanding correctly that this is a regular C compiler used as a component of the Zig compiler chain allowing compilation of C files alongside Zig? Or does Zig generate C and therefore need a C compiler under the hood? Looking at the documentation suggests it is the former, not the latter.
It says it's a C frontend for `zig translate-c` which translates C code to Zig code. `zig translate-c` is not required for most Zig projects or even for most Zig projects that interop with C.
I also started reading through the Zig overview [1] and near the end of that document it says this: "Not only can Zig compile C code, but there is a very good reason to use Zig as a C compiler: Zig ships with libc."
From the doc, IIUC, compilation of header files and other C code allows Zig to do direct interop with no intermediaries. Seems useful.
Re: Aro – Zig's new C compiler
#15Re: Aro – Zig's new C compiler
#16The dlang D compiler includes a full C compiler, so you can mix and match C and D code. You can import C code from D, and D code from C. dmd hello.c ./hello hello world This helps enormously in binding to existing C libraries.
Re: Aro – Zig's new C compiler
#17I'm not all that familiar with the Zig tool chain. Am I understanding correctly that this is a regular C compiler used as a component of the Zig compiler chain allowing compilation of C files alongside Zig? Or does Zig generate C and therefore need a C compiler under the hood? Looking at the documentation suggests it is the former, not the latter.
It says it's a C frontend for `zig translate-c` which translates C code to Zig code. `zig translate-c` is not required for most Zig projects or even for most Zig projects that interop with C.
Re: Aro – Zig's new C compiler
#18The dlang D compiler includes a full C compiler, so you can mix and match C and D code. You can import C code from D, and D code from C. dmd hello.c ./hello hello world This helps enormously in binding to existing C libraries.
Is it possible to do what Zig does and cross compile to any OS/arch, from any OS/arch? Last I tried, I found some compiler options and commands to do it, but they were badly explained, I tried for hours and it just didn't work at all, so I gave up.
Zig is notable for putting a lot of work into hard-coding basic C libraries, though of course you still need a scattering of other C libraries for most real-world programs.
(for a sufficiently advanced language ecosystem, the language's own libraries should be easy enough)
Re: Aro – Zig's new C compiler
#19Is this part of the long-term plan for zig to get rid of the dependency on clang/llvm? https://github.com/ziglang/zig/issues/16270
Re: Aro – Zig's new C compiler
#20Very nice, honestly the tooling around Zig is even more impressive than the language itself.