-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
Proposal Details
why
When we go install a pkg, we could not get the vcs info from runtime/debug.BuildSetting
So we could not get the binary version that installed from go install:
➜ git:(master) go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@cc70731
go: downloading github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.1-0.20240523165541-cc70731f9bd2
➜ git:(master) protoc-gen-grpc-gateway --version
commit unknown, built at unknownAnd it is how the code does:
if commit == "unknown" {
buildInfo, ok := debug.ReadBuildInfo()
if ok {
for _, setting := range buildInfo.Settings {
if setting.Key == "vcs.revision" {
commit = setting.Value
}
if setting.Key == "vcs.time" {
date = setting.Value
}
}
fmt.Printf("commit %v, built at %v\n", commit, date)
os.Exit(0)
}
}It would be nice if we could embed the vcs info and build time into the binary, so we could get the version and build time when installed from go install
Please refer to this issue for more detail
How
I am still not sure if it could work but I would try later.
This is part of stack trace when we run go install:
installOutsideModule
PackagesAndErrorsOutsideModule
PackagesAndErrors
loadImport
load
setBuildInfo
I wonder if we could update this opt
in installOutsideModulefrom
pkgOpts := load.PackageOpts{MainOnly: true}to
pkgOpts := load.PackageOpts{MainOnly: true, AutoVCS: true}so that this piece of code could embed the vcs info into BuildInfo
And maybe it will be nice if we could have a build time in runtime/debug.BuildInfo as well.
If this proposal is accepted I would try to make a PR for it.
yours sincerely.