https://codereview.appspot.com/57100043/ is a CL to support
cross-compiling when building programs that use cgo. It currently
introduces new environment variables XCC and XCXX to mean the
compilers to be used when cross-compiling.
Normally we only need a single compiler, which suggests that perhaps
we can always use CC. However, when running make.bash with GOARCH !=
GOHOSTARCH, we need to build some programs for GOARCH and some for
GOHOSTARCH.
The GNU autotools have many problems but they have good support for
building with a cross-compiler and for building cross-compilation
tools. They clearly differentiate between the build system (where the
tools are built), the host system (where the tools are run), and the
target system (where the programs built by the tools are run). The Go
system conflates the build and host system, for Go we have the
build/host system (where the tools are built and where they are run)
and the target system (where the programs built by the tools are run).
The build/host system is GOHOSTARCH and the target system is GOARCH.
When building a package that uses the GNU autotools, there are three
kinds of environment variables. CC is the compiler for the build
system. CC_FOR_HOST is the compiler for the host system.
CC_FOR_TARGET is the compiler for the target system.
Right now when building the Go system CC is the compiler for the
build/host system, and also becomes the default compiler for the
target system, and therefore becomes the compiler used to build the
packages that use cgo (net, os/user, crypto/x509, runtime/race). This
is of course the normal case and it should continue to work that way.
I propose that we use the same terminology as the GNU autotools, as
follows:
1) When building Go--that is, when running make.bash--CC is the
compiler used to build the Go compiler. CC_FOR_TARGET, if set,
becomes the default compiler used by cgo, and is used by cgo during
the build. If CC_FOR_TARGET is not set, it defaults to CC. In other
words, when running make.bash, CC is for GOHOSTARCH and CC_FOR_TARGET
is for GOARCH.
2) When running the go command, CC is the compiler to use. In other
words, when running go, CC is for GOARCH.
3) If we ever separate the host and build systems in Go, we will do it
by in some cases, while running make.bash, using CC_FOR_BUILD instead
of CC.
Another possibility would to always have CC correspond to GOARCH, and
to use CC_FOR_HOST while running make.bash. I personally like this
approach less because it's conventional when building a package to
have CC be the compiler used for the build.
Another possibility would be to have always have CC correspond to
GOHOSTARCH, and to use CC_FOR_TARGET when running the go command. I
personally like this approach less because the go command, unlike
make.bash, only cares about one compiler, and so I think that compiler
ought to be called CC.
Thoughts?
Ian