From 46c6d6f6565a5e01c4fc3d7249f87a1a6a487ab8 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 26 Feb 2017 03:51:44 -0500 Subject: [PATCH] compiling: Add -i flag to go build to speed up builds So builds take about 30s on my shitty machine which is pretty long. Turns out golang caches things in $GOPATH/pkg/ but is not clever enough to erase things from there that are out of date. As a result, it was rebuilding everything (including the unchanged dependencies) every build! By completely wiping out $GOPATH/pkg/ and then running `go build -i`, this now takes builds down to about 8 seconds. (After one full build is finished.) This is basically the same as running `go install`, but without copying junk to $GOPATH/bin. Hopefully the tooling will be smart enough to know when to throw out stuff in $GOPATH/pkg automatically and avoid this problem entirely. Is it wrong to send Google a bill for all the extra cpu cycles I've used? ;) --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 735b7409..d1bd6090 100644 --- a/Makefile +++ b/Makefile @@ -112,7 +112,7 @@ ifneq ($(OLDGOLANG),) @# avoid equals sign in old golang versions eg in: -X foo=bar time go build -ldflags "-X main.program $(PROGRAM) -X main.version $(SVERSION)" -o $(PROGRAM) $(BUILD_FLAGS); else - time go build -ldflags "-X main.program=$(PROGRAM) -X main.version=$(SVERSION)" -o $(PROGRAM) $(BUILD_FLAGS); + time go build -i -ldflags "-X main.program=$(PROGRAM) -X main.version=$(SVERSION)" -o $(PROGRAM) $(BUILD_FLAGS); endif $(PROGRAM).static: main.go