Skip to content

Build and toolchain: resources

Level: 201 · where the claims in this chapter come from

One line: The go command's own documentation settles most of this chapter — go help build, go help buildconstraint, go help generate, go help environment — and the release notes say when each piece arrived; the books cover the same ground under their tooling chapters.

Primary sources

Books

  • Jon Bodner, Learning Go, 2nd ed. (O'Reilly, 2024), chapter 11, "Go Tooling" — the sections "Embedding Content into Your Program", "Embedding Hidden Files", "Using go generate", "Working with go generate and Makefiles", "Reading the Build Info Inside a Go Binary", "Building Go Binaries for Other Platforms" and "Using Build Tags". The one chapter that covers all five lessons.
  • Miki Tebeka, Effective Go Recipes (Pragmatic, 2024), chapter 14, "Building Applications" — Recipe 72, "Embedding Assets in Your Binary"; Recipe 73, "Injecting Version to Your Executable"; Recipe 74, "Ensuring Static Builds"; Recipe 75, "Using Build Tags for Conditional Builds"; Recipe 76, "Building Executables for Different Platforms"; Recipe 77, "Generating Code".
  • Alan A. A. Donovan and Brian W. Kernighan, The Go Programming Language (Addison-Wesley, 2015), chapter 10, "Packages and the Go Tool" — section 10.7, "The Go Tool", and 10.7.3, "Building Packages", where build tags appear. Written before modules, //go:embed and //go:build; the go command it describes is GOPATH's.
  • Go in Practice, 2nd ed. (Manning, 2025), chapter 10, "Sending and receiving data" — section 10.1.3, "Embedding files in a binary"; chapter 13, "Reflection, code generation, and advanced Go" — section 13.3, "Generating Go code with Go code".
  • Adam Freeman, Pro Go (Apress, 2022) — a reference for the language and the standard library; build constraints, //go:embed, -ldflags and go generate are not among its topics.

Not on the shelf

Talks and videos

  • Russ Cox, "Go with Versions", GopherCon Singapore 2018 — the design of modules and the go.mod file that every driver in this chapter creates with go mod init.
  • Rob Pike's Generating code ↗ is a blog post rather than a talk; no recorded talk on go generate, //go:embed or reproducible toolchains is listed here, because none could be verified while writing this page.

Read with care

  • Any guide that ends at // +build — the line still works in Go 1.25 (measured on the vet page), but gofmt adds //go:build above it, and tools written after Go 1.17 read only the new line.
  • Guides that say -ldflags -X silently ignores a variable of the wrong type — on Go 1.25 the linker refuses an int with cannot set with -X: not a var of type string; what is silent is a misspelt name or a computed initialiser.
  • Tutorials that go get a code generator to install it — since Go 1.17 go get no longer installs binaries; use go install pkg@version, go run pkg@version in the directive, or the tool directive from Go 1.24.
  • Examples that set GOFLAGS with go env -w on a developer machine and call it CI configuration — the file it edits is the user's, and an environment variable in the job overrides it anyway.
  • Pre-release articles on //go:embed that put the directive on a local variable, or embed .. paths — both are refused, as the compiler-errors page records.
  • Advice to strip binaries with the system strip — Go's linker has -s -w for that; an external strip has damaged Go binaries on macOS in past releases and is not needed.

Checked 2026-09-23.