Zig Makes Rust Cross-Compilation Just Work
actually.fyi
actually.fyi
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
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.
Either way, hope Zig and Rust continue to inspire each other a bit!
What caused the linker errors for you?
(My issues with a rust lib for a C app were based around how rustc didn't want to include panicking code from core, even with a panic handler defined)
On a "clean" OS, you get:
• Panics from sys crates using the pkg_config crate, because the target sysroot is missing. It can auto-detect available sysroot on some Linux platforms, but on others you need to fiddle with env vars.
• Screen full of linker errors, because the linker for the host OS doesn't know what to do with the target OS's object files. It's less terrible if you enable a semi-secret option for bundled lld, but it's too buggy to use on some platforms.
Cross-compilation from one Linux flavor to another Linux flavor is reasonably easy with some distros. But anything more adventurous like Mac -> Linux just falls apart and you need to spend a whole day copy-pasting configs and installing bitrotting 3rd party Homebrew formulas from random people on the Internet.
Rust's tooling is usually excellent, but cross-compilation feels half-finished. The Rust's own side of it is fine (cross-compiles object files like a champ, has cross-libstd), but anything not written by the Rust project is left as "not our problem".
Check out cosmopolitan at https://justine.lol/cosmopolitan/index.html and background at https://justine.lol/ape.html
Aside: Zig and Zag were humourous puppet characters with attitude for adults in the UK. Always made me smile on the 'big breakfast' show in the 90s.
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.
Wasn't there some big kerfuffle that the owner of wasmtime won't maintain it but won't hand it over?
I heard this word in Eastern Europe countries exclusively referred to as a name for the neo-nazi salute.