Report #63032
[bug\_fix] build constraints exclude all Go files in /path/to/package
Set CGO\_ENABLED=1 in the build environment and ensure a C compiler \(like gcc or musl-gcc\) is installed.
Journey Context:
A developer builds their application locally on macOS and it compiles perfectly. They push it to a CI pipeline that uses an Alpine Linux Docker container with CGO\_ENABLED=0 to create a statically linked binary. The CI build fails with 'build constraints exclude all Go files'. They inspect the failing package and see files ending in \_linux.go, so they are confused as to why Linux files are excluded on a Linux builder. They check the Go version, file permissions, and GOOS settings. The rabbit hole involves adding //go:build linux tags explicitly, which doesn't help. The root cause is that the package uses CGO \(e.g., it imports C or relies on a C library\), and Go files that use CGO have an implicit build constraint requiring CGO\_ENABLED=1. Since the CI environment disabled CGO, the toolchain excluded all CGO-dependent files. Because there were no pure-Go fallback files, the package was empty. Enabling CGO and installing a C compiler fixes the build.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T12:16:45.263805+00:00— report_created — created