Skip to content

Commit

Permalink
feat grpc: add grpc service config proto
Browse files Browse the repository at this point in the history
commit_hash:2a5018e97eab4703a8414be3d31b369c203e4dfb
  • Loading branch information
kpavlov00 committed Feb 7, 2025
1 parent 8453bee commit edd79eb
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,15 @@ jobs:
docker-compose -f .github/docker-compose.yml
run --rm ${{ matrix.image }} bash -c
'cd /userver && cmake -DUSERVER_GOOGLE_COMMON_PROTOS=/app/api-common-protos
-DUSERVER_GRPC_PROTO=/app/grpc-proto
${{ matrix.cmake-flags }} -B./build -S./'
- name: Reconfigure cmake
run: >-
docker-compose -f .github/docker-compose.yml
run --rm ${{ matrix.image }} bash -c
'cd /userver && cmake -DUSERVER_GOOGLE_COMMON_PROTOS=/app/api-common-protos
-DUSERVER_GRPC_PROTO=/app/grpc-proto
${{ matrix.cmake-flags }} -B./build -S./'
- name: Compile
Expand Down
1 change: 1 addition & 0 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@
"cmake/SetupGTest.cmake":"taxi/uservices/userver/cmake/SetupGTest.cmake",
"cmake/SetupGoogleProtoApis.cmake":"taxi/uservices/userver/cmake/SetupGoogleProtoApis.cmake",
"cmake/SetupGrpc.cmake":"taxi/uservices/userver/cmake/SetupGrpc.cmake",
"cmake/SetupGrpcProto.cmake":"taxi/uservices/userver/cmake/SetupGrpcProto.cmake",
"cmake/SetupHomebrew.cmake":"taxi/uservices/userver/cmake/SetupHomebrew.cmake",
"cmake/SetupLTO.cmake":"taxi/uservices/userver/cmake/SetupLTO.cmake",
"cmake/SetupLinker.cmake":"taxi/uservices/userver/cmake/SetupLinker.cmake",
Expand Down
2 changes: 1 addition & 1 deletion cmake/SetupGoogleProtoApis.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ if (NOT api-common-protos_SOURCE_DIR)
message(FATAL_ERROR "Unable to get google common proto apis. It is required for userver-grpc build.")
endif()

