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: Since 1.18.1, go run always uses -buildvcs=false #52338

Closed
mgabeler-lee-6rs opened this issue Apr 13, 2022 · 7 comments
Closed

cmd/go: Since 1.18.1, go run always uses -buildvcs=false #52338

mgabeler-lee-6rs opened this issue Apr 13, 2022 · 7 comments
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mgabeler-lee-6rs
Copy link

mgabeler-lee-6rs commented Apr 13, 2022

What version of Go are you using (go version)?

$ go version
go version go1.18.1 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/circleci/.cache/go-build"
GOENV="/home/circleci/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/circleci/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/circleci/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="0"
GOMOD="/home/circleci/project/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2409035375=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Attempting to extract VCS info from debug.ReadBuildInfo() when running under go run.

  1. https://go.dev/play/p/_09ZOz1UlC7
  2. Create a new directory
  3. go mod init example
  4. Save the playground code as main.go
  5. git add . && git commit -m 'example'
  6. go run .

What did you expect to see?

With go 1.18.0, I get:

$ go run . 
-compiler gc
CGO_ENABLED 1
CGO_CFLAGS 
CGO_CPPFLAGS 
CGO_CXXFLAGS 
CGO_LDFLAGS 
GOARCH amd64
GOOS linux
GOAMD64 v1
vcs git
vcs.revision 3905f8828680bce9d913660e098c704687ec309b
vcs.time 2022-04-13T20:07:46Z
vcs.modified false

What did you see instead?

With go 1.18.1:

$ go run . 
-compiler gc
CGO_ENABLED 0
GOARCH amd64
GOOS linux
GOAMD64 v1

Even worse, -buildvcs=auto is not recognized:

$ go run -buildvcs=auto .
invalid boolean value "auto" for -buildvcs: parse error
usage: go run [build flags] [-exec xprog] package [arguments...]
Run 'go help run' for details.

Even even worse, -buildvcs=true is ignored:

$ go run -buildvcs=true .
-compiler gc
CGO_ENABLED 0
GOARCH amd64
GOOS linux
GOAMD64 v1
@mgabeler-lee-6rs
Copy link
Author

Presumably this is (unintentional) fallout from #51723 and/or #51748

@seankhliao seankhliao changed the title cmd/go: Since 1.18.1, go run always uses -buildvcs=false, rejects auto, ignores true cmd/go: Since 1.18.1, go run always uses -buildvcs=false Apr 13, 2022
@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Apr 13, 2022
@seankhliao
Copy link
Member

The backport for -buildvcs=auto is still open, so that's not expected to work yet #51798

cc @bcmills @matloob

@bcmills
Copy link
Contributor

bcmills commented Apr 20, 2022

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.

  • With an explicit version, there is no applicable VCS containing the package anyway.
  • Without an explicit version, the VCS metadata can be recovered by running the VCS tool manually, since (by definition) 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 bcmills added this to the Unplanned milestone Apr 20, 2022
@bcmills bcmills closed this as completed Apr 20, 2022
@mgabeler-lee-6rs
Copy link
Author

@bcmills I ask you reconsider for the following context/reasons:

  1. The use case of go run . has VCS data available
  2. At the very least, if go 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.

earthboundkid added a commit to earthboundkid/versioninfo that referenced this issue May 2, 2022
earthboundkid added a commit to earthboundkid/versioninfo that referenced this issue May 2, 2022
earthboundkid added a commit to earthboundkid/versioninfo that referenced this issue May 2, 2022
earthboundkid added a commit to earthboundkid/versioninfo that referenced this issue May 2, 2022
@ChandlerSwift
Copy link

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!

@aathan
Copy link

aathan commented Oct 20, 2022

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.

@paralin
Copy link
Contributor

paralin commented Nov 12, 2022

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants