Live data from Hacker News

Aro – Zig's new C compiler

github.com

31–40 of 130 posts

Re: Aro – Zig's new C compiler

#31
post #21

Earlier quoted context omitted.

Does Zig already compile without LLVM, even if not by default? Also, do you know when the changes Andrew mentioned in his "Data Oriented Design" are going to be released in the zig compiler? I would expect that when both of the above are done, compiling Zig will be really, really fast compared to anything we currently have.

The Zig compiler has used Data Oriented Design for a long time, so any recent version has that, yes. The most substantial part of running the compiler right now is LLVM, hence the focus to provide an alternative. The other big focus right now is incremental compilation, which will make recompilations very fast.

The talk I am referring to is from 2024 and shows some metrics improving by 30% or more. And Andrew said that's not yet shipped:

https://www.youtube.com/watch?v=IroPQ150F6c

So, are you sure about that??

EDIT: ok, the talk was uploaded just last week, but someone in the comments clarified that:

> The original talk is from 2021.. Thank you for reuploading.

I feel stupid now :/

Re: Aro – Zig's new C compiler

#32

Zig is amazing. What started as a one-man project is becoming a mature software ecosystem capable of standing on its own as a peer with the major languages.

I'm all-in on Zig, I think it's the bee's knees. I needed a regex library for another project, and dashed off an acceptable one in a week flat https://github.com/mnemnion/mvzr The fun part about this is that it can compile, and match , during both comptime and runtime. Will it replace PCRE? No. But nor is it intended to.

Really want to get into it when reading these posts. Feels like rust killed my casual programming taste in last years.

Re: Aro – Zig's new C compiler

#33

Earlier quoted context omitted.

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.

translate-c is not required for compiling pure Zig code. However, the plan is to remove the "@cImport" built in. So if your project is importing a c header, in the future you'll add build step translating it from c to Zig, and then you import it into your Zig code as a module.

what is the reason for this change? zig less than newbie here. I've only just recently started reading the zig overview, although I have been reading hn posts about zig with interest for some time.

Re: Aro – Zig's new C compiler

#34

The 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.

I would 100% be a D user if it had full C++ typesystem fluency.

Re: Aro – Zig's new C compiler

#35
post #30

Earlier quoted context omitted.

The grandparent post refers to the fact that Zig ships with C, C++ library source that it lazily cross-builds (at least for linux, I don't recall how it solves this problem for macOS or windows). And possibly it uses lld too? Since Zig ships with these, it makes the whole cross-build experience much smoother and less dependent on whether your host OS distribution includes packages for your desired target OS/architect…

Exactly. Zig tooling includes a linker, and that's also cross-platform. Zig can generate actual runnable executables that run anywhere from a single machine. As far as I can tell, D's DMD can cross compile but not link. I probably missed that before (actually, I think I was trying with LDC, I found the page where they document the process while searching for it just now: https://wiki.dlang.org/Cross-compiling_with_LD…

> I am sure Walter knows how to compile on one machine, then go to another machine and do the linking or whatever is needed.

Historically, you would or at least could get your compiler and linker from different vendors -- assembler, disassembler and other tools too. So it's normal/common for C compilers like gcc, clang, dmd to not be distributed like Zig is.

But I would dare say that the way Zig is doing it is a great model for others.

> go to another machine and do the linking

BTW - if you use something like debian/ubuntu for development, they have compilers+linkers+binutils for several different architectures available to make cross-building without Zig at least a little bit easier.

Re: Aro – Zig's new C compiler

#36
I don't think it's accurate to call it "Zig's". This is an independent project started by Veikka Tuominen, a Zig core team member, but it's not owned or managed by ZSF in any way. It's Veikka's project. Don't take that away from him!

Re: Aro – Zig's new C compiler

#38

Very nice, honestly the tooling around Zig is even more impressive than the language itself.

The language itself is the reason the tooling exists though, because it attracts a certain kind of developer that probably would not have done the same kind of work for other languages.

what kind of developer is that? interested to know.

I have a lot of prior C usage background, including for nontrivial stuff, including a product, although it has been a while since I used it.

and I am checking out zig as one of my next languages to learn in the C-like / systems programming area.

Re: Aro – Zig's new C compiler

#39

Earlier quoted context omitted.

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.

translate-c is not required for compiling pure Zig code. However, the plan is to remove the "@cImport" built in. So if your project is importing a c header, in the future you'll add build step translating it from c to Zig, and then you import it into your Zig code as a module.

How does this work with things which are expressible only in C? For example, Pascal strings with flexible array members?

I guess since you said header, you keep everything opaque and create a header for that which gets translated to Zig.

Re: Aro – Zig's new C compiler

#40

I don't think it's accurate to call it "Zig's". This is an independent project started by Veikka Tuominen, a Zig core team member, but it's not owned or managed by ZSF in any way. It's Veikka's project. Don't take that away from him!

thanks for clarifying.

I was wondering why it was under a different github site.

Post reply on HN