From bf241ce77e838ec714a3b40be3c66cfd225f3e93 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 16 Dec 2018 20:39:01 +0100 Subject: build.bash: use -trimpath for reproducible builds Support both Go 1.7...1.9 and Go 1.10 by checking the version and using the appropropriate syntax. We trim GOPATH/src and use both -gcflags and -asmflags like Debian does in https://salsa.debian.org/go-team/packages/dh-golang/blob/ab2bbcfc00b1229066cc3d3d1195ac901a2b9411/lib/Debian/Debhelper/Buildsystem/golang.pm#L465 . --- build.bash | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/build.bash b/build.bash index a8a0d60..900010c 100755 --- a/build.bash +++ b/build.bash @@ -64,11 +64,24 @@ if [[ -n ${SOURCE_DATE_EPOCH:-} ]] ; then BUILDDATE=$(date --utc --date="@${SOURCE_DATE_EPOCH}" +%Y-%m-%d) fi +# For reproducible builds, we get rid of $HOME references in the binary +# using "-trimpath". +# Note: we have to set both -gcflags and -asmflags because otherwise +# "$HOME/go/src/golang.org/x/sys/unix/asm_linux_amd64.s" stays in the binary. +GV=$(go version) +if [[ $GV == *"1.7"* ]] || [[ $GV == *"1.8"* ]] || [[ $GV == *"1.9"* ]] ; then + TRIM="-trimpath=${GOPATH1}/src" +else + # Go 1.10 changed the syntax. You now have to prefix "all=" to affect + # all compiled packages. + TRIM="all=-trimpath=${GOPATH1}/src" +fi + LDFLAGS="-X main.GitVersion=$GITVERSION -X main.GitVersionFuse=$GITVERSIONFUSE -X main.BuildDate=$BUILDDATE" -go build "-ldflags=$LDFLAGS" "$@" +go build "-ldflags=$LDFLAGS" "-gcflags=$TRIM" "-asmflags=$TRIM" "$@" -(cd gocryptfs-xray; go build "$@") +(cd gocryptfs-xray; go build "-gcflags=$TRIM" "-asmflags=$TRIM" "$@") ./gocryptfs -version -- cgit v1.2.3