Why is zig often mentionned in that context ? it seems that cross-compilation and C can be achieved using llvm/clang without a lot of problem ? What is zig accomplishing in that matter that makes it so special ?
Why is zig often mentionned in that context ? it seems that cross-compilation and C can be achieved using llvm/clang without a lot of problem ? What is zig accomplishing in that matter that makes it so special ?
With Zig, that all goes away. It’s as simple as saying `zig build -Dtarget=aarch64-linux-gnu` or `zig build -Dtarget=riscv32-freestanding-none` and it just works. It’s pretty incredible.
Zig has set the bar for how cross compilation should be done and all other languages should be measured against it. Rust is close but is still a headache. The only other language that compares at the moment (IMO) is Go.
What about Zig would you say makes it better? Rust has `cargo build --target <triple>`
I certainly agree that Rust is much better than C/C++, but it’s not quite at Zig level, at least in my (limited) experience.
[1] https://ziglang.org/learn/overview/#zig-is-also-a-c-compiler
---
I will resist making the obvious reference despite having said both "launch" and "zig" in the same sentence.
#include <stdio.h>
#include <sys/random.h>
int main(void) {
unsigned char buf[10];
ssize_t ret;
ret = getrandom(buf, sizeof(buf), 0);
if (ret != sizeof(buf))
fprintf(stderr, "getrandom() failed\n");
else
fprintf(stderr, "getrandom() success\n");
return ret != sizeof(buf);
}
You have an x86_64 Linux machine running glibc 2.17. Your task is to compile the above program into a dynamically linked executable targeting glibc 2.28 on x86_64 Linux.With Zig, it looks like this:
1) Download zig
2) `zig cc -target x86_64-linux-gnu.2.28 random.c`
What would those steps look like using llvm/clang?
Next, try doing it from Windows 8
clang random.c
glibc 2.28 will work with binaries compiled against 2.17.zig cc uses clang under the hood, and Zig the language is also mostly based on LLVM, but zig cc ships a lot of versions of libc to ensure that it can properly compile to all platforms without weird linker errors.
Openssl is typically one you want to be kept up to date with OS updates.
Like libc, it can be a pain.