I have a Synology NAS. It is pretty awesome and I enjoy it quite a bit.
I’ve recently started hacking on Go (golang). It is also pretty awesome.
One of the huge wins that you get with hacking Go is the ability to cross compile binaries for different architectures.
This means I can write a program on my Macbook Air, compile it to run under linux/arm5, and then rsync it to my synology and it will run.
Here is a “Hello World” example that you can try at home.
I’m operating under the assumption that you’re using homebrew.
The first step involves bootstrapping Go to support the foreign architecture. Out of the box on OSX, Go is only going to be able to build binaries for darwin/amd64.
This can be resolved very quickly by doing the following (keep in mind if you wanted to compile a binary for Windows, you could do the same thing).
cd `brew --prefix go`
GOOS=linux GOARCH=arm CGO_ENABLED=0 ./make.bash --no-clean
After that runs, your Go installation is able to build binaries for Linux systems with ARM CPUs. Pretty crazy, huh?
Remember the above can be applied to Linux, Darwin, and Windows systems running under i386,amd64, and ARM. You just have to run the above command for each platform that you plan on compiling binaries for.
Ok the next step is to actually compile a binary for the foreign architecture.
This is done using the `go` tool.
As an exercise to the reader, I’ll let you piece together a HelloWorld.go file.
When you’re ready to compile it just do the following
GOOS=linux GOARCH=arm GOARM=5 go build HelloWorld.go
That’s it. A binary named ‘HelloWorld’ should be in your current working directory. Just rsync/scp it to your NAS and it’ll run.