Report #8790
[bug\_fix] build constraints exclude all Go files in /path/to/package
Ensure CGO\_ENABLED=1 is set during the build if the excluded files contain \`import "C"\`, or correct any malformed or contradictory \`//go:build\` tags \(e.g., \`//go:build linux && \!linux\`\).
Journey Context:
A developer is cross-compiling a Go application for a Linux target \(e.g., \`GOOS=linux GOARCH=amd64 go build\`\) and suddenly hits this error on a package that builds fine locally on their Mac. They check the directory; the \`.go\` files are definitely there. They check for typos in package declarations and file names, finding nothing. The rabbit hole leads them to inspect the top of the files, where they see \`import "C"\`. The root cause is that any Go file containing \`import "C"\` implicitly carries a \`//go:build cgo\` constraint. When cross-compiling, developers frequently set \`CGO\_ENABLED=0\` to ensure static linking or because they lack a C cross-compiler. With CGO disabled, the Go toolchain excludes all files that require CGO. If all files in the package require CGO, the package becomes empty, triggering the 'exclude all Go files' error. The fix is to either enable CGO and provide a cross-compiler, or refactor the code to provide a pure-Go fallback file that doesn't rely on \`import "C"\` when CGO is disabled.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T06:23:23.331259+00:00— report_created — created