diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 5b46b27a6b08..f7eecd6bb207 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -119,6 +119,7 @@ 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 @@ -126,6 +127,7 @@ 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: Compile diff --git a/.mapping.json b/.mapping.json index fa589bbfd883..a8d93c9ba2b1 100644 --- a/.mapping.json +++ b/.mapping.json @@ -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", diff --git a/cmake/SetupGoogleProtoApis.cmake b/cmake/SetupGoogleProtoApis.cmake index beeae59a26ce..94dd1995d5e2 100644 --- a/cmake/SetupGoogleProtoApis.cmake +++ b/cmake/SetupGoogleProtoApis.cmake @@ -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} diff --git a/cmake/SetupGrpcProto.cmake b/cmake/SetupGrpcProto.cmake new file mode 100644 index 000000000000..37220c4447ad --- /dev/null +++ b/cmake/SetupGrpcProto.cmake @@ -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 $) + +_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) diff --git a/conanfile.py b/conanfile.py index 8593f8bc7884..d372ada85252 100644 --- a/conanfile.py +++ b/conanfile.py @@ -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 @@ -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: @@ -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' diff --git a/grpc/CMakeLists.txt b/grpc/CMakeLists.txt index d1ee80a38902..fe4a0233972f 100644 --- a/grpc/CMakeLists.txt +++ b/grpc/CMakeLists.txt @@ -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 @@ -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 diff --git a/scripts/docs/en/userver/build/options.md b/scripts/docs/en/userver/build/options.md index 2fca5de819e3..ba595ecb3002 100644 --- a/scripts/docs/en/userver/build/options.md +++ b/scripts/docs/en/userver/build/options.md @@ -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