fix: build release binaries with CGO_ENABLED=0 - #97
Open
dhryoo wants to merge 1 commit into
Open
Conversation
The published linux binaries are dynamically linked against the release
runner's glibc, so they fail to start on distros with an older one:
$ onecli version
onecli: /lib64/libc.so.6: version `GLIBC_2.34' not found (required by onecli)
onecli: /lib64/libc.so.6: version `GLIBC_2.32' not found (required by onecli)
$ objdump -T onecli | grep -o 'GLIBC_[0-9.]*' | sort -uV | tail -2
GLIBC_2.32
GLIBC_2.34
This affects every still-supported distro on glibc < 2.32 — RHEL/Rocky/
AlmaLinux 8 (2.28), Debian 10 (2.28), Ubuntu 20.04 (2.31).
goreleaser cross-compiles darwin and windows, so those artifacts are
already built without cgo; only the native linux build picks up the
runner's libc. Setting CGO_ENABLED=0 makes that explicit and uniform.
The source imports no cgo — no `import "C"`, no `#cgo` directives, no
cgo build tags — and every dependency is pure Go (kong, x/term, x/sys,
yaml). internal/auth reaches the OS keychain through an interface that
callers may leave nil, not through a cgo binding.
Verified all six release targets build clean with CGO_ENABLED=0
(linux, darwin, windows x amd64, arm64) and that the resulting linux
binary is statically linked and runs on glibc 2.28:
$ file onecli
ELF 64-bit LSB executable, x86-64, statically linked, stripped
$ ./onecli version
{"version": "2.2.5", "server_status": "ok"}
`goreleaser check` passes.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Problem
The published linux binaries are dynamically linked against the release runner's glibc, so they refuse to start on distros with an older one:
This affects every still-supported distro on glibc < 2.32:
There is no fallback — the binary cannot execute at all, so
onecliis simply unusable on these systems. I hit this installing NanoClaw on Rocky Linux 8.10, where its setup step fails atonecli_not_on_path_after_installbecause the freshly-downloaded binary won't run.Cause
.goreleaser.yamldoesn't pinCGO_ENABLED. goreleaser cross-compiles darwin and windows, so those artifacts are already built without cgo — only the native linux build picks up the runner's libc and ends up dynamically linked.Fix
One
enventry on the build. This makes the existing cross-compile behaviour explicit and applies it to linux too.Why this is safe
The source imports no cgo:
import "C", no#cgodirectives, no cgo build tags anywhere in*.gokong,x/term,x/sys,yamlinternal/authreaches the OS keychain through aKeychaininterface thatNewStoreexplicitly accepts as nil, not through a cgo bindingVerification
All six release targets build clean with
CGO_ENABLED=0:The resulting linux binary is static and runs on glibc 2.28:
goreleaser checkpasses.Trade-off worth naming
With cgo off, Go uses its pure-Go resolver and
os/userimplementation instead of the libc ones. For a CLI whose job is HTTPS calls to the OneCLI API this is not a behaviour change in practice, and it's already what the darwin and windows artifacts do today — so this only makes linux consistent with them.🤖 Generated with Claude Code