liveBook · Manning

Gox

As explained in Go in Practice, Second Edition

gox is a third-party Go command-line tool that builds binaries for multiple operating systems and architectures in parallel.

gox is a third-party Go command-line tool for cross-compiling binaries for multiple operating systems and architectures in parallel. It addresses applications developed on one platform but deployed or distributed on others. section 12.4.2

Listing 12.12 Cross-compiling an application with gox
$ gox \
  -os="linux darwin windows " \  #1
  -arch="amd64 386" \  #2
  -output="dist/{{.OS}}-{{.Arch}}/{{.Dir}}" .  #3

Build Linux, macOS, and Windows binaries for amd64 and 386, placing each result in an OS-and-architecture-specific directory. section 12.4.2

Use the surrounding Go toolchain deliberately:

  • Install gox with go get -u github.com/mitchellh/gox. section 12.4.2
  • Use GOOS and GOARCH with go build for a single target; use gox when parallel builds are useful. section 12.4.2
  • Test every target when cgo or external C libraries are involved, because cross-compilation can introduce complications. section 12.4.2

How Go in Practice, Second Edition covers it

How deep it goes
Shows installation and a parameterized multi-target command, while deferring implementation details beyond build configuration.
Examples
Uses Linux, macOS, and Windows targets with amd64 and 386 output directories.
What it assumes
Assumes the Go toolchain and introduces GOOS and GOARCH as target selectors.
What you can do after
Builds multiple cross-platform binaries concurrently with gox.
How it connects
Connects cross-compilation with GOOS, GOARCH, go build, filepath, and cgo.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Practice, Second Edition. The section links point to the parts of the book it draws on.