This post will give you a guide to build Go on no matter which system.
- After Go 1.5, all the source codes are written in Go or Assembly. So in a system where there is a Go install, we can build another Go using Go itself. The feature is called bootstrapping.
GOARCHflag, we can build Go program for given platform with given architecture. This is cross compile of Go.
So, it’s possible to build a Go environment for my Lenovo Newifi 2 (D1), which is based on OpenWRT, equiped with MIPS Little Endian MT7621AT processor, 256MB memory.
But I want to keep the official firmware, so I decided to build an independant build of Go for my router.
Get your Go>=1.5 installed in your system:
> which go
If you don’t have Go installed, please install it with your current package manager.
> sudo apt-get install golang-go
Get Golang source code from the downloads page.
I chose to use Golang 1.12.4:
> wget https://dl.google.com/go/go1.12.4.src.tar.gz
Decompress the tarball:
> tar xvf go1.12.4.src.tar.gz
We’ll have a directory like this:
Begin directly your build for mipsle:
> GOOS=linux GOARCH=mipsle GOROOT_BOOTSTRAP=<your-go-root> ./make.bash
After the building, copy the following folders to the router:
For example, I created
/mnt/mmcblk0p1/usr/share/go folder for them.
GOROOT to environment variables and
bin to PATH:
> export GOROOT=/mnt/mmcblk0p1/usr/share/go
Create the Hello World code in
> go run test.go
or build and run it:
> go build test.go
Enjoy your journal with Go on your router!