Report #17482
[bug\_fix] build constraints exclude all Go files in /path/to/package
Ensure the package contains at least one Go file that matches the current build environment. If using CGO, set \`CGO\_ENABLED=1\`. If using custom build tags, verify the tags are correctly passed to \`go build\` via \`-tags\`.
Journey Context:
A developer is building a Go application that uses a package with CGO, such as SQLite \(\`github.com/mattn/go-sqlite3\`\). They build it locally on macOS and it works. They push to a Docker container based on Alpine or Scratch to build a static binary, setting \`CGO\_ENABLED=0\` for a static build. The build fails with 'build constraints exclude all Go files'. They dive into the package's source code and see \`import "C"\`, realizing that \`CGO\_ENABLED=0\` automatically excludes all files containing CGO. The rabbit hole involves trying to install GCC in the container or messing with \`CGO\_LDFLAGS\`. The root cause is that the Go toolchain excludes files containing \`import "C"\` when CGO is disabled, leaving the package with zero valid Go files for the target environment. The fix works because enabling CGO or providing alternative pure-Go files allows the toolchain to find at least one valid file to compile for the package.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:26:38.199592+00:00— report_created — created