Skip to content

Commit

Permalink
feat(cpp-client): Generate protos for C++ as part of the build (#6136)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcferretti authored Sep 26, 2024
1 parent dec3ffd commit d6bee30
Show file tree
Hide file tree
Showing 48 changed files with 65 additions and 215,311 deletions.
30 changes: 4 additions & 26 deletions cpp-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,6 @@ spotless {
evaluationDependsOn Docker.registryProject('cpp-clients-multi-base')
evaluationDependsOn Docker.registryProject('manylinux2014_x86_64')

configurations {
cpp {}
}
dependencies {
cpp project(path: ':proto:proto-backplane-grpc', configuration: 'cpp')
}
def protoSourceDir = layout.projectDirectory.dir('deephaven/dhclient/proto')
def compare = tasks.register('compareProtobuf', DiffTask) {
expectedContents.set configurations.cpp
actualContents {
directory protoSourceDir
}
generateTask.set ':cpp-client:updateProtobuf'
}
// Need to disable until the proto base image can catch up to protobuf 28.2
tasks.getByName('compareProtobuf').enabled = false

// fail a "check" build if these are out of date
tasks.getByName('quick').dependsOn(compare)

tasks.register('updateProtobuf', Sync) {
finalizedBy compare
from configurations.cpp
into protoSourceDir
}

// start a grpc-api server
String randomSuffix = UUID.randomUUID().toString();
deephavenDocker {
Expand Down Expand Up @@ -77,6 +51,9 @@ def buildCppClientImage = Docker.registerDockerTask(project, 'cppClient') {
include 'deephaven/examples/**'
include 'deephaven/tests/**'
}
from("../proto/proto-backplane-grpc/src/main") {
include 'proto/**'
}
}

dockerfile {
Expand All @@ -96,6 +73,7 @@ def buildCppClientImage = Docker.registerDockerTask(project, 'cppClient') {
copyFile('deephaven/dhclient/', "${prefix}/src/deephaven/dhclient/")
copyFile('deephaven/examples/', "${prefix}/src/deephaven/examples/")
copyFile('deephaven/tests/', "${prefix}/src/deephaven/tests/")
copyFile('proto/', "${prefix}/proto/proto-backplane-grpc/src/main/proto/")
copyFile('cpp-tests-to-junit.sh', "${prefix}/bin/dhcpp")
copyFile('build-dependencies.sh', "/tmp")
runCommand("PREFIX='${prefix}'; BUILD_TYPE='${build_type}'; " +
Expand Down
113 changes: 61 additions & 52 deletions cpp-client/deephaven/dhclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,50 @@ find_package(Protobuf CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)
find_package(Threads REQUIRED)

set(PROTO_SRC_DIR
"${CMAKE_CURRENT_SOURCE_DIR}/../../../proto/proto-backplane-grpc/src/main/proto")
set(PROTO_GEN_DIR
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}/proto")
set(PROTO_OUT_DIR "${PROTO_GEN_DIR}/deephaven/proto")

set(PROTO_FILES
"${PROTO_SRC_DIR}/deephaven/proto/application.proto"
"${PROTO_SRC_DIR}/deephaven/proto/config.proto"
"${PROTO_SRC_DIR}/deephaven/proto/console.proto"
"${PROTO_SRC_DIR}/deephaven/proto/hierarchicaltable.proto"
"${PROTO_SRC_DIR}/deephaven/proto/inputtable.proto"
"${PROTO_SRC_DIR}/deephaven/proto/object.proto"
"${PROTO_SRC_DIR}/deephaven/proto/partitionedtable.proto"
"${PROTO_SRC_DIR}/deephaven/proto/session.proto"
"${PROTO_SRC_DIR}/deephaven/proto/storage.proto"
"${PROTO_SRC_DIR}/deephaven/proto/table.proto"
"${PROTO_SRC_DIR}/deephaven/proto/ticket.proto"
)

foreach(PROTO_FILE ${PROTO_FILES})
get_filename_component(BASENAME ${PROTO_FILE} NAME_WLE)
list(APPEND PROTO_GEN_FILES
"${PROTO_OUT_DIR}/${BASENAME}.grpc.pb.cc"
"${PROTO_OUT_DIR}/${BASENAME}.grpc.pb.h"
"${PROTO_OUT_DIR}/${BASENAME}.pb.cc"
"${PROTO_OUT_DIR}/${BASENAME}.pb.h"
)
endforeach()

add_custom_command(
OUTPUT ${PROTO_GEN_FILES}
COMMAND "${CMAKE_COMMAND}"
ARGS -E make_directory "${PROTO_OUT_DIR}"
COMMAND protobuf::protoc
ARGS "--plugin=protoc-gen-grpc=\$<TARGET_FILE:gRPC::grpc_cpp_plugin>"
"--cpp_out=${PROTO_GEN_DIR}"
"--grpc_out=${PROTO_GEN_DIR}"
"-I${PROTO_SRC_DIR}"
${PROTO_FILES}
DEPENDS ${PROTO_FILES}
COMMENT "Generating protos"
)

set(ALL_FILES
src/server/server.cc
include/private/deephaven/client/server/server.h
Expand Down Expand Up @@ -65,74 +109,39 @@ set(ALL_FILES
include/public/deephaven/client/utility/arrow_util.h
include/public/deephaven/client/utility/misc_types.h
include/public/deephaven/client/utility/table_maker.h

proto/deephaven/proto/application.grpc.pb.cc
proto/deephaven/proto/application.grpc.pb.h
proto/deephaven/proto/application.pb.cc
proto/deephaven/proto/application.pb.h
proto/deephaven/proto/config.grpc.pb.cc
proto/deephaven/proto/config.grpc.pb.h
proto/deephaven/proto/config.pb.cc
proto/deephaven/proto/config.pb.h
proto/deephaven/proto/console.grpc.pb.cc
proto/deephaven/proto/console.grpc.pb.h
proto/deephaven/proto/console.pb.cc
proto/deephaven/proto/console.pb.h
proto/deephaven/proto/inputtable.grpc.pb.cc
proto/deephaven/proto/inputtable.grpc.pb.h
proto/deephaven/proto/inputtable.pb.cc
proto/deephaven/proto/inputtable.pb.h
proto/deephaven/proto/object.grpc.pb.cc
proto/deephaven/proto/object.grpc.pb.h
proto/deephaven/proto/object.pb.cc
proto/deephaven/proto/object.pb.h
proto/deephaven/proto/partitionedtable.grpc.pb.cc
proto/deephaven/proto/partitionedtable.grpc.pb.h
proto/deephaven/proto/partitionedtable.pb.cc
proto/deephaven/proto/partitionedtable.pb.h
proto/deephaven/proto/session.grpc.pb.cc
proto/deephaven/proto/session.grpc.pb.h
proto/deephaven/proto/session.pb.cc
proto/deephaven/proto/session.pb.h
proto/deephaven/proto/table.grpc.pb.cc
proto/deephaven/proto/table.grpc.pb.h
proto/deephaven/proto/table.pb.cc
proto/deephaven/proto/table.pb.h
proto/deephaven/proto/ticket.grpc.pb.cc
proto/deephaven/proto/ticket.grpc.pb.h
proto/deephaven/proto/ticket.pb.cc
proto/deephaven/proto/ticket.pb.h
)

list(APPEND ALL_FILES ${PROTO_GEN_FILES})

add_library(dhclient SHARED ${ALL_FILES})

# This is so deephaven::client works both when using the installed CMake config
# and when using this project as a CMake subdirectory of your own project.
add_library(deephaven::client ALIAS dhclient)
add_library(deephaven::client ALIAS ${PROJECT_NAME})

set_property(TARGET dhclient PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)

if (LINUX)
target_compile_options(dhclient PRIVATE -Wall -Werror -Wno-deprecated-declarations)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Werror -Wno-deprecated-declarations)
endif()

if (WIN32)
set_property(TARGET dhclient PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
set_property(TARGET ${PROJECT_NAME} PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
# /Wall is a bit too chatty so we stick with /W3
# /bigobj needed because ticking/immer_table_state.cc compiles to something too large apparently
target_compile_options(dhclient PRIVATE /W3 /bigobj)
target_compile_options(${PROJECT_NAME} PRIVATE /W3 /bigobj)
endif()

target_include_directories(dhclient PRIVATE include/private)
target_include_directories(dhclient PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/public>)
target_include_directories(${PROJECT_NAME} PRIVATE include/private)
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/public>)
# Protos and flatbuf are doing their own thing.
target_include_directories(dhclient PRIVATE "./proto")
target_include_directories(dhclient PRIVATE "./flatbuf")
target_include_directories(${PROJECT_NAME} PRIVATE "${PROTO_GEN_DIR}")
target_include_directories(${PROJECT_NAME} PRIVATE "./flatbuf")

target_link_libraries(dhclient PUBLIC deephaven::dhcore)
target_link_libraries(${PROJECT_NAME} PUBLIC deephaven::dhcore)

target_link_libraries(dhclient PUBLIC ArrowFlight::arrow_flight_shared)
target_link_libraries(dhclient PUBLIC Arrow::arrow_shared)
target_link_libraries(dhclient PRIVATE protobuf::libprotobuf)
target_link_libraries(dhclient PRIVATE gRPC::grpc++)
target_link_libraries(dhclient PRIVATE Threads::Threads)
target_link_libraries(${PROJECT_NAME} PUBLIC ArrowFlight::arrow_flight_shared)
target_link_libraries(${PROJECT_NAME} PUBLIC Arrow::arrow_shared)
target_link_libraries(${PROJECT_NAME} PRIVATE protobuf::libprotobuf)
target_link_libraries(${PROJECT_NAME} PRIVATE gRPC::grpc++)
target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads)

This file was deleted.

Loading

0 comments on commit d6bee30

Please sign in to comment.