Using Zig as cross-platform C toolchain
ruoyusun.com
Using Zig as cross-platform C toolchain
1–10 of 42 posts
Re: Using Zig as cross-platform C toolchain
#2what about the mac-os(or linux,etc) native libraries on windows where you're building the demo code? The 60MB zig compiler and native clang on Windows will not have them, how is that done? Is it totally on clang side?
Re: Using Zig as cross-platform C toolchain
#3Re: Using Zig as cross-platform C toolchain
#4Re: Using Zig as cross-platform C toolchain
#5The main difference is that Clang does not ship with headers/libraries for different platforms, as Zig appears to do. You need to give Clang a "sysroot" -- a path that has the headers/libraries for the platform you want to compile for.
If you create a bunch of sysroots for various architectures, you can do some pretty "easy" cross-compiling with just a single compiler binary. Docker can be a nice way of packaging up these sysroots (especially combined with Docker images like manylinux: https://github.com/pypa/manylinux). Gone are the days when you had to build a separate GCC cross-compiler for each platform you want to target.
Re: Using Zig as cross-platform C toolchain
#6Re: Using Zig as cross-platform C toolchain
#7So basically a clang wrapper?
Re: Using Zig as cross-platform C toolchain
#8I'm almost sold, I checked zig briefly at its home page in the past and never used it. the cross platform build(similar to golang and rust) for c is very interesting. what about the mac-os(or linux,etc) native libraries on windows where you're building the demo code? The 60MB zig compiler and native clang on Windows will not have them, how is that done? Is it totally on clang side?
At work we could not for that reason use the same compilation server setup to cross-compile for Linux, MacOS, Windows and ended up with a separated MacPro box for the compilation farm.
EDIT: cross-compilation from Windows works after one gets Windows SDK and Visual Studio libraries (the later is not free, but free alternatives often are sufficient). The biggest headache is that Windows headers assume a case-insensitive file system and includes, for example, windows.h when the file is Windows.h. One can either use case-insensitive mount option for ext4 or symlink relevant files to the proper case.
Re: Using Zig as cross-platform C toolchain
#9* Links MachO binaries for Apple Silicon via the custom zld linker it ships. LLVM cannot do this currently.
* Provides (deduplicated) libc headers for pretty much every platform, including macOS and glibc/musl. https://github.com/ziglang/zig/tree/master/lib/libc/include
* Provides a libc implementation (libSystem for macOS, musl and glibc, mingw for Windows, and WASI)
* Deals with lots of the deep depths of hell, like enabling you to target any version of glibc out of the box by building symbol mappings: https://github.com/ziglang/glibc-abi-tool/
And that doesn't mention the most important part, IMO, which is that it lets you cross compile _out of the box_. No fiddling with sysroots, system packages, etc. to get a cross compiling toolchain working.
Re: Using Zig as cross-platform C toolchain
#10So basically a clang wrapper?
Plus, it makes cross-compilation really easy.