include(UserverGrpcTargets)
file(GLOB SOURCES
${api-common-protos_SOURCE_DIR}/google/api/*.proto
${api-common-protos_SOURCE_DIR}/google/rpc/*.proto
)

include(UserverGrpcTargets)
userver_generate_grpc_files(
PROTOS ${SOURCES}
INCLUDE_DIRECTORIES ${api-common-protos_SOURCE_DIR}
Expand Down
59 changes: 59 additions & 0 deletions cmake/SetupGrpcProto.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
set(USERVER_GRPC_PROTO_TARGET "" CACHE STRING "Name of cmake target preparing grpc proto library")
set(USERVER_GRPC_PROTO "" CACHE PATH "Path to the folder with grpc proto files")

if (USERVER_GRPC_PROTO_TARGET)
set(grpc-proto_LIBRARY ${USERVER_GRPC_PROTO_TARGET})
return()
elseif (USERVER_GRPC_PROTO)
set(grpc-proto_SOURCE_DIR ${USERVER_GRPC_PROTO})
endif()

if (NOT EXISTS ${grpc-proto_SOURCE_DIR})
include(DownloadUsingCPM)
CPMAddPackage(
NAME grpc-proto
GIT_TAG master
GITHUB_REPOSITORY grpc/grpc-proto
DOWNLOAD_ONLY YES
)
endif()

if(NOT TARGET userver-api-common-protos)
include(SetupGoogleProtoApis)
endif()

if (NOT api-common-protos_SOURCE_DIR)
message(FATAL_ERROR "Unable to get google common proto apis. It is required for userver-grpc build.")
endif()

if (NOT grpc-proto_SOURCE_DIR)
message(FATAL_ERROR "Unable to get grpc-proto. It is required for userver-grpc build.")
endif()

SET(SOURCES
${grpc-proto_SOURCE_DIR}/grpc/lookup/v1/rls_config.proto
${grpc-proto_SOURCE_DIR}/grpc/service_config/service_config.proto
)

include(UserverGrpcTargets)
userver_generate_grpc_files(
PROTOS ${SOURCES}
INCLUDE_DIRECTORIES ${grpc-proto_SOURCE_DIR} ${api-common-protos_SOURCE_DIR}
SOURCE_PATH ${grpc-proto_SOURCE_DIR}
GENERATED_INCLUDES include_paths
CPP_FILES generated_sources
CPP_USRV_FILES generated_usrv_sources
)

add_library(userver-grpc-proto-contrib STATIC ${generated_sources})
target_link_libraries(userver-grpc-proto-contrib PUBLIC ${api-common-proto_LIBRARY})
target_compile_options(userver-grpc-proto-contrib PRIVATE -Wno-deprecated-declarations)
target_include_directories(userver-grpc-proto-contrib SYSTEM PUBLIC $<BUILD_INTERFACE:${include_paths}>)

_userver_directory_install(COMPONENT grpc
DIRECTORY ${include_paths}/grpc
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/userver/third_party
PATTERN "*.pb.h"
)

set(grpc-proto_LIBRARY userver-grpc-proto-contrib)
5 changes: 4 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from conan.tools.cmake import cmake_layout
from conan.tools.cmake import CMakeDeps
from conan.tools.cmake import CMakeToolchain
from conan.tools.files import copy
from conan.tools.files import load

required_conan_version = '>=2.8.0' # pylint: disable=invalid-name
Expand Down Expand Up @@ -136,6 +135,7 @@ def requirements(self):
force=True,
)
self.requires('googleapis/cci.20230501')
self.requires('grpc-proto/cci.20220627')
if self.options.with_postgresql:
self.requires('libpq/14.5')
if self.options.with_mongodb or self.options.with_kafka:
Expand Down Expand Up @@ -219,6 +219,9 @@ def generate(self):
self.dependencies['googleapis'].cpp_info.components['google_rpc_status_proto'].resdirs[0]
)

if self.options.with_grpc:
tool_ch.variables['USERVER_GRPC_PROTO'] = self.dependencies['grpc-proto'].cpp_info.resdirs[0]

if self.options.with_otlp:
tool_ch.variables['USERVER_OPENTELEMETRY_PROTO'] = self.dependencies['opentelemetry-proto'].conf_info.get(
'user.opentelemetry-proto:proto_root'
Expand Down
7 changes: 7 additions & 0 deletions grpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ endif()
if(NOT TARGET userver-api-common-protos)
include(SetupGoogleProtoApis)
endif()
if(NOT TARGET userver-grpc-proto-contrib)
include(SetupGrpcProto)
endif()

file(GLOB_RECURSE SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/include/*pp
Expand Down Expand Up @@ -77,6 +80,10 @@ if(DEFINED api-common-proto_LIBRARY)
target_link_libraries(${PROJECT_NAME}-internal PUBLIC ${api-common-proto_LIBRARY})
_userver_install_targets(COMPONENT grpc TARGETS ${api-common-proto_LIBRARY})
endif()
if(DEFINED grpc-proto_LIBRARY)
target_link_libraries(${PROJECT_NAME}-internal PUBLIC ${grpc-proto_LIBRARY})
_userver_install_targets(COMPONENT grpc TARGETS ${grpc-proto_LIBRARY})
endif()

userver_generate_grpc_files(
PROTOS userver/field_options.proto
Expand Down
20 changes: 11 additions & 9 deletions scripts/docs/en/userver/build/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,17 @@ The exact format of setting cmake options varies depending on the method of buil

### CMake options for paths to dependencies

| Option | Description | Default |
|---------------------------------------|----------------------------------------------------------------------------------------------------------------|------------------------------------|
| `USERVER_PYTHON_PATH` | Path to the python3 binary for use in testsuite tests | `python3` |
| `USERVER_PG_SERVER_INCLUDE_DIR` | Path to the folder with @ref POSTGRES_LIBS "PostgreSQL server headers", e.g. /usr/include/postgresql/15/server | autodetected |
| `USERVER_PG_SERVER_LIBRARY_DIR` | Path to the folder with @ref POSTGRES_LIBS "PostgreSQL server libraries", e.g. /usr/lib/postgresql/15/lib | autodetected |
| `USERVER_PG_INCLUDE_DIR` | Path to the folder with @ref POSTGRES_LIBS "PostgreSQL libpq headers", e.g. /usr/local/include | autodetected |
| `USERVER_PG_LIBRARY_DIR` | Path to the folder with @ref POSTGRES_LIBS "PostgreSQL libpq libraries", e.g. /usr/local/lib | autodetected |
| `USERVER_GOOGLE_COMMON_PROTOS_TARGET` | Name of cmake target preparing google common proto library | Builds `userver-api-common-protos` |
| `USERVER_GOOGLE_COMMON_PROTOS` | Path to the folder with google common proto files | Downloads automatically |
| Option | Description | Default |
|---------------------------------------|----------------------------------------------------------------------------------------------------------------|-------------------------------------|
| `USERVER_PYTHON_PATH` | Path to the python3 binary for use in testsuite tests | `python3` |
| `USERVER_PG_SERVER_INCLUDE_DIR` | Path to the folder with @ref POSTGRES_LIBS "PostgreSQL server headers", e.g. /usr/include/postgresql/15/server | autodetected |
| `USERVER_PG_SERVER_LIBRARY_DIR` | Path to the folder with @ref POSTGRES_LIBS "PostgreSQL server libraries", e.g. /usr/lib/postgresql/15/lib | autodetected |
| `USERVER_PG_INCLUDE_DIR` | Path to the folder with @ref POSTGRES_LIBS "PostgreSQL libpq headers", e.g. /usr/local/include | autodetected |
| `USERVER_PG_LIBRARY_DIR` | Path to the folder with @ref POSTGRES_LIBS "PostgreSQL libpq libraries", e.g. /usr/local/lib | autodetected |
| `USERVER_GOOGLE_COMMON_PROTOS_TARGET` | Name of cmake target preparing google common proto library | Builds `userver-api-common-protos` |
| `USERVER_GOOGLE_COMMON_PROTOS` | Path to the folder with google common proto files | Downloads automatically |
| `USERVER_GRPC_PROTO_TARGET` | Name of cmake target preparing grpc proto library | Builds `userver-grpc-proto-contrib` |
| `USERVER_GRPC_PROTO` | Path to the folder with grpc proto files | Downloads automatically |

### CMake options for various compilation modes

Expand Down

0 comments on commit edd79eb

Please sign in to comment.