go
go copied to clipboard
cmd/go: allow versioned `go build` commands
~~Alternative:~~ allow to change the installed main package name in go install
command
Since go1.16, go install
accepts arguments with version suffixes. go install
places the output in $GOPATH/bin
or $GOBIN
, but does not allow the output binary's name change.
When a user wants to use multiple versions of tools, the user need to be careful not to overwrite other versions.
Different versions may be coming from different module paths.
e.g. VS Code Go extension uses two different versions of gocode
(stamblerre/gocode and mdempsky/gocode). In order to install the former, it does switching GOBIN
to use a temporary directory, installing it, and renaming and copying it to the real GOBIN
.
Alternative: There are other proposals for applying the same to go run
(https://github.com/golang/go/issues/42088) and go list
(https://github.com/golang/go/issues/44203). Extending go build
in the same way (or extending go install
) will help simplifying the tool installation workflow.
cc @jayconrod @bcmills @matloob