Why you should use go build -a (or gb)

Felix Geisendörfer
1 min readNov 20, 2015

Update: The problem was fixed in Go 1.5 (thanks Nicolas Grilly). I was accidentally testing with Go 1.4 when writing this article 😩.

The go build tool is pretty great compared other platforms, but there are a few problems with it when it comes to reproducible builds.

Consider the following scenario:

As you can see above, it’s possible for go build to “successfully” build a binary, even so one of the files it depends on was deleted. This is happening because go build compares the file modification time of the previously built pkg binary with the file times of all the files in the pkg directory, but not the modification time of the pkg directory itself.

So if you’re looking to improve your builds, especially for your CI setup, you should always use `go build -a`.

If you want to go even further, checkout Dave Cheney’s gb build tool, which also fixes this issue, as well as many other problems around reproducible builds.

That being said, I’m not sure why this hasn’t been fixed in go build itself yet, if anybody knows the reason I’ll update this article.

--

--

Felix Geisendörfer

Programmer. Mostly using Go, JS, HTML and Unix tools. Started @nodecopter and @transloadit. Contributed a lot to @nodejs.