-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Description
$ go version
go version go1.26-devel_320df537cc 2025-08-13 20:33:56 -0700 linux/amd64
Using https://github.com/cue-lang/cue as an example, where cmd/cue
is a main program which reports the main module's version as the first line of its cue version
command, the stamping works fine with go install
and go build
:
$ go install ./cmd/cue && cue version | sed 1q
cue version v0.15.0-0.dev.0.20250815110336-a2eed3278a6c
$ go build -o cue-build ./cmd/cue && ./cue-build version | sed 1q && rm cue-build
cue version v0.15.0-0.dev.0.20250815110336-a2eed3278a6c
With go run
it doesn't work by default, which is surprising and a bit inconsistent. We can however enable it explicitly.
$ go run ./cmd/cue version | sed 1q
cue version (devel)
$ go run -buildvcs=true ./cmd/cue version | sed 1q
cue version v0.15.0-0.dev.0.20250815110336-a2eed3278a6c
With go tool
it also doesn't work by default, and on top of that, we can't enable it in any way:
$ go tool cue version | sed 1q
cue version (devel)
$ go tool -buidlvcs=true cue version | sed 1q
flag provided but not defined: -buidlvcs
What's weird is that the "auto" mode (the default) seems to be broken with go run
:
$ go run -buildvcs=auto ./cmd/cue version | sed 1q
cue version (devel)
The docs say:
By default ("auto"), version control information is stamped into a binary if the main package, the main module containing it, and the current directory are all in the same repository.
It seems pretty clear to me that I'm meeting those requirements with go run ./cmd/cue
, so I don't understand why the auto-stamping is not working.
So it seems to me like go run
and go tool
should apply the -buildvcs=auto
default such that version stamping takes place.
It may also be a good idea for go tool
to expose the -buildvcs
build flag, so that one can explicitly turn it on or off if needed like with the other commands. But I don't feel strongly about it.