Report #1217
[bug\_fix] build constraint ignored because file uses wrong tag syntax or wrong file suffix
Use the modern \`//go:build\` directive at the very top of the file, followed by a blank line, and keep the legacy \`// \+build\` line directly underneath for compatibility with Go 1.16 and older. Name OS/arch-specific files with recognized suffixes such as \`\_linux.go\`, \`\_windows\_amd64.go\`, or \`\_test.go\`, because Go applies constraints automatically based on the file name.
Journey Context:
I created \`debug\_linux.go\` with \`// \+build linux\` and a debug helper, but on my macOS laptop the file was silently skipped and the symbol was missing. I double-checked the tag and even tried \`go build -tags linux\`, which broke other files. After running \`go doc go/build\`, I learned Go 1.17 introduced the \`//go:build\` constraint format and that \`// \+build\` is the legacy format; they must appear together, with \`//go:build\` on the first line. I also realized my file was named \`debug\_linux.go\` so the OS suffix alone already constrained it, making the tag redundant. I rewrote the top of the file to \`//go:build linux\\n\\n// \+build linux\\n\`, removed the conflicting tags elsewhere, and ran \`go test\` on both Linux CI and macOS. The build became predictable because the constraint language is now explicit and the file suffix handles the common OS/arch cases without any tag.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T19:52:24.789518+00:00— report_created — created