"When compiling a single main package, build writes the resulting executable to an output file named after the first source file ('go build ed.go rx.go' writes 'ed' or 'ed.exe') or the source code directory ('go build unix/sam' writes 'sam' or 'sam.exe'). The '.exe' suffix is added when writing a Windows executable.
When compiling multiple packages or a single non-main package, build compiles the packages but discards the resulting object, serving only as a check that the packages can be built.
The -o flag forces build to write the resulting executable or object to the named output file or directory, instead of the default behavior described in the last two paragraphs."
I agree with the OP: it would be less surprising if "go build ./..." always did build and store the artefacts, and there were a separate flag to discard them.Currently, "go build ./..." discards the build artefacts under certain conditions, see this example.
And I notice only now that you can do `go build -o "" ./...`.
On Tuesday, 20 April 2021 at 20:28:56 UTC+1 manlio....@gmail.com wrote:And I notice only now that you can do `go build -o "" ./...`.But does that work? See https://github.com/golang/go/blob/master/src/cmd/go/internal/work/build.go#L374-L377
> [...]