Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmd] Add new make targets with ldflags to build lite version binaries #34698

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) .
Comment on lines +335 to +337
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of repetition between otelcontribcol and otelcontribcollight targets. Perhaps it could be improved into something like:

Suggested change
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) .
otelcontribcollite:
GO_BUILD_LDFLAGS="-s -w" $(MAKE) otelcontribcol


.PHONY: genoteltestbedcol
genoteltestbedcol: $(BUILDER)
$(BUILDER) --skip-compilation --config cmd/oteltestbedcol/builder-config.yaml --output-path cmd/oteltestbedcol
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Makefile.Common
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
# 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)
GOTEST_INTEGRATION_OPT?= -race -timeout 360s -parallel 4
Expand Down