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

Generate proto for C++ #1871

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


*~
*.iml
*.ipr
Expand Down Expand Up @@ -58,3 +56,5 @@ test/tracetesting/tracetesting-vars.yaml

# Android
*.apk

!src/currency/build
1 change: 1 addition & 0 deletions .licenserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"/src/accounting/src/protos/",
"src/cart/src/obj/",
"src/cart/tests/obj/",
"src/currency/build/",
"src/checkoutservice/genproto/",
"src/featureflagservice/assets/vendor/",
"src/featureflagservice/priv/",
Expand Down
37 changes: 25 additions & 12 deletions docker-gen-proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,42 @@ set -x # Print commands and their arguments as they are executed

# This script is used to generate protobuf files for all services with Docker.

. ./.env

gen_proto_go() {
echo "Generating Go protobuf files for $1"
docker build -f "src/$1/genproto/Dockerfile" -t "$1-genproto" .
docker run --rm -v $(pwd):/build "$1-genproto" \
protoc -I /build/pb /build/pb/demo.proto --go_out="./src/$1/" --go-grpc_out="./src/$1/"
}

gen_proto_cpp() {
echo "Generating Cpp protobuf files for $1"
docker build --build-arg OPENTELEMETRY_CPP_VERSION=${OPENTELEMETRY_CPP_VERSION} -f "src/$1/genproto/Dockerfile" -t "$1-genproto" .
docker run --rm -v $(pwd):/build "$1-genproto" \
cp -r "/$1/build/generated" "/build/src/$1/build/"
}

gen_proto_python() {
echo "Generating Python protobuf files for $1"
docker build -f "src/$1/genproto/Dockerfile" -t "$1-genproto" .
docker run --rm -v $(pwd):/build "$1-genproto" \
python -m grpc_tools.protoc -I /build/pb/ --python_out="./src/$1/" --grpc_python_out="./src/$1/" /build/pb/demo.proto
}

#gen_proto_dotnet accounting
#gen_proto_java ad
#gen_proto_dotnet cart
gen_proto_go checkoutservice
#gen_proto_cpp currency
#gen_proto_ruby email
#gen_proto_ts frontend
#gen_proto_js payment
gen_proto_go productcatalogservice
#gen_proto_php quote
gen_proto_python recommendation
#gen_proto_rust shipping
if [ -z "$1" ]; then
#gen_proto_dotnet accounting
#gen_proto_java ad
#gen_proto_dotnet cart
gen_proto_go checkoutservice
gen_proto_cpp currency
#gen_proto_ruby email
#gen_proto_ts frontend
#gen_proto_js payment
gen_proto_go productcatalogservice
#gen_proto_php quote
gen_proto_python recommendation
#gen_proto_rust shipping
else
"gen_proto_$1" "$2"
fi
1 change: 0 additions & 1 deletion src/currency/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
client.js
node_modules/
build/
out/
50 changes: 1 addition & 49 deletions src/currency/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,10 @@ find_package(Protobuf REQUIRED)
find_package(gRPC CONFIG REQUIRED)
find_package(opentelemetry-cpp CONFIG REQUIRED)

set(PROTO_PATH "${CMAKE_CURRENT_SOURCE_DIR}/proto")
set(GENERATED_PROTOBUF_PATH "${CMAKE_BINARY_DIR}/generated/proto")
set(GENERATED_HEALTH_PROTOBUF_PATH "${GENERATED_PROTOBUF_PATH}/grpc/health/v1")

file(MAKE_DIRECTORY "${GENERATED_PROTOBUF_PATH}")
add_subdirectory(genproto)

