FAQ
I'd like to be able to build go packages with a cross-compiling gccgo
toolchain, without having to modify the package build scripts, or install
wrapper scripts or target-specific versions of the go tool.

Ideally cross-compiling would work just like it does with the Linux kernel
and other non-go projects, where the value of CROSS_COMPILE environment
variable gets tacked onto the front of any invocation of gcc, g++, ld, and
so on. If you're building for, say, a MIPS target, and your build machine
has cross compilers installed as mips-linux-gnu-gcc, mips-linux-gnu-g++,
and so on, you run make CROSS_COMPILE=mips-linux-gnu-. To build with the
normal compilers, you just leave CROSS_COMPILE unset or empty.

The following patch is my attempt to add this capability to go. With this
patch, setting CROSS_COMPILE to xxx-yyy-zzz- causes go build to:

- use gccgo rather than gc toolchain (similar to passing -compiler gccgo,
except it doesn't whine when the architecture is something other than x86
or arm)
- set GOARCH=xxx
- set GOOS=yyy
- enable cgo (and pass actual arch and os to cgo via GOARCH and GOOS)
- prepend xxx-yyy-zzz- default compiler names, e.g. xxx-yyy-zzz-gccgo
instead of gccgo

You can still override these parameters individually by setting GOARCH,
GOOS, CGO_ENABLED, CC, and so on. But my goal is to make cross-compiling as
transparent as possible, requiring only the CROSS_COMPILE environment
variable to be set.

When CROSS_COMPILE is empty or unset, go build behaves as usual.

The attached patch should work with the recent default branch of the golang
source tree. I have also backported the changes to the Debian 1.2.1-2
version of golang.

http://xenon.stanford.edu/~eswierk/misc/golang/golang-gccgo-cross-19905.patch
http://xenon.stanford.edu/~eswierk/misc/golang/golang-gccgo-cross-deb-1_2_1-2.patch

--Ed

--

---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedMay 14, '14 at 9:41p
activeMay 14, '14 at 9:41p
posts1
users1
websitegolang.org

1 user in discussion

Ed Swierk: 1 post

People

Translate

site design / logo © 2021 Grokbase