Skip to content

Commit

Permalink
release: build with consistent paths
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dbussink authored and serathius committed Nov 21, 2022
1 parent 7ccca08 commit 1a9742c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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
Expand All @@ -52,6 +53,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
Expand All @@ -62,6 +64,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
Expand Down Expand Up @@ -92,6 +95,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
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-binary
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function main {
export GOARCH=${TARGET_ARCH}

pushd etcd >/dev/null
GO_LDFLAGS="-s" ./build.sh
GO_LDFLAGS="-s -w" ./build.sh
popd >/dev/null

TARGET="etcd-${VER}-${GOOS}-${GOARCH}"
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/build
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ fi

(
cd ./tests
CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s" -o ../bin/etcd-agent ./functional/cmd/etcd-agent
CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s" -o ../bin/etcd-proxy ./functional/cmd/etcd-proxy
CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s" -o ../bin/etcd-runner ./functional/cmd/etcd-runner
CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s" -o ../bin/etcd-tester ./functional/cmd/etcd-tester
CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s -w" -o ../bin/etcd-agent ./functional/cmd/etcd-agent
CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s -w" -o ../bin/etcd-proxy ./functional/cmd/etcd-proxy
CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s -w" -o ../bin/etcd-runner ./functional/cmd/etcd-runner
CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s -w" -o ../bin/etcd-tester ./functional/cmd/etcd-tester
)

0 comments on commit 1a9742c

Please sign in to comment.