4 ms·
Cargo-zigbuild: Compile Cargo project with Zig as linker
- wyldfire 5y agoI didn't even know zig had a linker, just assumed it used libclang's driver to the system linker. So does it use lld, I suppose? If so, how different is this from using rust-lld?
- dgellow 5y agoThey seem to have their own linker: https://github.com/ziglang/zig/issues/8755 https://github.com/ziglang/zig/issues/8755. > Now that there is significant work put into Mach-O linking thanks to @kubkon, Zig is more than just a linker driver for LLD. It is now a linker that competes in the linker space, and some projects may want to use Zig as a drop-in replacement for other linkers.
- CJefferson 5y agoCan anyone explain why this is a useful thing to do? (The repository doesn't seem to explain why. That's fine if it is a thing only for those who know why of course!)
- 3836293648 5y agoIt's still work in progress as it only supports linux right now, but while Rust's cross compilation story is far better than C, it's still far behind Zig. This calls in Zig as a dependency for building rust code which fixes that and makes Rust's cross compilation just work
- rcxdude 5y agoSpecifically cross compilation works just fine with pure rust code, but rust doesn't include a linker so you need to provide an appropriate one for your host/target combination (which can be a pain). Zig happens to have a linker which supports a large variety of targets, so this project makes it easy to use that during your build.
- vlmutolo 5y agoCross-compilation is when you compile code on one machine meant to run on another machine with a different operating system or CPU architecture. Normally this process is awful because it requires a bunch of very specific files to be present at build time that normally come distributed on the "target" architecture. But you're not building on the target architecture, so you don't have any of these files. Typical solutions are a nightmare and require careful management of environment variables and finding the right versions of all these files and carefully putting them in the right place. Anything that compiles or links against C has to deal with this. Zig makes it far, far easier to cross compile. It ships with all these files by default and will handle everything for you. It's great, and Andy Kelly put in a ton of work to get the details right. It's a simple idea ("ship with the files, of course") but it leads to lots of problems that need solving. Zig solved them, and has the ability to link C code. Rust code often needs to link against C. Some Rust libraries explicitly call C/C++ code. Also the OS interface usually requires linking against C. So Rust programmers still have to touch the nightmare of cross-compilation, and so this benefits them in the same way it benefits C programmers.
- sitkack 5y agoThis is absolutely wonderful! Also using pip to distribute Zig is a nice hack. For reference, https://kristoff.it/blog/maintain-it-with-zig/ https://kristoff.it/blog/maintain-it-with-zig/ Shows how Zig can be a powerful tool for building C and C++ codebases. Now with Cargo integration, it can help achieve clean cross builds in Rust.