Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: no easy way to install multiple binaries to desired location when cross-compiling #13063

Closed
rogpeppe opened this Issue Oct 27, 2015 · 7 comments

Comments

Projects
None yet
8 participants
@rogpeppe
Copy link
Contributor

rogpeppe commented Oct 27, 2015

It's quite common to want to install a bunch of commands in
a single repository with "go install ./...". When packaging things
and not cross-compiling, we can use GOBIN to cause the binaries
to be written to a given directory. This doesn't work when cross-compiling
(see issue #9769), but there's no straightforward alternative.

Something like this can work, but feels clumsy:

cmds=$(go list -f '{{if (eq .Name "main")}}{{.ImportPath}}{{end}}' ./...)
cd $destdir
for i in $cmds; do
    go build $i
done

Perhaps if GOPATH has more than one element, binaries should
be installed to the first element of GOPATH, similarly to packages.

Then:

 GOPATH=$destdir:$GOPATH go install ./...

would do the trick, installing to $destdir/bin/$GOOS_$GOARCH

@bradfitz bradfitz changed the title no easy way to install multiple binaries to desired location when cross-compiling cmd/go: no easy way to install multiple binaries to desired location when cross-compiling Oct 27, 2015

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Nov 5, 2015

@james-lawrence

This comment has been minimized.

Copy link
Contributor

james-lawrence commented Jan 10, 2016

Not sure I agree that there isn't a straight forward alternative. The problem is its inconsistent.
If it consistently defaulted to $GOPATH/bin and overwrote whatever was there regardless of architecture, then we could just use GOBIN to cross compile safely. I mean the whole point of GOBIN is to specify that directory correct? I could be wrong on that...

consistency is why I suggested just using a flag to force the directory mode. #11001. That approach was to keep current behaviour, but if we don't care about maintaining that then lets just drop the creation of additional directories and emit warnings (or refuse to compile) when GOBIN isn't set and you are compiling to a non-native binary.

I don't see requiring GOBIN to be set when cross compiling would be a huge issue, we specify the majority
of those environment variable anyways when cross compiling.
i.e)

GOBIN=$PWD/darwin-amd64 GOOS=darwin GOARCH=amd64 go install ./...
GOBIN=$PWD/linux-amd64 GOOS=linux GOARCH=amd64 go install ./...

would write to different directories and be safe where as:

GOOS=darwin GOARCH=amd64 go install ./...
GOOS=linux GOARCH=amd64 go install ./...

would overwrite each other and emit a warning (or error) for one of the attempts depending if you where on mac or linux.

@simonvanderveldt

This comment has been minimized.

Copy link

simonvanderveldt commented Mar 8, 2016

+1

I'll explain my use case: I run go like all/most of my tooling in containers, but since I sometimes work on a Mac I need to cross-compile to make the binaries work.

Before the changes as discussed in #9769 it worked nicely for all go commands including go install. I set $GOBIN to $GOPATH/bin so the files ended up in the correct location on my Mac. After the change they end up in $GOPATH/bin/darwin_amd64.
If I set GOBIN as well as GOOS and GOARCH I get the following error go install: cannot install cross-compiled binaries when GOBIN is set

@amery

This comment has been minimized.

Copy link

amery commented May 23, 2017

The problem still exists in 1.8.x. the automagic ${GOPATH}/bin/${GOOS}_${GOARCH} works for darwin vs linux.... but for ARMv5 vs ARMv7 it becomes destructive :( this also affects ${GOPATH}/pkg but at least there is a -pkg option to disambiguate them there. It would be great if -o would support directories when using ./... notation

@andig

This comment was marked as off-topic.

Copy link

andig commented Jun 8, 2018

It would be great if -o would support directories when using ./... notation

+1

adracus added a commit to adracus/gardener that referenced this issue Jul 31, 2018

fix go build for cross compiles
see issue golang/go#13063 why we cannot use
`go install`
@bcmills

This comment has been minimized.

Copy link
Member

bcmills commented Jan 23, 2019

It would be great if -o would support directories when using ./... notation

That's #14295.

@bcmills

This comment has been minimized.

Copy link
Member

bcmills commented Jan 23, 2019

Anyone have a use-case that would not be handled by #14295?

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Feb 23, 2019

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@gopherbot gopherbot closed this Feb 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.