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
