Cross-compilation builds software on one operating system or hardware architecture for execution on another. Go supports this directly through the installed toolchain: set GOOS for the target operating system and GOARCH for its hardware architecture. section 12.4.2
Build a Windows binary
To build a Windows executable for the 386 architecture, run GOOS=windows GOARCH=386 go build. GOARCH can also target amd64 or arm; GOOS can target windows, linux, darwin, or freebsd. section 12.4.2
$ GOOS=windows GOARCH=386 go build
Use the compact command listing to see how target operating system and architecture are supplied to go build. section 12.4.2
For several deployment targets:
- Use the standard Go toolchain when a straightforward build is sufficient. section 12.4.2
- Use gox when multiple operating-system and architecture combinations should be built concurrently; its output can be organized by target. section 12.4.2
- Test every cross-compiled result before deployment, especially when the application uses cgo and C libraries. section 12.4.2

