mirror of
https://github.com/pgsty/minio.git
synced 2026-08-09 15:53:28 +03:00
build: stop stamping the build machine's GOPATH/GOROOT into the binary
gen-ldflags injected -X cmd.GOPATH / cmd.GOROOT from the builder's environment, baking absolute paths like /Users/<user>/go into every released binary. That defeats -trimpath and makes the build unreproducible: a third party rebuilding the same tag gets different bytes and cannot verify checksums.txt. The values only seed logger.Init's source-path trim list, and under -trimpath the binary's paths are already relative, so there is no build-machine prefix left to trim - the trim list also still gets runtime.GOROOT() and build.Default.GOPATH at run time. Dropping the two stamps changes no observable logging behaviour; cmd.GOPATH/GOROOT keep the empty defaults a plain go build leaves. Verified: gen-ldflags output no longer contains cmd.GOPATH/GOROOT; a -trimpath release build has zero occurrences of the builder path (was 1); Version, ReleaseTag and CommitID stamps are intact. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -38,8 +38,12 @@ func genLDFlags(version string) string {
|
|||||||
ldflagsStr += " -X github.com/minio/minio/cmd.ReleaseTag=" + releaseTag
|
ldflagsStr += " -X github.com/minio/minio/cmd.ReleaseTag=" + releaseTag
|
||||||
ldflagsStr += " -X github.com/minio/minio/cmd.CommitID=" + commitID()
|
ldflagsStr += " -X github.com/minio/minio/cmd.CommitID=" + commitID()
|
||||||
ldflagsStr += " -X github.com/minio/minio/cmd.ShortCommitID=" + commitID()[:12]
|
ldflagsStr += " -X github.com/minio/minio/cmd.ShortCommitID=" + commitID()[:12]
|
||||||
ldflagsStr += " -X github.com/minio/minio/cmd.GOPATH=" + os.Getenv("GOPATH")
|
// GOPATH/GOROOT are deliberately not stamped in. They only seed the logger's
|
||||||
ldflagsStr += " -X github.com/minio/minio/cmd.GOROOT=" + os.Getenv("GOROOT")
|
// source-path trim list, which -trimpath already makes moot (paths are
|
||||||
|
// relative in the binary, so there is no build-machine prefix left to trim),
|
||||||
|
// and stamping them baked the builder's absolute paths into the released
|
||||||
|
// binary - defeating -trimpath and reproducible builds. cmd.GOPATH/GOROOT
|
||||||
|
// keep their empty defaults, exactly as a plain `go build` leaves them.
|
||||||
return ldflagsStr
|
return ldflagsStr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user