diff options
author | Jakob Unterwurzacher | 2018-12-16 20:39:01 +0100 |
---|---|---|
committer | Jakob Unterwurzacher | 2018-12-16 20:39:01 +0100 |
commit | bf241ce77e838ec714a3b40be3c66cfd225f3e93 (patch) | |
tree | 18152b703038445659a4e24909ae099957dca432 /build.bash | |
parent | d32c1492664645078801d81fbfd7f8b7a469bcc5 (diff) |
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 .
Diffstat (limited to 'build.bash')
-rwxr-xr-x | build.bash | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -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 |