// Note that the GoVersion field is not set here to avoid encoding it twice.
// It is stored separately in the binary, mostly for historical reasons.
func (p *Package) setBuildInfo() {
+ // TODO: build and vcs information is not embedded for executables in GOROOT.
+ // cmd/dist uses -gcflags=all= -ldflags=all= by default, which means these
+ // executables always appear stale unless the user sets the same flags.
+ // Perhaps it's safe to omit those flags when GO_GCFLAGS and GO_LDFLAGS
+ // are not set?
setPkgErrorf := func(format string, args ...interface{}) {
if p.Error == nil {
p.Error = &PackageError{Err: fmt.Errorf(format, args...)}
// Add command-line flags relevant to the build.
// This is informational, not an exhaustive list.
- if cfg.BuildBuildinfo {
+ if cfg.BuildBuildinfo && !p.Standard {
appendSetting("compiler", cfg.BuildContext.Compiler)
if BuildAsmflags.present {
appendSetting("asmflags", BuildAsmflags.String())
var repoDir string
var vcsCmd *vcs.Cmd
var err error
- if cfg.BuildBuildvcs && p.Module != nil && p.Module.Version == "" {
+ if cfg.BuildBuildvcs && p.Module != nil && p.Module.Version == "" && !p.Standard {
repoDir, vcsCmd, err = vcs.FromDir(base.Cwd(), "")
if err != nil && !errors.Is(err, os.ErrNotExist) {
setVCSError(err)