Last Updated: May 22, 2026
Some code only makes sense on certain operating systems, certain CPU architectures, or under certain feature flags. Build tags (officially called build constraints) let you tell the Go toolchain "compile this file only when these conditions hold". They're how Go ships a single source tree that targets Linux and Windows, with and without cgo, with and without paid features, all from the same go build command.