in module mode, GOPATH is really only used for deriving default locations for GOBIN and GOMODCACHE setting it to /dev/null might not be great for caching dependencies if GOMODCACHE isn't set
cross compile to GOBIN was recently (re)opened https://go.dev/issue/57485 There are open requests to print out the directory where it would be installed, (presumably to update PATH) but not for the actual binaries built. https://go.dev/issue/45546 -o dir/ ending in a slash is documented as: > If the named output is an existing directory or > ends with a slash or backslash, then any resulting executables > will be written to that directory. - sean On Fri, Jan 20, 2023 at 5:30 PM 'Tim Hockin' via golang-nuts < golang-nuts@googlegroups.com> wrote: > I'm trying to make kubernetes' codebase easier to navigate by people who > have muscle-memory for go. In the past we said "you have to call our > Makefile" to build things. I'd like to make \`go install\` work but I'm > struggling to find a pattern that really works - am I missing something? > > First, GOPATH is dead. I hate that Go silently writes to my home > directory, which is ALMOST NEVER what I really wanted. > > Aside: is there any way to get `go install` and `go build` to tell me what > they wrote? Would that be a reasonable feature request? E.g. > > ``` > $ go install --print-result <pkg/path/to/cmd> > /home/thockin/go/bin/cmd > ``` > > I usually set GOPATH=/dev/null. > > ``` > $ GOPATH=/dev/null \ > go install <pkg> > go install <pkg>: mkdir /dev/null: not a directory > ``` > > Good. I want to install to a repo-local dir so all of our CI and stuff > can find it. > > ``` > $ GOPATH=/dev/null \ > GOBIN=./bin \ > go install <pkg> > ``` > > That works. > > ``` > $ GOPATH=/dev/null \ > GOBIN=./bin \ > GOARCH=arm \ > go install <pkg> > go: cannot install cross-compiled binaries when GOBIN is set > ``` > > Well, shoot. I can't find any other way for `go install` to work. > > ``` > $ GOPATH=/dev/null \ > GOBIN=./bin \ > GOARCH=arm \ > go build <pkg> > ``` > > That works, but splats the file into the current dir. To be fair, that is > documented behavior. > > ``` > $ GOPATH=/dev/null \ > GOARCH=arm \ > go build -o ./bin <pkg> > ``` > > That works, except when ./bin doesn't exist, in which case it becomes the > output file (if I am building 1 thing) or I get an error (if I am building > multiple things): > > ``` > $ GOPATH=/dev/null \ > GOARCH=arm \ > go build -o ./bin <pkg1> <pkg2> > go: cannot write multiple packages to non-directory ./foo > ``` > > I can specify a directory by adding a trailing `/` it seems: > > ``` > $ GOPATH=/dev/null \ > GOARCH=arm \ > go build -o ./bin/ <pkg1> <pkg2> > ``` > > That seems to work, but I have to get the invocation JUST RIGHT 100% of > the time or risk causing weird errors and CI fails. The obvious answer is > "wrap it in a script or Makefile", which puts me right back where I started. > > Is there a better answer? > > Tim > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/d04fca5a-8b85-4386-9bae-50853f317fccn%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/d04fca5a-8b85-4386-9bae-50853f317fccn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAGabyPocd8cx%3Dyg1arT74ULHoLjB4eNrUm17dqAw6KG8SazmPA%40mail.gmail.com.