8.10.12

Go on the Pi

If you have a Raspberry Pi and you want to program it, there are a lot of choices. Here's another: Go.

You're probably wondering why Go? Well, it's got some good libraries for networking and the binaries it makes are statically linked (albeit huge) so you don't need any supporting runtime when you ship a program. It's also cross platform enough so that the same program compiles on Windows and the Pi.

There are a few problems with it too. I would argue that Go is the ugliest looking language in the world because it forces K & R style braces - always. And the debugger is gdb, which I compare only slightly favourably with repeatedly poking a sharp stick in your eye. But hey, it's only a system the size of a credit card, what do you expect. I've worked on many embedded systems that have far more arcane (and expensive) tool chains.

Many others have got Go running on the Pi. ARM is one of the supported architectures. But since there are no binary packages available, this means installing from source. In case I have to do this a third time because I'm an idiot and baffed the SD Card image again (don't mess with the files in /etc/sudoers.d without enabling a root passwd), I'm recording the steps here:

Set the memory split for the pi, to the maximum for the CPU using:
sudo raspi-config
and the memory_split option.

Start by getting mercurial running:
sudo apt-get install mercurial

As suggested add these lines to /etc/mercurial/hgrc:
[web]
cacerts = /etc/ssl/certs/ca-certificates.crt


Get the GO source code.
cd /usr/local
sudo hg clone -u release https://code.google.com/p/go
(note: this takes a while)

Then update to the tip so that the ARM 7 support is available:
cd go
sudo hg update -C tip

Build the go runtime and binaries:
cd go/src
export GOARM=7
sudo ./all.bash

(note: this takes a real long time)

Test it out:
export PATH=$PATH:/usr/local/go/bin
Create a file hello.go containing:
package main
import "fmt"
func main() {
    fmt.Printf("hello, world\n")
}

Then run it with the go tool:
go run hello.go
which produces:
hello, world