From b52a403f1cfbe2439011813f326ef8e6d73ca985 Mon Sep 17 00:00:00 2001 From: Murphy Chen Date: Thu, 15 Aug 2024 14:48:26 +0800 Subject: [PATCH 1/2] Add new make targets with ldflags to build lite version binaries --- Makefile | 16 ++++++++++++++++ Makefile.Common | 2 ++ 2 files changed, 18 insertions(+) diff --git a/Makefile b/Makefile index c033110b6ef9..1c45796c2718 100644 --- a/Makefile +++ b/Makefile @@ -330,6 +330,12 @@ otelcontribcol: cd ./cmd/otelcontribcol && GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -trimpath -o ../../bin/otelcontribcol_$(GOOS)_$(GOARCH)$(EXTENSION) \ -tags $(GO_BUILD_TAGS) . +# Build the Collector executable without the symbol table, debug information, and the DWARF symbol table. +.PHONY: otelcontribcollite +otelcontribcollite: + cd ./cmd/otelcontribcol && GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -trimpath -o ../../bin/otelcontribcol_$(GOOS)_$(GOARCH)$(EXTENSION) \ + -tags $(GO_BUILD_TAGS) -ldflags $(GO_BUILD_LDFLAGS) . + .PHONY: genoteltestbedcol genoteltestbedcol: $(BUILDER) $(BUILDER) --skip-compilation --config cmd/oteltestbedcol/builder-config.yaml --output-path cmd/oteltestbedcol @@ -341,12 +347,22 @@ oteltestbedcol: cd ./cmd/oteltestbedcol && GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -trimpath -o ../../bin/oteltestbedcol_$(GOOS)_$(GOARCH)$(EXTENSION) \ -tags $(GO_BUILD_TAGS) . +.PHONY: oteltestbedcollite +oteltestbedcollite: + cd ./cmd/oteltestbedcol && GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -trimpath -o ../../bin/oteltestbedcol_$(GOOS)_$(GOARCH)$(EXTENSION) \ + -tags $(GO_BUILD_TAGS) -ldflags $(GO_BUILD_LDFLAGS) . + # Build the telemetrygen executable. .PHONY: telemetrygen telemetrygen: cd ./cmd/telemetrygen && GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -trimpath -o ../../bin/telemetrygen_$(GOOS)_$(GOARCH)$(EXTENSION) \ -tags $(GO_BUILD_TAGS) . +.PHONY: telemetrygenlite +telemetrygenlite: + cd ./cmd/telemetrygen && GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -trimpath -o ../../bin/telemetrygen_$(GOOS)_$(GOARCH)$(EXTENSION) \ + -tags $(GO_BUILD_TAGS) -ldflags $(GO_BUILD_LDFLAGS) . + # helper function to update the core packages in builder-config.yaml # input parameters are # $(1) = path/to/versions.yaml (where it greps the relevant packages) diff --git a/Makefile.Common b/Makefile.Common index 35380f3245f5..2f26b76cd8ab 100644 --- a/Makefile.Common +++ b/Makefile.Common @@ -25,6 +25,8 @@ SRC_PARENT_DIR := $(shell dirname $(SRC_ROOT)) # build tags required by any component should be defined as an independent variables and later added to GO_BUILD_TAGS below GO_BUILD_TAGS="" +# The default ldflags allow the build tool to omit the symbol table, debug information, and the DWARF symbol table to downscale binary size. +GO_BUILD_LDFLAGS="-s -w" GOTEST_TIMEOUT?= 600s GOTEST_OPT?= -race -timeout $(GOTEST_TIMEOUT) -parallel 4 --tags=$(GO_BUILD_TAGS) GOTEST_INTEGRATION_OPT?= -race -timeout 360s -parallel 4 From 04097a9a26d4150a0ae6fbb85bd2e7ec6d0a4580 Mon Sep 17 00:00:00 2001 From: Murphy Chen Date: Sat, 31 Aug 2024 15:31:27 +0800 Subject: [PATCH 2/2] Update Makefile.Common Co-authored-by: Curtis Robert --- Makefile.Common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.Common b/Makefile.Common index 2f26b76cd8ab..639300b87755 100644 --- a/Makefile.Common +++ b/Makefile.Common @@ -25,7 +25,7 @@ SRC_PARENT_DIR := $(shell dirname $(SRC_ROOT)) # build tags required by any component should be defined as an independent variables and later added to GO_BUILD_TAGS below GO_BUILD_TAGS="" -# The default ldflags allow the build tool to omit the symbol table, debug information, and the DWARF symbol table to downscale binary size. +# These ldflags allow the build tool to omit the symbol table, debug information, and the DWARF symbol table to downscale binary size. GO_BUILD_LDFLAGS="-s -w" GOTEST_TIMEOUT?= 600s GOTEST_OPT?= -race -timeout $(GOTEST_TIMEOUT) -parallel 4 --tags=$(GO_BUILD_TAGS)