Report #1126
[bug\_fix] build constraint ignored: file with build tags or \`\_GOOS\_GOARCH\` suffix is not compiled when expected
Use the modern \`//go:build\` syntax \(Go 1.17\+\) and keep the legacy \`// \+build\` line directly above it for older toolchains. Place the constraint line at the very top of the file, preceded only by a blank line, and ensure there are no spaces between \`//\` and \`go:build\`. For OS/arch-specific files, use the correct suffix such as \`\_linux.go\` or \`\_amd64.go\`.
Journey Context:
A developer adds a file \`sysctl\_darwin.go\` containing Darwin-specific syscalls and tags it with \`// \+build darwin\`. On a colleague's Mac the file is compiled, but Linux CI fails because the function defined there is missing. They first think the tag is wrong, then notice the file actually starts with a package comment before the build tag. In Go, build constraints must be the first non-blank, non-comment line of the file to be recognized. Additionally, the older \`// \+build\` syntax is still supported but the newer \`//go:build\` line is the canonical form. After moving \`//go:build darwin\` to line 1 directly above \`package platform\`, with the legacy \`// \+build darwin\` line immediately above it, the file is correctly included only on Darwin and excluded on Linux. The fix works because the go command parses build constraints before the rest of the file; anything before the constraint hides it from the build system.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T17:57:12.730693+00:00— report_created — created