this post was submitted on 29 Jul 2023
28 points (88.9% liked)

Programming

17364 readers
194 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS
 

Through witchcraft and dark magic, Zig contains a C standard library and cross compiler for every architecture in 45 megabytes.

top 8 comments
sorted by: hot top controversial new old
[–] SFGrenade@feddit.de 9 points 1 year ago (1 children)

amazingly i read recently that zig wants to cut out llvm in the future, which is the reason it can compile c/c++

[–] etewar@lemmy.blahaj.zone 6 points 1 year ago

I read that as well and Andrew explained that although he wants to do that, it won't happen immediately. There are large projects that rely on this feature and he asked for their input on this topic.

Another thing is that proposed change is to remove clang from the zig distribution. It would still be possible to depend on a zig package that provides an interface to seamlessly compile with system clang.

[–] redcalcium@lemmy.institute 6 points 1 year ago (1 children)

Isn't Zig currently planning to remove the LLVM backend? https://github.com/ziglang/zig/issues/16270

Wouldn't this means zig will lose support for many architectures currently supported via LLVM?

[–] JackbyDev@programming.dev 1 points 1 year ago

No, here

Note that there would still be an LLVM backend for outputting .bc files (#13265), but the Zig compiler would lack the capability to compile .bc files into object files. LLVM or Clang would need to be installed and invoked separately for that use case.

You'd just need LLVM separately but Zig would still be able to make files that LLVM can handle.

[–] prcrst@lemmy.world 5 points 1 year ago

Very interesting. Cross compilation is always daunting.

I'll just throw zig on the ever growing list of 'things to take a look at'

[–] mint_tamas@lemmy.world 3 points 1 year ago (1 children)

“Clang and GCC cannot do this” this is such a dishonest claim. A certain clang distribution he tried “couldn’t do it”, but that does not mean that clang in general can’t cross-compile. In fact, the reason zig can is LLVM itself. You can build a custom distribution with all your favorite targets from clang (just like you can build a whole compiler for a new language).

[–] etewar@lemmy.blahaj.zone 3 points 1 year ago (1 children)

The magical thing here are C header files. While it is certainly possible to crosscompile using traditional tooling, what zig does here is an all-in-one package that lets you cross-compile not only to a different architecture, but a different libc or operating system. Most impressive is it's support for selecting target glibc version.

Actually there was some effort (I think currently on halt) to make those headers usable outside of zig. So yeah, it's not a thing that is (or rather must be) zig specific, but right now zig is the only language that does that AFAIK

[–] mint_tamas@lemmy.world 3 points 1 year ago

Like I said - you can build a distribution of LLVM with your favorite targets, including sysroots and have it cross compile with ease (or you can download toolchains that others built). What zig does is not special and it is highly misleading (and needlessly contrarian) to claim that clang/LLVM is not capable of doing the same when the very thing enabling zig to do this is LLVM.