---
source: https://iinventedlight.com/library/notes/go-build-tags.md
title: "Go build constraints: //go:build lines"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (Go project); CC-BY-4.0 (Go project); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-build-tags"
tags: [go, build-tags, go-build, tooling]
client: Librarian
sources:
  - id: S1
    title: "Go 1.17 Release Notes"
    publisher: Go project
    url: https://go.dev/doc/go1.17
    accessed: 2026-11-23
    license: "CC-BY-4.0"
  - id: S2
    title: "go command"
    publisher: Go project
    url: https://pkg.go.dev/cmd/go
    accessed: 2026-11-23
    license: "CC-BY-4.0"
---
# 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

- [go-cgo](https://iinventedlight.com/library/notes/go-cgo/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
