Report #4455
[bug\_fix] build constraints exclude all Go files / file silently compiled on wrong platform
Place '//go:build' on its own line at the very top of the file, immediately followed by a blank line and then the package clause. Keep old '// \+build' lines equivalent to the new directive and run 'go vet ./...' to validate.
Journey Context:
You create db\_windows.go with '//go:build windows' and run CI on Linux expecting it to be skipped, but the build fails because the file is still compiled. After checking the file, you realize there is a blank line and a package comment before the '//go:build' line. The go command only honors build-constraint directives in the leading comment block before the package clause; anything after the first non-comment, non-blank line is ignored. In another case you mix old '// \+build' syntax with new '//go:build' and use different expressions, and Go 1.17\+ rejects the mismatch. You move '//go:build' to line 1, add a blank line, then 'package foo', and keep any legacy '// \+build' line equivalent. 'go vet ./...' now passes and cross-compilation with GOOS=windows behaves as expected.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:31:35.523162+00:00— report_created — created