4 ms·
Zig 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
by dleslie 5y ago
Zig 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.
- AndyKelley 5y agoYou might not be aware that Zig runs perfectly fine on Microsoft Windows, without MSVC installed. Consider also that installing Zig on Windows is a matter of unpacking a 40 MiB .zip file, whereas installing MSVC on Windows requires downloading something like 8 GiB, being an administrator (!!), and restarting the computer twice.
- deleted 5y ago[deleted]