shithub: docs.9front.org

ref: 23520cdd0314a2ea171ce8a7c1047fbd805a7e83
dir: /building-go.md/

View raw version
Building Go from source
===

First we'll need a suitable location for our 'GOROOT', the standard convention is
to place it in '/sys/lib/go/$objtype-$version'.

	mkdir -p /sys/lib/go
	cd /sys/lib/go
	hget https://golang.org/dl/go1.15.2.src.tar.gz | gunzip -c | tar x
	mv go amd64-1.15.2

If you don't already have some version of Go installed it's best to
grab a bootstrap tarball built by the 9legacy folks:

	hget http://www.9legacy.org/download/go/go1.14.1-plan9-amd64-bootstrap.tbz | bunzip2 -c | tar x

If you have an existing install you can use that instead of the 9legacy bootstraps.
There may be some hiccups when there are large version distances between a
bootstrap and desired build version. It is best to use to the latest bootstrap when possible and
some intermediate builds may be required depending on the age of the bootstrap.

Next we'll need to configure both 'GOROOT' and 'GOROOT_BOOTSTRAP'

	GOROOT_BOOTSTRAP=/sys/lib/go/go-plan9-amd64-bootstrap
	GOROOT=/sys/lib/go/amd64-1.15.2
	cd amd64-1.15.2/src
	make.rc

This will build the binaries under `$GOROOT/bin`. You can install these with:

	cp $GOROOT/bin/* /$objtype/bin

or bind them with `/bin` in your profile:

	bind -b $GOROOT/bin /bin

If you have the memory available on your system it may be faster to build using a ramfs in '/tmp'.
Setting 'GOROOT_FINAL' to the desired final location of 'GOROOT' will help in building.

	mkdir -p /sys/lib/go/
	ramfs
	cd /tmp
	hget https://golang.org/dl/go1.15.2.src.tar.gz | gunzip -c | tar x
	hget http://www.9legacy.org/download/go/go1.14.1-plan9-amd64-bootstrap.tbz | bunzip2 -c | tar x
	mv go amd64-1.15.2
	GOROOT_BOOTSTRAP=/tmp/go-plan9-amd64-bootstrap
	GOROOT_FINAL=/sys/lib/go/amd64-1.15.2
	cd amd64-1.15.2/src
	make.rc
	dircp /tmp/amd64-1.15.2 /sys/lib/go/

You can verify that GOROOT has been set properly using:

	$GOROOT_FINAL/bin/go env