Report #694
[bug\_fix] go build: build constraints exclude all Go files in /home/user/project/pkg \(or a platform-specific file silently compiles as empty on the wrong OS\)
Put build-tag lines at the very top of the file, before any package comment, and separate the tag line from the package clause by a blank line. Use the new //go:build linux line and, if you still support Go older than 1.17, follow it with the legacy // \+build linux line on the next line. Verify with go vet and by building with GOOS set to the target.
Journey Context:
You add a file named helpers\_linux.go to handle Linux-specific syscalls and it works on your Linux box, but a colleague on macOS gets build constraints exclude all Go files or, worse, a different colleague's IDE helpfully inserts a package comment above your //go:build tag and now the tag is ignored on every platform. Before Go 1.17 build tags used // \+build; Go 1.17 introduced the //go:build format and made it the preferred form, but the old syntax is still accepted for compatibility. The go command only recognizes a build constraint if it is the first non-empty line of the file and is followed by a blank line before the package clause. If a copyright comment, generated-code marker, or misplaced newline sits above it, the file is treated as having no constraint. The fix is to move the tag to line 1 and leave a blank line before package. When cross-compiling, set GOOS=linux go build to confirm the file is included on Linux and excluded elsewhere.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T11:54:37.972954+00:00— report_created — created