[HN Gopher] Zig Makes Rust Cross-Compilation Just Work
___________________________________________________________________
Zig Makes Rust Cross-Compilation Just Work
Author : jedisct1
Score : 54 points
Date : 2021-05-22 11:02 UTC (11 hours ago)
(HTM) web link (actually.fyi)
(TXT) w3m dump (actually.fyi)
| simpleguitar wrote:
| Zig is better C. I love zig.
| isaiahg wrote:
| Same here and I've been counting the days until my current
| project is finished so I can start one in zig
| bsaul wrote:
| Tried to understand the reason zig is able to compile a c program
| for a different platform, as opposed to a regular C compiler, but
| i couldn't really understand why (since zig is using libclang
| underneath). Could someone here explain this particular bit ?
| pornel wrote:
| Zig bundles its own private copies of glibc or musl for each
| platofrm, crt.o, system headers, cross-linkers, and clang.
| They've done a lot of work to replicate cross-build toolkits
| for each target:
|
| https://andrewkelley.me/post/zig-cc-powerful-drop-in-replace...
|
| As a Rust user I'm super jealous of that, because Rust's
| "rustup target add" gives a false illusion of being able to
| cross-compile, but it can only build object files/static
| libraries, and if you ask for anything more, Rust just spits a
| big linker error and you're on your own.
| ArthurBrussee wrote:
| Wonder if Rust should pursue this as a feature as well -
| might be hard to promise this as a fully fledged feature when
| Cranelift comes into the picture though. Still it could be
| possible to ship a linker that can handle cross-compiling
| like Zig and compile C code with LLVM irregardless of the
| Rust backend.
|
| Either way, hope Zig and Rust continue to inspire each other
| a bit!
| jorangreef wrote:
| On a related note, if you've mostly spent time with JavaScript,
| and you've always wanted to write a fast native binding for
| Node.js but didn't know any C, or if you ever had issues with the
| node-gyp build system, then you can even use Zig to write and
| compile native bindings for Node.js, without a line of C, and
| without any node-gyp: zig build-lib -dynamic -lc
| -isystem /usr/include/node example.zig -femit-bin=example.node
|
| Here's an example repo with everything you need to give it a
| shot!
|
| https://github.com/ifreund/zig-napi-example
|
| This uses Node's N-API, which is actually a C header, but which
| is consumed perfectly from within Zig. And here are the relevant
| N-API docs: https://nodejs.org/api/n-api.html
| clavigne wrote:
| So I guess LLVM has rather poor fortran support, but zig fortran
| compilation would be really neat for all kind of scientific
| programming purposes.
|
| Being able to call fortran code from zig as easily as one can
| call C libraries would also make it a really nice way to wrap
| fortran libraries into lightweight static programs.
| dsabanin wrote:
| I can't help but think every time it's mentioned: what a poor
| choice of a name for a programming language.
| hiccuphippo wrote:
| I like it. The only problem I've had with it is that searching
| for zig in YouTube gives me mostly children cartoons so I have
| to use ziglang. Not many other languages are much better
| though. Rust, ruby, java, python, they are all existing words
| with prior meaning.
| Alekhine wrote:
| Why is Zig a bad name?
| ford_o wrote:
| I would go with Zag.
___________________________________________________________________
(page generated 2021-05-22 23:01 UTC)