Go build constraints: //go:build lines
Answer: A Go build constraint is a line comment that begins //go:build. The go command prefers //go:build lines over // +build lines.
The Go 1.17 syntax
Release notes for 1.17 say the go command understands //go:build lines.
It prefers that form, rather than the older // +build lines.
The new syntax uses boolean expressions, just like Go.
gofmt now synchronizes //go:build lines with // +build lines.
Where a constraint may appear
The go command docs say a build constraint is given by a line comment that begins //go:build.
Those comments may appear in any kind of source file, Go or not, near the top of the file.
For a Go file, place the constraint before the package clause.
The comment is an expression of build tags joined by ||, &&, and !.
See also
Claims
- id: C1 claim: The go command prefers //go:build lines over // +build lines. source: S1 evidence: "prefers them over // +build lines"
- id: C2 claim: The new syntax uses boolean expressions, just like Go. source: S1 evidence: "uses boolean expressions, just like Go"
- id: C3 claim: A build constraint is a line comment that begins //go:build. source: S2 evidence: "line comment that begins //go:build"
- id: C4 claim: In Go files the constraint must appear before the package clause. source: S2 evidence: "must appear before the package clause"
Sources
- [S1] Go 1.17 Release Notes. Go project. https://go.dev/doc/go1.17 . License: CC-BY-4.0. Accessed 2026-11-23.
- [S2] go command. Go project. https://pkg.go.dev/cmd/go . License: CC-BY-4.0. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go project, Go 1.17 Release Notes; Go project, go command. CC-BY-4.0 (https://go.dev/copyright). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go project, Go 1.17 Release Notes; Go project, go command. CC-BY-4.0 (https://go.dev/copyright). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go build constraints: //go:build lines." iinventedlight Library, iil:note:tgaynpm1, version of 2026-11-23. https://iinventedlight.com/library/notes/go-build-tags/. License: CC-BY-4.0.
@misc{iil_note_tgaynpm1,
author = {{iinventedlight}},
title = {{Go build constraints: //go:build lines}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/go-build-tags/},
note = {Permanent ID iil:note:tgaynpm1. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-build-tags.schema.json (schema; CC-BY-4.0)
- go-build-tags.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-build-tags.md.