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: spurious error about GOBIN during cross-compile #11778

Closed
zcalusic opened this issue Jul 18, 2015 · 16 comments
Closed

cmd/go: spurious error about GOBIN during cross-compile #11778

zcalusic opened this issue Jul 18, 2015 · 16 comments
Milestone

Comments

@zcalusic
Copy link

The error in title is the result of: GOARCH=386 go install -x

But $GOBIN is NOT set!

How do I install cross-compiled binaries now?

go version devel +aadd84e Sat Jul 18 01:35:25 2015 +0000 linux/amd64

Basically go1.5beta2 + some fixes

@crawshaw crawshaw self-assigned this Jul 18, 2015
@crawshaw crawshaw added this to the Go1.5 milestone Jul 18, 2015
@crawshaw
Copy link
Member

Looks like my attempt to fix #9769 is overzealous. Taking a look.

@crawshaw
Copy link
Member

I suspect the way you are trying to use go install should fail, it's just a slightly confusing error message. When you go install mycmd, it typically installs in $GOPATH/bin, or if it's set, $GOBIN. When cross compiling, there is really no good place to do the installation. Both of those bin directories are designed to be on your $PATH, so creating subdirectories does not make sense.

In general with your own programs, you should go build cross-compiled binaries, not go install them. You can use -o to specify where you want the binary to end up.

However cross-compile go installs of cmd/* binaries should work, except cmd/go when GOBIN is set. It looks like that's one case I missed, so I'm looking at it and improving the error message.

@zcalusic
Copy link
Author

Makes sense. I changed my rules from:

go install -x
GOARCH=386 go install -x

to

go install -x
GOARCH=386 go build -x -o $(GOBIN)/linux_386/binary

and it's now working as before.

Though, to be honest, I liked the previous way better, less typing, more streamlined rules for building. 386 binaries are executable on the amd64 platform, so makes sense to have them in the subdirectory of $GOPATH/bin.

If this change in policy is final, certainly the error message should be improved to tell that go install won't work for cross-compiling and that go build -o should be used.

@zcalusic
Copy link
Author

Oh, few minutes later I see another bad consequence of this change in policy. go build is not the same as go install, now if I run it again it's again rebuilding from the scratch, even if there were no changes in the source code and the binary is up-to-date. go install is clever not to rebuild if not needed.

Now, seeing this behaviour, I don't like this policy change at all. There should be a way to go install even for cross-compiling, IMHO.

@crawshaw
Copy link
Member

You should probably take up the issue of whether or not it is a good idea on #9769. I tend to think of cross compilation as a special case, but I see your point.

@gopherbot
Copy link

CL https://golang.org/cl/12384 mentions this issue.

@zcalusic
Copy link
Author

I left a note on #9769, too. Although, I'm still a bit puzzled, #9769 specifically mentions creating subdirectories under $GOBIN as problematic, where I see behaviour change even without $GOBIN set.

@rsc rsc changed the title go install: cannot install cross-compiled binaries when GOBIN is set cmd/go: spurious error about GOBIN during cross-compile Jul 21, 2015
@gavrie
Copy link

gavrie commented Jul 21, 2015

I'd just like to point out how problematic this issue is: When cross-compiling an executable, all dependencies are cross-compiled as well. This means that without functional cross compilation support for go install, all dependencies are rebuilt every time the end user's executable is built, which takes a lot of time.

@dmitris
Copy link
Contributor

dmitris commented Jul 21, 2015

I hit the same error and wonder what needs to be done to avoid rebuilding all the standard library dependencies on every invocation of GOOS=linux go build (when cross-compiling on a Mac).

@crawshaw
Copy link
Member

The go build command has a -i flag that can be used when cross compiling.

@gavrie
Copy link

gavrie commented Jul 21, 2015

@crawshaw Cool, that helps! It saves a lot of time when compiling. But of course it would still be great if with the release of Go 1.5 the build system will enable avoiding any gratuitous compilation when cross-compiling, even if it's just the end user's binary.

@jhawk28
Copy link

jhawk28 commented Jul 21, 2015

Came across this issue when trying beta2 out. Would also prefer the old behavior.

@dvyukov
Copy link
Member

dvyukov commented Jul 28, 2015

Error message text, so that it is possible to find this issue by exact text:

go install: cannot install cross-compiled binaries when GOBIN is set

@inconshreveable
Copy link
Contributor

This change completely breaks my cross-compilation workflow and is very frustrating. (GOBIN is not set)

@gopherbot
Copy link

CL https://golang.org/cl/12938 mentions this issue.

@mwhudson
Copy link
Contributor

FWIW, you should be able to say GOARCH=xxx go install -buildmode=archive prefix/... to only compile and install the non-main packages.

andreaskoch added a commit to andreaskoch/allmark that referenced this issue Aug 20, 2015
The previous cross-compilation process does not work with go 1.5
because go 1.5 does not allow to use GOBIN (see:
golang/go#11778).

There is no longer a special docker-image for cross-compilation with all
sources
compiled for all platforms since this is no longer necessary (see:
https://news.ycombinator.com/item?id=9135163)

And go is no longer available for x86 architectures (see:
https://golang.org/doc/go1.5)
@golang golang locked and limited conversation to collaborators Aug 5, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants