Report #14423
[bug\_fix] build constraints exclude all Go files in /path/to/package
Enable CGO by setting \`CGO\_ENABLED=1\` and ensure a C compiler \(like \`gcc\` or \`clang\`\) is installed and available in the PATH.
Journey Context:
A developer's application builds perfectly on their local macOS or Windows machine. They push it to a CI pipeline that uses a minimal Docker image \(like \`alpine\`\) to build a Linux binary. The CI build abruptly fails with 'build constraints exclude all Go files'. The developer is confused—they haven't used any \`//go:build\` tags in their own code. They dig into the failing dependency and discover it uses \`import "C"\`, meaning it relies on CGO. They then realize that their CI script sets \`CGO\_ENABLED=0\` to create a static binary, or the Alpine image simply lacks a C compiler. When CGO is disabled, the Go compiler automatically excludes any files that import "C", effectively making the package empty and triggering the constraint error. Installing a C compiler in the build environment \(e.g., \`apk add build-base\` for Alpine\) and setting \`CGO\_ENABLED=1\` allows the Go toolchain to include and compile the CGO files.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:26:50.248723+00:00— report_created — created