Zig Makes Go Cross Compilation Just Work

This is fascinating stuff – Zig is used to cross compile CGO code in Go projects:

In the second post, native SQLite CGO code is cross-compiled using Zig:

I’ve been using the modern-C SQLite port in SIOT, but this may open up the option to use the native port if needed.

Pocketbase does something really neat – if CGO is enabled, native sqlite is used, otherwise the modern-C translation.

Seems there are tradeoffs – the following is from a SQLite discord group:

I think this is a nice use of zig’s capabilities for solving hard problem of cross-compiler toolchain and configuration management. This is on line with what go compiler does.

https://andrewkelley.me/post/zig-cc-powerful-drop-in-replacement-gcc-clang.html

1 Like

I like this comment:

I have carefully designed Zig since the very beginning to treat cross compilation as a first class use case. Now that the zig cc frontend is available, it brings these capabilities to C code.

The only sane way to do cross-compiling is to design it in from the start.