Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build script to use GOFLAGS and CGO_LDFLAGS #460

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,15 @@ 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

export GOFLAGS="${GOFLAGS:--buildmode=pie -trimpath}"
export CGO_LDFLAGS="${CGO_LDFLAGS:-${LDFLAGS:-}}"
GO_LDFLAGS="-X main.GitVersion=$GITVERSION -X main.GitVersionFuse=$GITVERSIONFUSE -X main.BuildDate=$BUILDDATE"

# If LDFLAGS is set, add it as "-extldflags".
if [[ -n ${LDFLAGS:-} ]] ; then
GO_LDFLAGS="$GO_LDFLAGS \"-extldflags=$LDFLAGS\""
fi

# Actual "go build" call for gocryptfs
go build "-ldflags=$GO_LDFLAGS" "-gcflags=$TRIM" "-asmflags=$TRIM" "$@"
go build "-ldflags=$GO_LDFLAGS" "$@"
# Additional binaries
(cd gocryptfs-xray; go build "-ldflags=$GO_LDFLAGS" "-gcflags=$TRIM" "-asmflags=$TRIM" "$@")
(cd contrib/statfs; go build "-ldflags=$GO_LDFLAGS" "-gcflags=$TRIM" "-asmflags=$TRIM" "$@")
(cd gocryptfs-xray; go build "-ldflags=$GO_LDFLAGS" "$@")
(cd contrib/statfs; go build "-ldflags=$GO_LDFLAGS" "$@")

./gocryptfs -version

Expand Down