-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: go build should be able to write multiple executables #14295
Comments
Flag -o would name the file and -odir would name the directory. Seems clear to me. If both are set one could complain if -o is a rooted path. Not sure this is worth doing at all, but it seems easy to design and understand. |
@robpike That's a fair design. I think it would be useful to have, but I'm unsure if it would pay for a new flag. I'm curious if others would also find it useful or if it is just me :). |
FWIW I have been looking for something like this as well. For company policy reasons I need to build a .deb on a build box. There are several binaries, which I currently build individually and then package up. Not a terrible nuisance, but could probably save me some compile time since the binaries share most code. |
if you use go install instead of go build, then it doesn't matter if you're
building one at time or building everything together. The shared code will
only be built once.
I think a lot of problems come from the overuse of "go build" where "go
install" should be used instead.
|
@minux There are times when I want the functionality of "go install", but placed into a local folder.
The above may come up more often for me then others as I work on a contract basis and juggle different customers accounts. I use a single GOPATH, but often architect projects to run within a non-global context. (Sorry, that might not make complete sense). |
This is so close to working. I'm not sure why it doesn't. We should fix it for Go 1.12.
|
You could imagine -o or a variant specifying a directory rather than or as well as a file. |
This isn't exactly a necessity, but it would be a huge convenience in my workflow - not to mention it would bring it in line with the install command. I never looked this up in the go docs. I just assumed it would work, but it doesn't 😞 I have a few projects with numerous small tools/utils and it would greatly simplify my testing if I could build them all at once to my cwd. Currently I have a bash script that runs consecutive |
Same here, we do most of our local dev on mac but than build and package for our standard linux image so have have similar problems since the This works for now but would prefer a |
Change https://golang.org/cl/143139 mentions this issue: |
One side effect of this CL is that it breaks the venerable "go build -a std cmd" for Go maintainers (when run from $GOROOT/src, it will complain that "go" is already a directory; when run from any different directory, it will drop many binaries in it). The current workaround is "go build -o /dev/null -a std cmd". |
There is a bit of discussion on the proposed CL, as well s the comment that the CL as implemented breaks I would make the following proposal: Make In the CL there are comments that suggest either: Sometimes it would be really useful to install a bunch of commands into a specific directory. Most of the semantics are already defined. |
Another option is to add an explicit -dryrun option (or similar name) to avoid writing binaries; similar to the undocumented -o /dev/null but more explicit. This would help those who want to “just test it compiles”, in an explicit way. Then, building multiple executables would just work, by default. This would make the behavior of go build more consistent; by default, it would always build executables, rather than changing behavior depending on how many packages were specified. It would be easier to explain and document, and less surprising for beginners. |
Ping, can we get this unstuck? It just needs a decision on a small detail, we all want the main feature in. |
|
@kardianos In module mode, it may be useful to issue a |
@bcmills Thank you for working on defining how
Can you explain why you would need to pass in |
We may all want this "in", but it's too late for Go 1.12. |
This is very sad. It is the second release that this feature is postponed because the community doesn't get answers from the Go team regarding it in time for the release cycle (see also #23616 where I didn't get an answer for months). I have even sent a CL well in time, to try to unblock things. How can we break this cycle? Is there a better channel than this? The community can't do development for things we care about if the Go team doesn't even prioritize answering to questions. /cc @andybons @bradfitz @bcmills @FiloSottile @cassandraoid |
I'm sorry this one got stuck. As you know there has been a great deal of work on cmd/go last cycle and this one, and that has made looking at CLs for cmd/go even slower than usual. Also it seems that this feature interacts with modules, which makes it even worse since modules is in a steady state of flux. |
To move forward with this, let's make Separately, |
Change https://golang.org/cl/167679 mentions this issue: |
It looks like only
|
Change https://golang.org/cl/190839 mentions this issue: |
For reference, my CL 143139 did work also without |
Sorry for the scattered discussion. CL comment https://go-review.googlesource.com/c/go/+/143139/4#message-fb8adc4368e18ba081fe2fe221448bce17d990bc showed that |
Makes sense, thanks for closing the loop. |
The docs refer to "the last two paragraphs", but in fact should refer to the first two of the previous three paragraphs. Moved up the out of place paragraph. Updates #14295 Change-Id: I066da7a665bc6754d246782b941af214a385017a Reviewed-on: https://go-review.googlesource.com/c/go/+/190839 Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Change https://golang.org/cl/190907 mentions this issue: |
Fixes #33720 Updates #14295 Change-Id: I9cb6e02bcaccd7971057315163d8810157d465bd Reviewed-on: https://go-review.googlesource.com/c/go/+/190907 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
The docs refer to "the last two paragraphs", but in fact should refer to the first two of the previous three paragraphs. Moved up the out of place paragraph. Updates golang#14295 Change-Id: I066da7a665bc6754d246782b941af214a385017a Reviewed-on: https://go-review.googlesource.com/c/go/+/190839 Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Fixes golang#33720 Updates golang#14295 Change-Id: I9cb6e02bcaccd7971057315163d8810157d465bd Reviewed-on: https://go-review.googlesource.com/c/go/+/190907 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Is
Note that it does not work without |
@odiferousmint If a package is specified as a list of |
I just got 1.14 and I'm confused. This works great with regular GOOS and GOARCH on non-empty directories (nice work!):
But doesn't work with GOOS=js GOARCH=wasm:
It works great with GOOS=js GOARCH=wasm if I make a new directory:
And it works great if I rebuild into the bin directory:
Is this intended to work with non-empty parent directories of the binaries? Why does it work with GOOS=windows GOARCH=amd64 but not GOOS=js GOARCH=wasm? |
@Gregory-Ledray, please open a new issue with steps to reproduce. Probably there is something special about |
Right now there is no easy cross platform way to output multiple artifacts from multiple packages into a single directory.
Right now you can do
env GOBIN=bin/ go install cmd/...
on many platforms, but not when cross compiling or on windows.Suggesting making
go build -o bin/ pkg1 pkg2
build both packages into the "bin" folder.@robpike thinks this would make the meaning different based on if it is a file or directory and suggests using a different flag like "-odir". That seems fine however I'm not sure how -o would interact with -odir. If they were forbidden from being set at the same time, I would say they should be the same flag, namely -o.
Reference thread: https://groups.google.com/forum/#!topic/golang-dev/a1wvIZdnic0
The text was updated successfully, but these errors were encountered: