Closed mgabeler-lee-6rs closed 2 years ago
Presumably this is (unintentional) fallout from #51723 and/or #51748
The backport for -buildvcs=auto
is still open, so that's not expected to work yet #51798
cc @bcmills @matloob
go run
intentionally should not stamp VCS metadata. It has a nonzero latency cost and essentially zero benefit; the fact that it happened to stamp the binary in Go 1.18 was a bug missed during pre-release testing.
go run
may be used with or without an explicit version.
go run
does not result in a binary to be stored and shipped separately from the VCS and the go run
command must have occurred within the repository.@bcmills I ask you reconsider for the following context/reasons:
go run .
has VCS data availablego run
is never going to stamp VCS data, then it should report an error if you invoke it as go run -buildvcs=true
. Currently it accepts this flag but silently ignores it.I'm in the same boat as @mgabeler-lee-6rs I believe. I'm using this interface as part of a web API which dumps version info on errors to aid in debugging. As of go1.18.1, this stopped working with go run
. Right now, I wasn't able to figure out a workaround other than special casing this (i.e. "if run with go run
, don't expect vcs.*
to be present; otherwise present this information").
While I definitely agree that buildvcs=false
is a great default for go run
, lack of support for buildvcs=true
means that a program that works with go build && ./program
doesn't work with go run
, which breaks my understanding of how go run
should work (basically, identically to go build && ./program
).
The docs seem to support my confusion (from https://pkg.go.dev/cmd/go, emphasis mine):
The build flags are shared by the build, clean, get, install, list, run, and test commands:
-buildvcs Whether to stamp binaries with version control information. By default, version control information is stamped into a binary if the main package and the main module containing it are in the repository containing the current directory (if there is a repository). Use -buildvcs=false to omit version control information.
It's entirely likely that I'm misunderstanding how go run
is supposed to work, though -- if you can help me understand a better way to do what I'm trying to do here, such that I don't have to special case running the program with go run
, I'd be appreciative!
I am also having a lot of trouble getting go build -buildvcs=true
to embed anything but (devel)
as the version string for our internal included package, and the buildinfo.Settings including nothing but this:
-compiler = gcSetting CGO_ENABLED = 1Setting CGO_CFLAGS = Setting CGO_CPPFLAGS = Setting CGO_CXXFLAGS = Setting CGO_LDFLAGS = Setting GOARCH = amd64Setting GOOS = linuxSetting GOAMD64 = v1Dep github.com/PuerkitoBio/purell = v1.1.1
The documentation for BuildInfo is laughably sparse, and there is no indication how to add entries to Settings nor how to modulate the version strings embedded in the executable for the main program.
Maybe all of that info comes from what should be obvious places to those more familiar with go's package system than I am, but I have had no luck getting go build
to embed anything useful when building inside a committed git repo.
Let's say you require a package in go.mod...
module mymodule
require github.com/gopherjs/gopherjs latest
And then you run it with go run...
go mod tidy
go run github.com/gopherjs/gopherjs -- build ./
Let's say we want to use debug.ReadBuildInfo
in the GopherJS compiler to determine the version & mod sum for gopherjs from go.mod
used when we ran go run
.
This is a situation where -buildvcs=true with go run makes sense.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Attempting to extract VCS info from
debug.ReadBuildInfo()
when running undergo run
.go mod init example
main.go
git add . && git commit -m 'example'
go run .
What did you expect to see?
With go 1.18.0, I get:
What did you see instead?
With go 1.18.1:
Even worse,
-buildvcs=auto
is not recognized:Even even worse,
-buildvcs=true
is ignored: