Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
grpc: move protos to a separate library
Browse files Browse the repository at this point in the history
- when compiling protos into a shared library, the shared library can not
be reloaded: protocolbuffers/protobuf#4126

- it is not recommended to have multiple shared libraries with protos
  compiled in them: protocolbuffers/protobuf#1489

Signed-off-by: László Várady <[email protected]>
  • Loading branch information
MrAnno committed Aug 1, 2023
1 parent 3174724 commit 145dd60
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
url = https://github.com/bazsi/ivykis.git
ignore = dirty
[submodule "modules/grpc/otel/opentelemetry-proto"]
path = modules/grpc/otel/opentelemetry-proto
path = modules/grpc/protos/opentelemetry-proto
url = https://github.com/open-telemetry/opentelemetry-proto.git
1 change: 1 addition & 0 deletions modules/grpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ set(MODULE_GRPC_LIBS
gRPC::grpc++
protobuf::libprotobuf)

add_subdirectory(protos)
add_subdirectory(otel)
2 changes: 2 additions & 0 deletions modules/grpc/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include modules/grpc/protos/Makefile.am

include modules/grpc/otel/Makefile.am

if ENABLE_GRPC
Expand Down
33 changes: 2 additions & 31 deletions modules/grpc/otel/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
set(OTEL_PROTO_SRCDIR "${CMAKE_CURRENT_SOURCE_DIR}/opentelemetry-proto")
set(OTEL_PROTO_BUILDDIR "${CMAKE_CURRENT_BINARY_DIR}/proto")

set(OTEL_PROTO_SOURCES
opentelemetry/proto/common/v1/common.proto
opentelemetry/proto/logs/v1/logs.proto
opentelemetry/proto/metrics/v1/metrics.proto
opentelemetry/proto/trace/v1/trace.proto
opentelemetry/proto/resource/v1/resource.proto)

set(OTEL_PROTO_GRPC_SOURCES
opentelemetry/proto/collector/logs/v1/logs_service.proto
opentelemetry/proto/collector/metrics/v1/metrics_service.proto
opentelemetry/proto/collector/trace/v1/trace_service.proto)

protobuf_generate_cpp(
PROTO_PATH ${OTEL_PROTO_SRCDIR}
CPP_OUT ${OTEL_PROTO_BUILDDIR}
OUT_SRCS OTEL_PROTO_GENERATED_SOURCES
PROTOS ${OTEL_PROTO_SOURCES})

protobuf_generate_cpp_grpc(
PROTO_PATH ${OTEL_PROTO_SRCDIR}
CPP_OUT ${OTEL_PROTO_BUILDDIR}
OUT_SRCS OTEL_PROTO_GENERATED_GRPC_SOURCES
PROTOS ${OTEL_PROTO_GRPC_SOURCES})

set(OTEL_CPP_SOURCES
otel-source.cpp
otel-source.hpp
Expand All @@ -43,9 +16,7 @@ set(OTEL_CPP_SOURCES
otel-dest.cpp
otel-dest.h
otel-dest-worker.hpp
otel-dest-worker.cpp
${OTEL_PROTO_GENERATED_SOURCES}
${OTEL_PROTO_GENERATED_GRPC_SOURCES})
otel-dest-worker.cpp)

