Skip to content

Commit a727de1

Browse files
authored
Silence linker warnings on build and test (#3615)
1 parent 35d4aae commit a727de1

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:v$(GOLANG_VERSION)
2121
GOBIN := $(shell go env GOPATH)/bin
2222
GIT_COMMIT := $(shell git rev-parse --short HEAD)
2323

24+
LDFLAGS := -ldflags "-X github.com/GoogleContainerTools/kpt/run.version=${GIT_COMMIT}
25+
ifeq ($(OS),Windows_NT)
26+
# Do nothing
27+
else
28+
UNAME := $(shell uname -s)
29+
ifeq ($(UNAME),Linux)
30+
LDFLAGS += -extldflags '-z noexecstack'
31+
endif
32+
endif
33+
LDFLAGS += "
34+
2435
# T refers to an e2e test case matcher. This enables running e2e tests
2536
# selectively. For example,
2637
# To invoke e2e tests related to fnconfig, run:
@@ -32,7 +43,7 @@ T ?= ".*"
3243
all: generate license fix vet fmt lint license-check test build tidy
3344

3445
build:
35-
go build -ldflags "-X github.com/GoogleContainerTools/kpt/run.version=${GIT_COMMIT}" -o $(GOBIN)/kpt -v .
46+
go build ${LDFLAGS} -o $(GOBIN)/kpt -v .
3647

3748
update-deps-to-head:
3849
go get sigs.k8s.io/cli-utils@master
@@ -90,7 +101,7 @@ license-check: install-go-licenses
90101
$(GOBIN)/go-licenses check github.com/GoogleContainerTools/kpt
91102

92103
test:
93-
go test -cover ./...
104+
go test -cover ${LDFLAGS} ./...
94105

95106
# This target is used to run Go tests that require docker runtime.
96107
# Some tests, like pipeline tests, need to have docker available to run.

release/tag/goreleaser.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ builds:
5151
env:
5252
- CC=x86_64-linux-gnu-gcc
5353
- CXX=x86_64-linux-gnu-g++
54-
ldflags: -s -w -X github.com/GoogleContainerTools/kpt/run.version={{.Version}} -linkmode external -extldflags "-static"
54+
ldflags: -s -w -X github.com/GoogleContainerTools/kpt/run.version={{.Version}} -linkmode external -extldflags "-static -z noexecstack"
5555

5656
- id: linux-arm64
5757
goos:
@@ -61,7 +61,7 @@ builds:
6161
env:
6262
- CC=aarch64-linux-gnu-gcc
6363
- CXX=aarch64-linux-gnu-g++
64-
ldflags: -s -w -X github.com/GoogleContainerTools/kpt/run.version={{.Version}} -linkmode external -extldflags "-static"
64+
ldflags: -s -w -X github.com/GoogleContainerTools/kpt/run.version={{.Version}} -linkmode external -extldflags "-static -z noexecstack"
6565

6666
dockers:
6767
- ids:

0 commit comments

Comments
 (0)