Skip to content
Latchkey

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.

go build output
package github.com/yourorg/app/internal/platform:
build constraints exclude all Go files in
/home/runner/work/app/internal/platform

Common 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.

Terminal
GOOS=linux GOARCH=amd64 go build ./...
go env GOOS GOARCH   # confirm the target

Enable cgo or pass the required tag

Terminal
CGO_ENABLED=1 go build ./...
# or, for a custom tag:
go build -tags integration ./...

Provide a file for the target platform

  1. Add an implementation file without the excluding constraint (or with a matching one).
  2. Use a _other.go fallback with //go:build !linux for unsupported platforms.
  3. 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 -tags consistently in CI.

Frequently asked questions

What causes ""build constraints exclude all Go files""?
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.
How do I fix "build constraints exclude all Go files"?
Set GOOS/GOARCH to a target the package actually has files for.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card