Repository navigation
fix(build): do not force static linking on non-Linux hosts - #655
Merged
Merged
Conversation
`zig build k8e` has never worked on a macOS host. It fails in the external
link step with:
ld: library 'crt0.o' not found
buildVersionFlags emitted one linker flag set for every binary the graph
produces, unconditionally:
-w -s -extldflags '-static -lm -ldl -lz -lpthread'
None of that is satisfiable on macOS. The system has no static libc, and libdl
and libpthread do not exist as separate libraries — both live in libSystem. The
linker therefore goes looking for glibc's static startup object crt0.o, which
macOS does not ship (it has crt1.o), and the build stops.
Nothing in the graph sets GOOS for its Go builds, so k8e, containerd and the
shims all compile for the host. On a Linux host (every CI runner) the flags are
correct, which is why this only ever failed locally.
Pass the host down and select the flag set with it. On Linux the chosen string
is byte-identical to the one this replaces, so release artifacts are unchanged;
elsewhere the binaries keep -w -s and link the system libraries dynamically.
Verified on macOS: `zig build k8e` now links and the resulting binary reports
`k8e version v1.37.0-20261018-rc1 (721c0c5)`; `zig build sandboxd` and the Go
suites still pass. `go build` with the old flags reproduces the crt0.o failure
exactly, and with `-w -s` succeeds, which pins the diagnosis.
build.zig is left as zig fmt --check already reports it on main: reformatting it
would bury this change in alignment noise.
|
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



这个 PR 修的是什么
zig build k8e在 macOS 上从来没能成功过,一直卡在链接阶段:根因
buildVersionFlags()对图里每一个 Go 二进制都无条件输出同一套链接参数:这套在 macOS 上一条都不成立:
-static无法满足libdl和libpthread在 macOS 上都不是独立库(都在libSystem里)crt0.o,而 macOS 只有crt1.o而
build.zig里没有任何 Go 构建设置GOOS—— k8e、containerd、各 shim 全部按 host 编译。所以 Linux 主机(CI 全是)上这组参数是对的,只有 macOS 本地会失败。这就是为什么 CI 一直是绿的。改法
把 host 系统传进去,按它选择链接参数:
调用处:
buildVersionFlags(b.allocator, vi, builtin.os.tag == .linux)。Linux 上选中的字符串与改动前逐字节一致,发布产物不变;其他平台保留
-w -s,动态链接系统库。验证
macOS 实测:
go build -ldflags "-w -s -extldflags '-static -lm -ldl -lz -lpthread'"ld: library 'crt0.o' not foundgo build -ldflags "-w -s"修复后:
zig build k8e✅ 链接成功,bin/k8e182 MB,./bin/k8e --version→k8e version v1.37.0-20261018-rc1 (721c0c58)zig build sandboxd✅ 三架构通过go build ./pkg/...、go vet✅一个有意为之的取舍
没有顺手跑
zig fmt build.zig。因为build.zig在main上本身就不符合zig fmt(我用 stash 对比确认过:改动前后zig fmt --check都会报它)。全量格式化会带来几十行对齐噪音,把这两行核心改动埋掉。如果你希望单独提一个 formatting chore PR,我可以另开。Done By AI