I came across interesting problem recently when building AzureRM: due to a massive refactoring, the repo now have a lot more files and packages

Ran out of tmp space

First, my WSL box throw tons of write /tmp/go-build123456789/...: no space left on device error. The tmp file system ran out of space.

This can be fixed be mapping another larger volume for compilation: export GOTMPDIR="$HOME/.cache/go-tmp" although I suspect this makes the build slower?

Slow compilation time

A cold build with no cache hit took 12 minutes. A common daily main pull require 5 - 7 mins depending on how much are changing.

I learned that go keep local build cache in $HOME/.cache/go-build and the morning ritual of pulling latest main to warm up the cache is really useful to speed up subsequent build throughout the day.

Stripping debugging info cuts down my build time to 10 minutes, it's not m uch, but why not if we don't need it? go build -ldflags="-s -w" ..

gobuildcache + Azure Pipeline

I even tried automating this using an Azure Pipeline, gobuildcache and a blob store with the hope it will speed up my local morning pull build, but no luck so far. For some reason I cannot get the cache key aligned between local and CI to get any hit at all. I've checked for matching go version, arch, build args, used -trimpath and -buildvcs=false, what else am I missing? Maybe the repo has to have the same path between local and CI?