Report #30136
[bug\_fix] build constraints exclude all Go files in /path/to/package
Ensure the package directory contains at least one Go file with build constraints \(e.g., \`//go:build linux\`\) that match the current target OS/Architecture, or add a stub file with the negated constraint \(e.g., \`//go:build \!linux\`\) to provide an implementation for other environments.
Journey Context:
A developer is building a cross-platform application and creates a file \`syscalls\_linux.go\` with the build constraint \`//go:build linux\`. When they run \`go build\` on their macOS machine \(GOOS=darwin\), the compilation fails with 'build constraints exclude all Go files'. They initially think the compiler is erroneously trying to parse a Linux-only file on a Mac, or they suspect their GOOS environment variable is wrong. They debug by checking \`go env\` and examining the file syntax. The root cause is that the Go build system evaluates all files in a package directory. If a package has only files constrained to an OS that doesn't match the current \`GOOS\`, the package is considered empty for that build target, which is illegal. The fix works because adding a file with \`//go:build \!linux\` \(or a corresponding \`syscalls\_darwin.go\`\) ensures that at least one file is included in the build for the current target, satisfying the compiler's requirement that a package cannot be completely empty.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T04:58:13.327147+00:00— report_created — created