Go "build constraints exclude all Go files" - Fix in CI
Go evaluated the build constraints on every file in a package and found none that apply to the current platform. With nothing left to compile, it reports build constraints exclude all Go files.
What this error means
A build fails with build constraints exclude all Go files in <dir>. The directory has .go files, but each one is gated by a //go:build tag or a _GOOS/_GOARCH filename suffix that does not match the target.
package github.com/yourorg/app/internal/platform:
build constraints exclude all Go files in
/home/runner/work/app/internal/platformCommon causes
Building for an unsupported GOOS/GOARCH
Files tagged //go:build linux (or named foo_linux.go) are all skipped when you build for windows or darwin, leaving the package with no compilable files.
CGO required but disabled
Files behind //go:build cgo are excluded when CGO_ENABLED=0, so a package that only has cgo files compiles to nothing.
A custom build tag not passed
Files gated by a custom tag (e.g. //go:build integration) are excluded unless you pass -tags integration.
How to fix it
Build for a platform the files support
Set GOOS/GOARCH to a target the package actually has files for.
GOOS=linux GOARCH=amd64 go build ./...
go env GOOS GOARCH # confirm the targetEnable cgo or pass the required tag
CGO_ENABLED=1 go build ./...
# or, for a custom tag:
go build -tags integration ./...Provide a file for the target platform
- Add an implementation file without the excluding constraint (or with a matching one).
- Use a
_other.gofallback with//go:build !linuxfor unsupported platforms. - Confirm filename suffixes (
_linux.go,_amd64.go) match where you intend to build.
How to prevent it
- Keep build tags and filename suffixes aligned with your target platforms.
- Provide a fallback file so no platform compiles to zero files.
- Pass custom
-tagsconsistently in CI.