From c26dabacbd5e43f4fda6a813a4d8a34808a0ec0a Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Wed, 22 Dec 2021 09:59:40 +0100 Subject: [PATCH] release: build with consistent paths This changes the builds to always add -trimpath which removes specific build time paths from the binary (like current directories etc). Improves build reproducability to make the final binary independent from the specific build path. Lastly, when stripping debug symbols, also add -w to strip DWARF symbols as well which aren't needed in that case either. Signed-off-by: Dirkjan Bussink --- scripts/build-binary.sh | 2 +- scripts/build_lib.sh | 4 ++++ tests/functional/build.sh | 8 ++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/build-binary.sh b/scripts/build-binary.sh index ff42270a0..ef07c7584 100755 --- a/scripts/build-binary.sh +++ b/scripts/build-binary.sh @@ -87,7 +87,7 @@ function main { export GOARCH=${TARGET_ARCH} pushd etcd >/dev/null - GO_LDFLAGS="-s" ./scripts/build.sh + GO_LDFLAGS="-s -w" ./scripts/build.sh popd >/dev/null TARGET="etcd-${VER}-${GOOS}-${GOARCH}" diff --git a/scripts/build_lib.sh b/scripts/build_lib.sh index 5d33c932f..be5fa4bd4 100755 --- a/scripts/build_lib.sh +++ b/scripts/build_lib.sh @@ -60,6 +60,7 @@ etcd_build() { # Static compilation is useful when etcd is run in a container. $GO_BUILD_FLAGS is OK # shellcheck disable=SC2086 run env "${GO_BUILD_ENV[@]}" go build $GO_BUILD_FLAGS \ + -trimpath \ -installsuffix=cgo \ "-ldflags=${GO_LDFLAGS[*]}" \ -o="../${out}/etcd" . || return 2 @@ -70,6 +71,7 @@ etcd_build() { ( cd ./etcdutl run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS}" "${GO_BUILD_ENV[@]}" go build $GO_BUILD_FLAGS \ + -trimpath \ -installsuffix=cgo \ "-ldflags=${GO_LDFLAGS[*]}" \ -o="../${out}/etcdutl" . || return 2 @@ -80,6 +82,7 @@ etcd_build() { ( cd ./etcdctl run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS}" "${GO_BUILD_ENV[@]}" go build $GO_BUILD_FLAGS \ + -trimpath \ -installsuffix=cgo \ "-ldflags=${GO_LDFLAGS[*]}" \ -o="../${out}/etcdctl" . || return 2 @@ -110,6 +113,7 @@ tools_build() { run rm -f "${out}/${tool}" # shellcheck disable=SC2086 run env GO_BUILD_FLAGS="${GO_BUILD_FLAGS}" CGO_ENABLED=0 go build ${GO_BUILD_FLAGS} \ + -trimpath \ -installsuffix=cgo \ "-ldflags=${GO_LDFLAGS[*]}" \ -o="${out}/${tool}" "./${tool}" || return 2 diff --git a/tests/functional/build.sh b/tests/functional/build.sh index a354c3bca..1c28b6d9a 100755 --- a/tests/functional/build.sh +++ b/tests/functional/build.sh @@ -9,8 +9,8 @@ outdir="${BINDIR:-../bin}" ( cd ./tests - CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s" -o "${outdir}/etcd-agent" ./functional/cmd/etcd-agent - CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s" -o "${outdir}/etcd-proxy" ./functional/cmd/etcd-proxy - CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s" -o "${outdir}/etcd-runner" ./functional/cmd/etcd-runner - CGO_ENABLED=0 go test -v -installsuffix cgo -ldflags "-s" -c -o "${outdir}/etcd-tester" ./functional/cmd/etcd-tester + CGO_ENABLED=0 go build -trimpath -v -installsuffix cgo -ldflags "-s -w" -o "${outdir}/etcd-agent" ./functional/cmd/etcd-agent + CGO_ENABLED=0 go build -trimpath -v -installsuffix cgo -ldflags "-s -w" -o "${outdir}/etcd-proxy" ./functional/cmd/etcd-proxy + CGO_ENABLED=0 go build -trimpath -v -installsuffix cgo -ldflags "-s -w" -o "${outdir}/etcd-runner" ./functional/cmd/etcd-runner + CGO_ENABLED=0 go test -v -installsuffix cgo -ldflags "-s -w" -c -o "${outdir}/etcd-tester" ./functional/cmd/etcd-tester )