7 ms·
> The author seems to be under the impression that Rust cannot live harmoniously within the C ABI ecosystem, which is false. The author is not under any such i
by kristoff_it 5y ago
> The author seems to be under the impression that Rust cannot live harmoniously within the C ABI ecosystem, which is false.
The author is not under any such impression. The key point is that Zig can cross-compile C/C++ code, while Rust can't. If you have a Rust project that depends on C code, you will have to put in some work if you want to compile it for a different target.
That's a pretty big difference in practice. The point about the Python package example is not to say that Zig can get on platforms where Rust can't, but rather that the C infrastructure that we all use is not that easy to replace and every time you touch something, regardless of how decrepit and broken it might have been, you will irritate and break someone else's use case, which can be a necessary evil sometimes but not always.
This is a point I made in the section of the blog post dedicated to explaining the limits or rewriting code.
> since it does not compile to C.
Give it some time, it will.
- dleslie 5y agoZig itself doesn't cross compile C/C++ code, LLVM does the work for Zig. > If you have a Rust project that depends on C code, you will have to put in some work if you want to compile it for a different target. Rust is built on LLVM, and so its toolchain can also cross-compile C/C++ code. There are crates for that[0], and projects inspired by that idea[1]. > Give it some time, it will. Given enough time mountains become valleys. Zig doesn't compile to C now; and won't be mature and field-tested for a decade or more. 0: https://crates.io/crates/cc https://crates.io/crates/cc 1: https://www.build2.org/ https://www.build2.org/
- steveklabnik 5y agoYou're splitting hairs in a weird way. rustc cannot compile C code. zig can. That they delegate to LLVM is immaterial. "This crate calls out to the most relevant compiler for a platform, for example using cl on MSVC."
- kllrnohj 5y ago> You're splitting hairs in a weird way. rustc cannot compile C code. zig can. But why do I care? I don't use rustc directly, the build system of choice does. And very few of the major build systems have an issue handling multiple languages. Cargo (rust's build system) supports build scripts and the community has already created C/C++ compiler hooks such as https://github.com/alexcrichton/cc-rs https://github.com/alexcrichton/cc-rs rustup and cargo also provide easy cross-compilation support, too.
- steveklabnik 5y agoYou care because you need to have a c compiler installed, as well as the libc stuff… It is a giant pain to do so in some circumstances. One less dependency is a good thing. I quoted from cc’s readme above.
- kllrnohj 5y ago100% of platforms that Zig & Rust run on already have a C compiler installed, though. A c compiler being present is the baseline assumption. If Zig existed in places C doesn't and I wanted to write C for that platform then having Zig CC would be an advantage. But such a situation doesn't currently exist and seems unlikely to ever exist? Especially in the context of a library/module porting to Zig or Rust piecemeal, though, then I already obviously have a working C compiler & build toolchain in place since that's my start point.
- steveklabnik 5y agoyou may have one. Not everyone does, or should. It is a massive pain. See how many folks complain about various native wrapper packages in Python and Ruby for example. Someone even made a Python wheel wrapper for zig to make it easier to compile C extensions.
- ikskuh 5y agoYes, most of my systems have "zig cc" as a C compiler installed nowadays. Why? It's so much easier to install. Especially on systems like windows, and i get other benefits. One example: "I can send you a project, and you can just compile it." Dependencies? "Zig toolchain, any OS" I haven't had this experience with any other language. When a package manager lands, you won't even have to install any SDKs by hand anymore.