← All notes

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

Sources

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

Permanent ID: iil:note:tgaynpm1

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.},
}

Markdown

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.

All artifact files (JSON index)

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.