Skip to content

Commit f3f823c

Browse files
authored
Merge pull request #7002 from thaJeztah/smaller_size
scripts/build: set grpcnotrace build-tag to reduce binary size
2 parents 02e2c2e + 45fc3b0 commit f3f823c

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

scripts/build/.variables

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ fi
9898
if [ "$CGO_ENABLED" = "1" ] && [ "$GO_LINKMODE" = "static" ] && [ "$(go env GOOS)" = "linux" ]; then
9999
GO_LDFLAGS="$GO_LDFLAGS -linkmode external -extldflags -static"
100100
fi
101+
102+
# We only import google.golang.org/grpc as an indirect dependency, and
103+
# do not make gRPC connections.
104+
#
105+
# grpcnotrace avoids importing golang.org/x/net/trace, which in turn enables
106+
# dead code elimination, which can reduce binary size when tracing is not needed.
107+
#
108+
# see https://github.com/grpc/grpc-go/blob/v1.81.1/trace_notrace.go#L23-L25
109+
GO_BUILDTAGS="$GO_BUILDTAGS grpcnotrace"
110+
101111
if [ "$CGO_ENABLED" = "1" ] && [ "$GO_LINKMODE" = "static" ]; then
102112
# compiling statically with CGO enabled requires osusergo and netgo to be set.
103113
GO_BUILDTAGS="$GO_BUILDTAGS osusergo netgo"

0 commit comments

Comments
 (0)