set(OTEL_SOURCES
otel-plugin.c
Expand All @@ -56,7 +27,7 @@ set(OTEL_SOURCES
add_module(
TARGET otel-cpp
SOURCES ${OTEL_CPP_SOURCES}
DEPENDS ${MODULE_GRPC_LIBS}
DEPENDS ${MODULE_GRPC_LIBS} grpc-protos
INCLUDES ${OTEL_PROTO_BUILDDIR}
LIBRARY_TYPE STATIC
)
Expand Down
59 changes: 5 additions & 54 deletions modules/grpc/otel/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,46 +1,7 @@
OTEL_PROTO_SRCDIR = $(top_srcdir)/modules/grpc/otel/opentelemetry-proto
OTEL_PROTO_BUILDDIR = $(top_builddir)/modules/grpc/otel/proto

if ENABLE_GRPC

OTEL_PROTO_PROTOC_FLAGS = $(PROTOC_GEN_GRPC_CPP_PLUGIN_FLAGS) --proto_path=$(OTEL_PROTO_SRCDIR) --cpp_out=$(OTEL_PROTO_BUILDDIR)

modules/grpc/otel/proto/%.grpc.pb.cc modules/grpc/otel/proto/%.grpc.pb.h:
mkdir -p $(OTEL_PROTO_BUILDDIR)
$(PROTOC) $(OTEL_PROTO_PROTOC_FLAGS) --grpc-cpp_out=$(OTEL_PROTO_BUILDDIR) $*.proto

modules/grpc/otel/proto/%.pb.cc modules/grpc/otel/proto/%.pb.h:
mkdir -p $(OTEL_PROTO_BUILDDIR)
$(PROTOC) $(OTEL_PROTO_PROTOC_FLAGS) $*.proto

OTEL_PROTO_BUILT_SOURCES = \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/common/v1/common.pb.h \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/common/v1/common.pb.cc \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/resource/v1/resource.pb.h \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/resource/v1/resource.pb.cc \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/logs/v1/logs.pb.h \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/logs/v1/logs.pb.cc \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/metrics/v1/metrics.pb.h \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/metrics/v1/metrics.pb.cc \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/trace/v1/trace.pb.h \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/trace/v1/trace.pb.cc \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.cc \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/collector/logs/v1/logs_service.pb.h \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/collector/logs/v1/logs_service.pb.cc \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.cc \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/collector/metrics/v1/metrics_service.pb.cc \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.cc \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/collector/trace/v1/trace_service.pb.h \
$(OTEL_PROTO_BUILDDIR)/opentelemetry/proto/collector/trace/v1/trace_service.pb.cc

noinst_LTLIBRARIES += modules/grpc/otel/libotel_cpp.la

nodist_modules_grpc_otel_libotel_cpp_la_SOURCES = $(OTEL_PROTO_BUILT_SOURCES)

modules_grpc_otel_libotel_cpp_la_SOURCES = \
modules/grpc/otel/otel-source.h \
modules/grpc/otel/otel-source.hpp \
Expand All @@ -65,14 +26,10 @@ modules_grpc_otel_libotel_cpp_la_CXXFLAGS = \
$(AM_CXXFLAGS) \
$(PROTOBUF_CFLAGS) \
$(GRPCPP_CFLAGS) \
-I$(OTEL_PROTO_BUILDDIR) \
-I$(OPENTELEMETRY_PROTO_BUILDDIR) \
-I$(top_srcdir)/modules/grpc/otel \
-I$(top_builddir)/modules/grpc/otel

if ENABLE_EXTRA_WARNINGS
modules_grpc_otel_libotel_cpp_la_CXXFLAGS += -Wno-switch-default
endif

modules_grpc_otel_libotel_cpp_la_LIBADD = $(MODULE_DEPS_LIBS) $(PROTOBUF_LIBS) $(GRPCPP_LIBS)
modules_grpc_otel_libotel_cpp_la_LDFLAGS = $(MODULE_LDFLAGS)
modules_grpc_otel_libotel_cpp_la_DEPENDENCIES = $(MODULE_DEPS_LIBS)
Expand All @@ -92,36 +49,30 @@ modules_grpc_otel_libotel_la_CPPFLAGS = \

modules_grpc_otel_libotel_la_LIBADD = \
$(MODULE_DEPS_LIBS) \
$(top_builddir)/modules/grpc/protos/libgrpc-protos.la \
$(top_builddir)/modules/grpc/otel/libotel_cpp.la \
-lstdc++

modules_grpc_otel_libotel_la_LDFLAGS = $(MODULE_LDFLAGS)

modules_grpc_otel_libotel_la_DEPENDENCIES = \
$(MODULE_DEPS_LIBS) \
$(top_builddir)/modules/grpc/protos/libgrpc-protos.la \
$(top_builddir)/modules/grpc/otel/libotel_cpp.la

modules/grpc/otel modules/grpc/otel/ mod-otel: modules/grpc/otel/libotel.la
else
modules/grpc/otel modules/grpc/otel/ mod-otel:
endif

CLEANFILES += \
$(OTEL_PROTO_BUILT_SOURCES)

BUILT_SOURCES += \
modules/grpc/otel/otel-grammar.y \
modules/grpc/otel/otel-grammar.c \
modules/grpc/otel/otel-grammar.h \
$(OTEL_PROTO_BUILT_SOURCES)

NODIST_BUILT_SOURCES += \
$(OTEL_PROTO_BUILT_SOURCES)
modules/grpc/otel/otel-grammar.h

EXTRA_DIST += \
modules/grpc/otel/otel-grammar.ym \
modules/grpc/otel/CMakeLists.txt \
$(OTEL_PROTO_SRCDIR)
modules/grpc/otel/CMakeLists.txt

.PHONY: modules/grpc/otel/ mod-otel

Expand Down
16 changes: 10 additions & 6 deletions modules/grpc/otel/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,37 @@ modules_grpc_otel_tests_test_otel_protobuf_parser_SOURCES = \
modules/grpc/otel/tests/test-otel-protobuf-parser.cpp

modules_grpc_otel_tests_test_otel_protobuf_parser_DEPENDENCIES = \
$(top_builddir)/modules/grpc/otel/libotel_cpp.la
$(top_builddir)/modules/grpc/otel/libotel_cpp.la \
$(top_builddir)/modules/grpc/protos/libgrpc-protos.la

modules_grpc_otel_tests_test_otel_protobuf_parser_CXXFLAGS = \
$(TEST_CXXFLAGS) \
-I$(OTEL_PROTO_BUILDDIR) \
-I$(OPENTELEMETRY_PROTO_BUILDDIR) \
-I$(top_srcdir)/modules/grpc/otel \
-I$(top_builddir)/modules/grpc/otel

modules_grpc_otel_tests_test_otel_protobuf_parser_LDADD = \
$(TEST_LDADD) \
$(top_builddir)/modules/grpc/otel/libotel_cpp.la
$(top_builddir)/modules/grpc/otel/libotel_cpp.la \
$(top_builddir)/modules/grpc/protos/libgrpc-protos.la

modules_grpc_otel_tests_test_otel_protobuf_formatter_SOURCES = \
modules/grpc/otel/tests/test-otel-protobuf-formatter.cpp

modules_grpc_otel_tests_test_otel_protobuf_formatter_DEPENDENCIES = \
$(top_builddir)/modules/grpc/otel/libotel_cpp.la
$(top_builddir)/modules/grpc/otel/libotel_cpp.la \
$(top_builddir)/modules/grpc/protos/libgrpc-protos.la

modules_grpc_otel_tests_test_otel_protobuf_formatter_CXXFLAGS = \
$(TEST_CXXFLAGS) \
-I$(OTEL_PROTO_BUILDDIR) \
-I$(OPENTELEMETRY_PROTO_BUILDDIR) \
-I$(top_srcdir)/modules/grpc/otel \
-I$(top_builddir)/modules/grpc/otel

modules_grpc_otel_tests_test_otel_protobuf_formatter_LDADD = \
$(TEST_LDADD) \
$(top_builddir)/modules/grpc/otel/libotel_cpp.la
$(top_builddir)/modules/grpc/otel/libotel_cpp.la \
$(top_builddir)/modules/grpc/protos/libgrpc-protos.la

endif

Expand Down
34 changes: 34 additions & 0 deletions modules/grpc/protos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
set(OTEL_PROTO_SRCDIR "${CMAKE_CURRENT_SOURCE_DIR}/opentelemetry-proto")
set(OTEL_PROTO_BUILDDIR "${CMAKE_CURRENT_BINARY_DIR}/opentelemetry-proto")
set(OTEL_PROTO_BUILDDIR ${OTEL_PROTO_BUILDDIR} PARENT_SCOPE)

set(GRPC_PROTO_SOURCES
opentelemetry/proto/common/v1/common.proto
opentelemetry/proto/logs/v1/logs.proto
opentelemetry/proto/metrics/v1/metrics.proto
opentelemetry/proto/trace/v1/trace.proto
opentelemetry/proto/resource/v1/resource.proto)

set(GRPC_PROTO_GRPC_SOURCES
opentelemetry/proto/collector/logs/v1/logs_service.proto
opentelemetry/proto/collector/metrics/v1/metrics_service.proto
opentelemetry/proto/collector/trace/v1/trace_service.proto)

protobuf_generate_cpp(
PROTO_PATH ${OTEL_PROTO_SRCDIR}
CPP_OUT ${OTEL_PROTO_BUILDDIR}
OUT_SRCS GRPC_PROTO_GENERATED_SOURCES
PROTOS ${GRPC_PROTO_SOURCES})

protobuf_generate_cpp_grpc(
PROTO_PATH ${OTEL_PROTO_SRCDIR}
CPP_OUT ${OTEL_PROTO_BUILDDIR}
OUT_SRCS GRPC_PROTO_GENERATED_GRPC_SOURCES
PROTOS ${GRPC_PROTO_GRPC_SOURCES})

add_module(
TARGET grpc-protos
SOURCES ${GRPC_PROTO_GENERATED_SOURCES} ${GRPC_PROTO_GENERATED_GRPC_SOURCES}
DEPENDS ${MODULE_GRPC_LIBS}
INCLUDES ${OTEL_PROTO_BUILDDIR}
)
69 changes: 69 additions & 0 deletions modules/grpc/protos/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
GRPC_PROTOS_SRCDIR = $(top_srcdir)/modules/grpc/protos
GRPC_PROTOS_BUILDDIR = $(top_builddir)/modules/grpc/protos

if ENABLE_GRPC

OPENTELEMETRY_PROTO_SRCDIR = $(GRPC_PROTOS_SRCDIR)/opentelemetry-proto
OPENTELEMETRY_PROTO_BUILDDIR = $(GRPC_PROTOS_BUILDDIR)/otlp

OPENTELEMETRY_PROTO_PROTOC_FLAGS = $(PROTOC_GEN_GRPC_CPP_PLUGIN_FLAGS) --proto_path=$(OPENTELEMETRY_PROTO_SRCDIR) --cpp_out=$(OPENTELEMETRY_PROTO_BUILDDIR)

modules/grpc/protos/otlp/%.grpc.pb.cc modules/grpc/protos/otlp/%.grpc.pb.h:
mkdir -p $(OPENTELEMETRY_PROTO_BUILDDIR)
$(PROTOC) $(OPENTELEMETRY_PROTO_PROTOC_FLAGS) --grpc-cpp_out=$(OPENTELEMETRY_PROTO_BUILDDIR) $*.proto

modules/grpc/protos/otlp/%.pb.cc modules/grpc/protos/otlp/%.pb.h:
mkdir -p $(OPENTELEMETRY_PROTO_BUILDDIR)
$(PROTOC) $(OPENTELEMETRY_PROTO_PROTOC_FLAGS) $*.proto

GRPC_PROTOS_BUILT_SOURCES = \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/common/v1/common.pb.h \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/common/v1/common.pb.cc \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/resource/v1/resource.pb.h \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/resource/v1/resource.pb.cc \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/logs/v1/logs.pb.h \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/logs/v1/logs.pb.cc \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/metrics/v1/metrics.pb.h \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/metrics/v1/metrics.pb.cc \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/trace/v1/trace.pb.h \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/trace/v1/trace.pb.cc \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.cc \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/collector/logs/v1/logs_service.pb.h \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/collector/logs/v1/logs_service.pb.cc \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.cc \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/collector/metrics/v1/metrics_service.pb.cc \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.cc \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/collector/trace/v1/trace_service.pb.h \
$(OPENTELEMETRY_PROTO_BUILDDIR)/opentelemetry/proto/collector/trace/v1/trace_service.pb.cc

lib_LTLIBRARIES += modules/grpc/protos/libgrpc-protos.la

nodist_modules_grpc_protos_libgrpc_protos_la_SOURCES = $(GRPC_PROTOS_BUILT_SOURCES)

modules_grpc_protos_libgrpc_protos_la_CXXFLAGS = \
$(AM_CXXFLAGS) \
$(PROTOBUF_CLFAGS) \
$(GRPCPP_CFLAGS) \
-I$(OPENTELEMETRY_PROTO_SRCDIR) \
-I$(OPENTELEMETRY_PROTO_BUILDDIR)

modules_grpc_protos_libgrpc_protos_la_LIBADD = $(MODULE_DEPS_LIBS) $(PROTOBUF_LIBS) $(GRPCPP_LIBS) -lstdc++
modules_grpc_protos_libgrpc_protos_la_DEPENDENCIES = $(MODULE_DEPS_LIBS)

endif

CLEANFILES += \
$(GRPC_PROTOS_BUILT_SOURCES)

BUILT_SOURCES += \
$(GRPC_PROTOS_BUILT_SOURCES)

NODIST_BUILT_SOURCES += \
$(GRPC_PROTOS_BUILT_SOURCES)

EXTRA_DIST += \
$(OPENTELEMETRY_PROTO_SRCDIR)
1 change: 1 addition & 0 deletions packaging/debian/syslog-ng-mod-grpc.install
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
usr/lib/syslog-ng/*/libgrpc-protos.so
usr/lib/syslog-ng/*/libotel.so

0 comments on commit 145dd60

Please sign in to comment.