klingtnet / cross-compile-with-zigcc

A cross compilation example from arm64 macos to amd64 linux using Go and zig cc.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cross compiling with zig cc

Andrew Kelley announced zig cc, a replacement for GCC/clang, with this blog post. In this repository I want to experiment with cross compiling a sample Go project with C dependencies using zig cc.

To list compilation targets use zig targets, e.g. to list all libc targets for amd64 linux:

$ zig targets | jq -r '.libc[] | select(startswith("x86_64-linux"))'
x86_64-linux-gnu
x86_64-linux-gnux32
x86_64-linux-musl

Please note that I developed this example on an M1 🍏 and thus my target system for cross compilation is amd64 linux.

Run

Just do make run and it should print out a bunch of text ending with

1 foo
2 bar
3 baz

About

A cross compilation example from arm64 macos to amd64 linux using Go and zig cc.


Languages

Language:Go 89.4%Language:Makefile 10.6%