Report #26766
[bug\_fix] build constraints exclude all Go files in /path/to/package
Add a Go file to the package with complementary build constraints \(e.g., //go:build \!linux\) or a file with no build constraints to ensure at least one file is included for the target OS/architecture.
Journey Context:
A developer creates a package that implements a low-level system feature, using //go:build linux on all the .go files in that package. They try to compile or test the project on their macOS development machine, and the compiler throws an error that build constraints exclude all Go files. They dive down a rabbit hole checking their Go installation and GOPATH, thinking the files aren't being found. The root cause is that the Go build system strictly enforces that a package must contain at least one non-excluded .go file for the target OS/architecture; otherwise, it's an error, not just an empty package. The fix works because providing a stub file with //go:build \!linux \(or no constraints at all\) ensures the package compiles on all platforms, satisfying the compiler even if the functionality is a no-op on unsupported platforms.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:19:31.272314+00:00— report_created — created