Cross compiling Go packages to ARM is easy unless they rely on C libraries via cgo, in which case C cross-compilers and libraries built for the target are required on the host, and the invocation is not straightforward at all.
Dimitri's post shows a way to do it using armhf chroots, and inspired by it I put together a docker image that does slightly more and can be used as if it were a simple command. The image uses a Go
package built from a PPA , since the one in the archive does not have a CGO enabled ARM cross compiler.
Install the image
$ docker pull janimo/goqml-cross
Set up an alias for convenience
alias goqml-cross='docker run --rm -it -v $(pwd):/home/developer -v $GOPATH:/home/developer/gopath -w $(pwd|sed "s,$GOPATH,/home/developer/gopath,") janimo/goqml-cross'
Go to the source tree
$ cd $GOPATH/src/your/package
Run the container as if it were the go tool (which in fact it is, /usr/bin/go being the docker container's default entry point)
$ goqml-cross version
$ goqml-cross build -i
This will reuse your host environment's GOPATH and place the resulting Go packages under $GOPATH/pkg/linux_arm/ to be available in subsequent fast incremental builds.
Check the docker registry for details on how to use it and the project on github if you want to build your image from source.
Add a comment