Report #821
[bug\_fix] package example.com/foo/bar: build constraints exclude all Go files in /path/to/module
Identify which constraint is excluding the files \(commonly \`//go:build cgo\` when \`CGO\_ENABLED=0\`, or \`//go:build linux\` when building on darwin, or a missing custom tag\). Either build with the matching constraint \(e.g. \`CGO\_ENABLED=1\`, \`GOOS=linux\`, or \`go test -tags=integration\`\) or add a fallback implementation file with the complementary \`//go:build \!cgo\` / \`//go:build windows\` / default constraint so the package always has at least one file to compile.
Journey Context:
Our CI build on Alpine Linux started failing with "build constraints exclude all Go files" after we added a small package that wrapped a C library. The package had two files: \`binding.go\` with \`//go:build cgo\` and \`binding\_stub.go\` with \`//go:build \!cgo\`. Locally on macOS it built fine, but the CI image used a static \`golang:alpine\` image that had \`CGO\_ENABLED=0\` by default. With cgo disabled, \`binding.go\` was excluded, and the stub file was supposed to provide a pure-Go fallback. We had accidentally committed the stub with a typo in the build tag \(\`//go:build \!cg\` instead of \`//go:build \!cgo\`\), so the go tool found no eligible files for the package. Fixing the tag restored the fallback implementation and the build succeeded. The lesson is that every package must have at least one file whose constraints are satisfied by the current build tags.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T13:54:40.085917+00:00— report_created — created