go build -o bin/ cmd/...

7,441 views
Skip to first unread message

Daniel Theophanes

unread,
Feb 10, 2016, 2:28:55 PM2/10/16
to golang-dev
I'd like to float a suggestion for the go1.7 timeframe.

Right now "go build -o mymain cmd/mymain" builds a single package and outputs it to the path specified by  "-o". I propose modifying that slightly so that if the value of -o is a directory, it will output using the standard name in that directory, allowing multiple packages to be specified at once.

The following except from "go help build":
The -o flag, only allowed when compiling a single package,
forces build to write the resulting executable or object
to the named output file, instead of the default behavior described
in the last two paragraphs.

would be modified to read as:
The -o flag, forces build to write the resulting executable or object
to the named output file. If named output is a directory, build allows
compiling multiple packages into the named output directory.

I could then use it to install multiple commands into a local bin (tool) directory for builds, say:
go build -o bin/ cmd/...

Thoughts?

gugl.z...@gmail.com

unread,
Feb 10, 2016, 2:45:45 PM2/10/16
to golang-dev
You can do it with go install and GOBIN environment variable actually:

env GOBIN=bin go install cmd/...

Brad Fitzpatrick

unread,
Feb 10, 2016, 4:21:19 PM2/10/16
to Ainar Garipov, golang-dev
That doesn't work when cross-compiling, though. I never investigated why.


--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Theophanes

unread,
Feb 10, 2016, 4:24:47 PM2/10/16
to golang-dev, gugl.z...@gmail.com
This is true, and a fair comment.
However, on windows there is no easy way to set an environment variable for just one command.

Rob Pike

unread,
Feb 10, 2016, 4:34:18 PM2/10/16
to Daniel Theophanes, golang-dev, gugl.z...@gmail.com
In any case, making -o mean two different things depending on the type of the file it names is a poor design. If you want to pursue this, please file an issue but suggest a different flag for this, perhaps -odir.

-rob


Ian Lance Taylor

unread,
Feb 10, 2016, 4:41:09 PM2/10/16
to Brad Fitzpatrick, Ainar Garipov, golang-dev
On Wed, Feb 10, 2016 at 1:21 PM, Brad Fitzpatrick <brad...@golang.org> wrote:
> That doesn't work when cross-compiling, though. I never investigated why.

https://golang.org/issue/9769

Ian

Daniel Theophanes

unread,
Feb 10, 2016, 5:11:32 PM2/10/16
to golang-dev
filed https://golang.org/issue/14295

If this is agreed to I can send a CL.

Reply all
Reply to author
Forward
0 new messages