Go: cmd/go: buildmode=plugin always recompile all dependencies

Created on 25 Mar 2017  ·  1Comment  ·  Source: golang/go

go version go1.8 linux/amd64

What did you do?

For example,

package main
var V int
go build -buildmode=plugin -v test/main.go

What did you expect to see?

lion@Lion-Laptop [ test ] $ go build -buildmode=plugin -v test/main.go
command-line-arguments
lion@Lion-Laptop [ test ] $ 

What did you see instead?

lion@Lion-Laptop [ test ] $ go build -buildmode=plugin -v test/main.go
runtime/internal/sys
runtime/internal/atomic
runtime
runtime/cgo
command-line-arguments
lion@Lion-Laptop [ test ] $ 

The same as building with -a

NeedsFix help wanted

Most helpful comment

This is because all packages need to be rebuilt by the toolchain configured for dynamic linking, and by default go build does not cache intermediate package builds. I believe work on cmd/go will change that, and this problem will go away.

Until then, you can use -i when building plugins to cache intermediate package builds, so this only happens the first time:

$ go build -buildmode=plugin -i -v plugin1
runtime/internal/sys
runtime/internal/atomic
runtime
common
internal/cpu
errors
unicode/utf8
sync/atomic
unicode
internal/race
math
sync
syscall
strconv
reflect
runtime/cgo
plugin1
$ go build -buildmode=plugin -i -v plugin1
plugin1
$

>All comments

This is because all packages need to be rebuilt by the toolchain configured for dynamic linking, and by default go build does not cache intermediate package builds. I believe work on cmd/go will change that, and this problem will go away.

Until then, you can use -i when building plugins to cache intermediate package builds, so this only happens the first time:

$ go build -buildmode=plugin -i -v plugin1
runtime/internal/sys
runtime/internal/atomic
runtime
common
internal/cpu
errors
unicode/utf8
sync/atomic
unicode
internal/race
math
sync
syscall
strconv
reflect
runtime/cgo
plugin1
$ go build -buildmode=plugin -i -v plugin1
plugin1
$
Was this page helpful?
0 / 5 - 0 ratings