Out of memory building grafana on a pi

I am trying to build grafana on a pi 3 but cannot as it fails due to lack of memory

go run build.go setup
Version: 6.1.0-pre, Linux Version: 6.1.0, Package Iteration: 1553960343pre
go get -v github.com/golang/dep
go install -v ./pkg/cmd/grafana-server
# github.com/colinl/grafana/pkg/cmd/grafana-server
/usr/local/go/pkg/tool/linux_arm/link: running gcc failed: fork/exec /usr/bin/gcc: cannot allocate memory

I have shut down as much other stuff as I can, it is a headless server so no gui. Google suggested export GOMAXPROCS=1 but that hasn’t fixed it.
Can anyone offer suggestions?

[Edit] I have 500MB of swap and it is only using about half of that when it fails.

Golang supports cross architecture compilation, so you can build Grafana for RP (armX architecture) on standard amd64 server, where high memory allocation won’t be a problem.

OK, thanks, I had just started googling how to do that when I managed to get it to complete. I had found another couple of services to shutdown and had freed up some disc space (it was getting low) and it managed to go through to the end. I have a suspicion that it was actually getting a bit further each time so it may be that if I cleaned it and started again I would still have to run it a dozen times to get it through, or it may be that the last fiddling I did was just enough. I won’t know unless I wipe it out and try again (or rather move it away, so I can put it back). I may do that at some point and will comment again here if I do.

Although I succeeded in building on the pi it is horribly tedious so I decided to have a go a cross compiling (on Ubuntu). I can successfully build an amd64 deb package using
go run build.go build package
and have determined that to cross build for a pi (3) I need something like
go run build.go -goarch armv7 -pkg-arch armv7 build package
but when I do that I get

go version go1.12.1 linux/amd64
Targeting linux/armv7
go build -ldflags -w -X main.version=6.1.0-pre -X main.commit=1b312597a -X main.buildstamp=1553947972 -X main.buildBranch=graph-y-ticks -o ./bin/linux-armv7/grafana-server ./pkg/cmd/grafana-server
# runtime/cgo
gcc: error: unrecognized command line option '-marm'; did you mean '-mabm'?
exit status 2
exit status 1

Presumably I am doing something wrong. Can someone point out my error?

You need to install and use cross compiler (arm-linux-gnueabihf-gcc for armv7). Example build script:

OK, thanks, will see if I can work out how to do it.