gokrazy / tools

this repository contains the gok CLI tool of gokrazy
https://gokrazy.org
BSD 3-Clause "New" or "Revised" License
50 stars 27 forks source link

Use of go install interacts badly with $GOBIN #2

Closed twpayne closed 4 years ago

twpayne commented 7 years ago

This issue might be related to trying to use gokrazy from macOS. For sure, building gokrazy images on non-Linux systems is not yet supported and this is likely one issue that will need to fixed to enable that.

On my macOS system, I have:

export GOPATH=$HOME
export GOBIN=$GOPATH/bin

When I run

gokr-packer -overwrite=/dev/disk3 github.com/gokrazy/hello

I get the error:

2017/03/23 19:42:55 packer.go:222: installing [github.com/gokrazy/hello]
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set

I suspect that this is related to the use of go install at gotool.go:71. I suspect that the cross-compiled binaries should be built with go build but rather than installing them, the built binaries should be copied from their output location (wherever that is) to their final location.

go build has an -o option to specify the path of the output binary, but this obviously only works when building one binary at a time and is incompatible with gokrazy's use of ./... to build all binaries in a tree.

stapelberg commented 7 years ago

https://github.com/gokrazy/gokrazy/issues/14 is related

stapelberg commented 7 years ago

As per http://stackoverflow.com/a/25950604/712014, why are you setting GOBIN in the first place? Binaries should be installed to $GOPATH/bin by default anyway? :)

stapelberg commented 4 years ago

As per https://groups.google.com/g/golang-nuts/c/nyS0ESkKTlk, using go install with GOBIN when cross-compiling is intentionally unsupported.

It is desirable to not litter the user’s GOBIN (or GOPATH/bin etc.) when using gokrazy, so we should switch from go install to go build indeed.