-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
Short Summary
Add a CI worker that runs Go's unit tests with CC="zig cc" on linux/amd64.
About zig cc
On Linux, zig cc is a wrapper on top of LLVM and LLD. Main benefits compared to other popular compilers:
- Cross-compilation out of the box via a command-line flag.
- Can dynamically link to a specified glibc version via a command-line flag (i.e. it generates a
libc.so.6on the fly before linking, no need to ship one).
For example:
CC="zig cc -target aarch64-linux-gnu.2.17" go build .
Will (cross-)compile the current package for linux/arm64 and link to glibc 2.17. Read this to learn more about zig cc.
Zig also has it's own Mach-O linker, making it possible to cross-compile to OS X. This is not in scope for this proposal, but may be considered as a next step. cc @kubkon who expressed interest in this.
Logistics
Initial changes:
- Add a
linux/amd64worker that lack any C/C++ compiler (i.e. make sure gcc/ld are not installed). - Install
zig v0.11(to be released in May) to the worker. - Run all Golang's unit tests with
CC="zig cc".
Upkeep:
- The CI worker will have
ReleaseSafe+Debugbuild, so, in case Zig crashes or trips an assertion, there will be decent information about the crash right in the logs. Refs Proposal: change nightlies from ReleaseFast to ReleaseSafe+debug ziglang/zig#15194. - The worker should have Zig upgraded when a new Zig version is released. This can be coordinated by Uber's Go team (cc @linzhp @sywhang) or Zig folks (cc @kubkon @andrewrk).
Why is this important?
As of writing a few companies are known to use zig cc to compile C/C++ (via this toolchain) and bundle it with Go code. My employer Uber uses zig cc to compile+link it's Go Monorepo for linux/amd64 and linux/arm64. During the last 4 months that we have been using zig cc in production (which included an upgrade to Go 1.20) we have encountered some issues in a released Go version that would have been caught in dev versions should zig cc worker be present:
- runtime/pprof: missing profile info for CGo code when compiled with CC="zig cc" #59466
- cmd/link: Incorrect symbol linked in darwin/arm64 #58935 - any Go 1.20-1.20.2 executable on
darwin/arm64would have triggered an assertion during linking with Zig.
Since Go unit tests is a decent "integration" test, we believe it is a worth-while exercise to have this in CI.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status