Report #7673
[bug\_fix] build constraints exclude all Go files
Enable CGO by setting CGO\_ENABLED=1 and ensuring a C compiler \(like gcc\) is in the PATH, or provide an alternative implementation for non-CGO environments using the \`//go:build \!cgo\` build constraint.
Journey Context:
A developer is building a Go application for a minimal Docker container using \`FROM scratch\` or \`alpine\`. To ensure a statically linked binary, they run \`CGO\_ENABLED=0 go build -o app .\`. The build fails with 'build constraints exclude all Go files'. They initially suspect a corrupted file or missing main function, but the real issue is that a dependency \(like github.com/mattn/go-sqlite3\) relies on CGO and uses \`import "C"\`, which implicitly adds a \`//go:build cgo\` constraint. When CGO is disabled, all files in that package are excluded, leaving an empty package. The fix works because providing a \`\!cgo\` stub or enabling CGO ensures at least one file exists for the package under the current build configuration.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T03:21:59.602527+00:00— report_created — created