Saturday, April 23, 2011

Cross Compiling Google Go Code

This is more of a note to self, so I can look up this information in the future as needed. Google Go makes it really easy to cross-compile. Here is how you an compile your Go project for another architecture. The first step is to compile the cross compiling compilers (I can't believe I just typed that). So lets checkout the source code for the go compiler.
hg clone -r release go

Now to compile the Go compiler for the architecture of your machine, simply cd into the go/src directory and run the all.bash script
cd go/src; ./all.bash
If you want to create compilers for a different architecture you set the GOARCH environment variable and then run the make.bash script.
GOARCH=arm ./make.bash
GOARCH=386 ./make.bash
GOARCH=amd64 ./make.bash

The all.bash script compiles the compiler and runs the unit tests, the make.bash script just compiles the compilers.

This will create separate compilers, linkers and assemblers for each of the three architectures. Because each compiler, linker and assembler have a different name you can have support all architectures simultaneously.

Once you have the Go compilers compiled you can now compile your project for different architectures by creating a Go Makefile and setting the GOARCH environment variable before typing make.

GOARCH=arm make
GOARCH=386 make
GOARCH=amd64 make

That's it! You can now cross compile your Go code. More information on the Go compilers, creating a Go Makefile and getting started with Go can be found here, here, and here respectively. Happy Hacking!

Friday, April 22, 2011

I'm back

Last year I decided that it was time to finish up my Masters degree. I recognized that in order to finish in a timely manner I would need to forgo all hobbies for a while and so this blog has been on hold. I'm now done, or at least I'm at the stage where I'm waiting for the final announcement that I'm done and so I'm now returning to normal life. After having dropped out more than a year ago I'm finding that it's taking some time to get adjusted to normal non-academic life. I'm also slowly starting to remember all the non-homework activities that I used to participate in. I wonder how long it will be before I become as busy as I was before.