Go version
go version go1.25rc2 darwin/arm64
Output of go env
in your module/workspace:
(not relevant)
What did you do?
I noticed a regression in a particular edge case of the -buildvcs
behavior.
Consider the following minimal sequence that reproduces it:
$ cd $(mktemp -d)
$ mkdir subdir
$ (cd subdir && go mod init example.com/subdir && go get go@1.24.0)
$ echo 'package main; import ("fmt"; "log"; "runtime/debug"); func main() { bi, ok := debug.ReadBuildInfo(); if !ok { log.Fatalln("no build info") }; fmt.Println(bi.Main.Version) }' > subdir/main.go
$ git init && git add . && git commit -m 'example commit'
$ cd subdir
$ GOTOOLCHAIN=go1.24.5 go run -buildvcs=true .
v0.0.0-20250726003140-f31775ad565e
$ GOTOOLCHAIN=go1.25rc2 go run -buildvcs=true .
(devel)
What did you see happen?
As visible above, when using Go 1.25 the reported main module version is "(devel)" despite -buildvcs=true and the example.com/subdir module being inside a git repository.
What did you expect to see?
As visible above, when using Go 1.24 the reported main module version is "v0.0.0-20250726003140-f31775ad565e". I expected Go 1.25 to report the same version.
Comment From: dmitshur
The issue appears to reproduce whenever the repository root doesn't have a go.mod file. From a quick look, the relevant change is likely CL 661875 (CC @samthanawalla) given it adds:
rootModPath := goModPath(repoDir)
// If no root module is found, skip embedding VCS data since we cannot determine the module path of the root.
if rootModPath == "" {
goto omitVCS
}
It is possible for a repository to have nested modules (with their own go.mod files) and no go.mod file at the repo root, and it seemingly worked in Go 1.24. That said, I expect this is more of a rare edge case rather than a common situation.
CC @golang/command-line.
Comment From: gabyhelp
Related Issues
- In multi-module Git repos, local Go compilations stamp the wrong main module version for main packages that are in a non-root Go module #74412 (closed)
- cmd/go: local version stamping doesn't work with v2+ #72877 (closed)
- cmd/go: stamped (pseudo) version on build does not work for module in subdirectory #71738 (closed)
- cmd/go: unknown revision when using semver tag for module in subdirectory #31045 (closed)
- buildvcs regression in 1.24 breaks security scanners with versions not previously seen, and no way to build binaries with same buildinfo as it was in 1.23 #71969 (closed)
- cmd/go: binary does not contain VCS information when compiled in git worktree dir #58218
- cmd/go build does not append +dirty #71684 (closed)
- cmd/go: `go build` fails to read vcs info from isolated git submodule #53640 (closed)
- cmd/go: use version control to discover the main module's version? #29814 (closed)
- cmd/go: VCS stamping complains inappropriately about VCS in unreleated parent directory #49004 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)