set(DEMO_PROTO "${PROTO_PATH}/demo.proto")
set(DEMO_PB_CPP_FILE "${GENERATED_PROTOBUF_PATH}/demo.pb.cc")
set(DEMO_PB_H_FILE "${GENERATED_PROTOBUF_PATH}/demo.pb.h")
set(DEMO_GRPC_PB_CPP_FILE "${GENERATED_PROTOBUF_PATH}/demo.grpc.pb.cc")
set(DEMO_GRPC_PB_H_FILE "${GENERATED_PROTOBUF_PATH}/demo.grpc.pb.h")
set(HEALTH_PROTO "${PROTO_PATH}/grpc/health/v1/health.proto")
set(HEALTH_PB_CPP_FILE "${GENERATED_HEALTH_PROTOBUF_PATH}/health.pb.cc")
set(HEALTH_PB_H_FILE "${GENERATED_HEALTH_PROTOBUF_PATH}/health.pb.h")
set(HEALTH_GRPC_PB_CPP_FILE "${GENERATED_HEALTH_PROTOBUF_PATH}/health.grpc.pb.cc")
set(HEALTH_GRPC_PB_H_FILE "${GENERATED_HEALTH_PROTOBUF_PATH}/health.grpc.pb.h")

foreach(IMPORT_DIR ${PROTOBUF_IMPORT_DIRS})
list(APPEND PROTOBUF_INCLUDE_FLAGS "-I${IMPORT_DIR}")
endforeach()

find_program(gRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)

add_custom_command(
OUTPUT ${DEMO_PB_H_FILE}
${DEMO_PB_CPP_FILE}
${DEMO_GRPC_PB_CPP_FILE}
${DEMO_GRPC_PB_H_FILE}
${HEALTH_PB_H_FILE}
${HEALTH_PB_CPP_FILE}
${HEALTH_GRPC_PB_CPP_FILE}
${HEALTH_GRPC_PB_H_FILE}

COMMAND
${PROTOBUF_PROTOC_EXECUTABLE} ARGS "--experimental_allow_proto3_optional"
"--proto_path=${PROTO_PATH}" ${PROTOBUF_INCLUDE_FLAGS}
"--cpp_out=${GENERATED_PROTOBUF_PATH}"
"--grpc_out=generate_mock_code=true:${GENERATED_PROTOBUF_PATH}"
--plugin=protoc-gen-grpc="${gRPC_CPP_PLUGIN_EXECUTABLE}" ${DEMO_PROTO} ${HEALTH_PROTO})

message(STATUS "gRPC_CPP_PLUGIN_EXECUTABLE=${gRPC_CPP_PLUGIN_EXECUTABLE}")

add_library(demo-proto ${DEMO_PB_H_FILE}
${DEMO_PB_CPP_FILE}
${DEMO_GRPC_PB_CPP_FILE}
${DEMO_GRPC_PB_H_FILE}
${HEALTH_PB_H_FILE}
${HEALTH_PB_CPP_FILE}
${HEALTH_GRPC_PB_CPP_FILE}
${HEALTH_GRPC_PB_H_FILE})

target_link_libraries(demo-proto gRPC::grpc++ protobuf::libprotobuf)
include_directories("${GENERATED_PROTOBUF_PATH}" "${OPENTELEMETRY_CPP_INCLUDE_DIRS}")

add_executable(currency src/server.cpp)
Expand Down
5 changes: 2 additions & 3 deletions src/currency/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ RUN apk update && apk add git cmake make g++ grpc-dev protobuf-dev linux-headers

ARG OPENTELEMETRY_CPP_VERSION

RUN git clone https://github.com/open-telemetry/opentelemetry-cpp \
&& cd opentelemetry-cpp/ \
&& git checkout tags/v${OPENTELEMETRY_CPP_VERSION} -b v${OPENTELEMETRY_CPP_VERSION} \
RUN git clone --depth 1 --branch v${OPENTELEMETRY_CPP_VERSION} https://github.com/open-telemetry/opentelemetry-cpp \
&& cd opentelemetry-cpp/ \
&& mkdir build \
&& cd build \
&& cmake .. -DCMAKE_CXX_STANDARD=17 -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
Expand Down
Loading
Loading