Cross-compilation
Cross-compilation is the process of generating a binary executable file for a different architecture than the one that we are working on without having access to other machines. The main benefit that we receive from cross-compilation is that we do not need a second or third machine to create and distribute executable files for different architectures. This means that we basically need just a single machine for our development. Fortunately, Go has built-in support for cross-compilation.
To cross-compile a Go source file, we need to set the GOOS
and GOARCH
environment variables to the target operating system and architecture, respectively, which is not as difficult as it sounds.
You can find a list of available values for the GOOS
and GOARCH
environment variables at https://go.dev/doc/install/source. Keep in mind, however, that not all GOOS
and GOARCH
combinations are valid. You can find a list of all valid combinations using go tool dist list
.