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

Add slim Go module without gRPC dependencies #155

Merged
merged 11 commits into from
Mar 11, 2024
45 changes: 38 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ ifeq ($(strip $(SUBMODULE_PROTO_FILES)),)
$(error Submodule at $(OTEL_PROTO_SUBMODULE) is not checked out, use "git submodule update --init")
endif

GO := go
PROTOBUF_GEN_DIR := opentelemetry-proto-gen
PROTOBUF_TEMP_DIR := $(GEN_TEMP_DIR)/go
GO := go
GO_VERSION := 1.17
GO_MOD_ROOT := go.opentelemetry.io/proto
PROTOBUF_GEN_DIR := opentelemetry-proto-gen
PROTOBUF_TEMP_DIR := $(GEN_TEMP_DIR)/go

PROTO_SOURCE_DIR := $(GEN_TEMP_DIR)/proto
SOURCE_PROTO_FILES := $(subst $(OTEL_PROTO_SUBMODULE),$(PROTO_SOURCE_DIR),$(SUBMODULE_PROTO_FILES))
GO_MOD_ROOT := go.opentelemetry.io/proto
OTLP_OUTPUT_DIR := otlp
GO_VERSION := 1.17

PROTOSLIM_SOURCE_DIR := $(GEN_TEMP_DIR)/slim/proto
SOURCE_PROTOSLIM_FILES := $(subst $(OTEL_PROTO_SUBMODULE),$(PROTOSLIM_SOURCE_DIR),$(SUBMODULE_PROTO_FILES))
OTLPSLIM_OUTPUT_DIR := slim/otlp

# Function to execute a command. Note the empty line before endef to make sure each command
# gets executed separately instead of concatenated with previous one.
Expand All @@ -55,6 +60,7 @@ endef

OTEL_DOCKER_PROTOBUF ?= otel/build-protobuf:0.23.0
PROTOC := docker run --rm -u ${shell id -u} -v${PWD}:${PWD} -w${PWD} ${OTEL_DOCKER_PROTOBUF} --proto_path="$(PROTO_SOURCE_DIR)"
PROTOC_SLIM := docker run --rm -u ${shell id -u} -v${PWD}:${PWD} -w${PWD} ${OTEL_DOCKER_PROTOBUF} --proto_path="$(PROTOSLIM_SOURCE_DIR)"

.DEFAULT_GOAL := protobuf

Expand All @@ -78,7 +84,7 @@ $(TOOLS)/dbotconf: PACKAGE=go.opentelemetry.io/build-tools/dbotconf
tools: $(DBOTCONF) $(MULTIMOD)

.PHONY: protobuf
protobuf: protobuf-source gen-otlp-protobuf copy-otlp-protobuf
protobuf: protobuf-source gen-otlp-protobuf copy-otlp-protobuf gen-otlp-protobuf-slim copy-otlp-protobuf-slim

.PHONY: protobuf-source
protobuf-source: $(SOURCE_PROTO_FILES)
Expand All @@ -96,6 +102,19 @@ $(PROTO_SOURCE_DIR)/%.proto: $(OTEL_PROTO_SUBMODULE)/%.proto
sed -e $(SED_EXPR) "$<" >"$@.tmp"; \
mv "$@.tmp" "$@"

# The sed expression for replacing the go_package option in proto
# file with a one that's valid for us.
SED_EXPR_SLIM := 's,go_package = "go.opentelemetry.io/proto/otlp/,go_package = "$(GO_MOD_ROOT)/$(OTLPSLIM_OUTPUT_DIR)/,'

# This copies proto files from submodule into $(PROTO_SOURCE_DIR),
# thus satisfying the $(SOURCE_PROTOSLIM_FILES) prerequisite. The copies
# have their package name replaced by go.opentelemetry.io/proto.
$(PROTOSLIM_SOURCE_DIR)/%.proto: $(OTEL_PROTO_SUBMODULE)/%.proto
@ \
mkdir -p $(@D); \
sed -e $(SED_EXPR_SLIM) "$<" >"$@.tmp"; \
mv "$@.tmp" "$@"

.PHONY: gen-otlp-protobuf
gen-otlp-protobuf: $(SOURCE_PROTO_FILES)
rm -rf ./$(PROTOBUF_TEMP_DIR)
Expand All @@ -111,10 +130,22 @@ copy-otlp-protobuf:
rm -rf ./$(OTLP_OUTPUT_DIR)/*/
@rsync -a $(PROTOBUF_TEMP_DIR)/go.opentelemetry.io/proto/otlp/ ./$(OTLP_OUTPUT_DIR)
cd ./$(OTLP_OUTPUT_DIR) && go mod tidy

.PHONY: gen-otlp-protobuf-slim
gen-otlp-protobuf-slim: $(SOURCE_PROTOSLIM_FILES)
rm -rf ./$(PROTOBUF_TEMP_DIR)
mkdir -p ./$(PROTOBUF_TEMP_DIR)
$(foreach file,$(SOURCE_PROTOSLIM_FILES),$(call exec-command,$(PROTOC_SLIM) $(PROTO_INCLUDES) --go_out=./$(PROTOBUF_TEMP_DIR) $(file)))

.PHONY: copy-otlp-protobuf-slim
copy-otlp-protobuf-slim:
rm -rf $(OTLPSLIM_OUTPUT_DIR)/*/
@rsync -a $(PROTOBUF_TEMP_DIR)/go.opentelemetry.io/proto/slim/otlp/ ./$(OTLPSLIM_OUTPUT_DIR)
cd ./$(OTLPSLIM_OUTPUT_DIR) && go mod tidy

.PHONY: clean
clean:
rm -rf $(GEN_TEMP_DIR) $(OTLP_OUTPUT_DIR)/*/
rm -rf $(GEN_TEMP_DIR) $(OTLP_OUTPUT_DIR)/*/ $(OTLPSLIM_OUTPUT_DIR)/*/

.PHONY: check-clean-work-tree
check-clean-work-tree:
Expand Down
Loading
Loading