Try to fix grpc for aarch64 crosscompilation

(cherry picked from commit f3fbf532e0d4d7616f51a9c3d5087cf7b2e6d7d5)
This commit is contained in:
alesapin 2024-05-17 22:52:25 +02:00
parent 8c5af6abd6
commit 24892b151a
3 changed files with 61 additions and 4 deletions

View File

@ -41,10 +41,7 @@ if (CMAKE_CROSSCOMPILING)
set (ENABLE_ICU OFF CACHE INTERNAL "")
set (ENABLE_FASTOPS OFF CACHE INTERNAL "")
elseif (OS_LINUX OR OS_ANDROID)
if (ARCH_AARCH64)
# FIXME: broken dependencies
set (ENABLE_GRPC OFF CACHE INTERNAL "")
elseif (ARCH_PPC64LE)
if (ARCH_PPC64LE)
set (ENABLE_GRPC OFF CACHE INTERNAL "")
elseif (ARCH_RISCV64)
# RISC-V support is preliminary

View File

@ -31,3 +31,59 @@ add_library(_ch_contrib_grpc INTERFACE)
target_link_libraries(_ch_contrib_grpc INTERFACE ${gRPC_LIBRARIES})
target_include_directories(_ch_contrib_grpc SYSTEM INTERFACE ${gRPC_INCLUDE_DIRS})
add_library(ch_contrib::grpc ALIAS _ch_contrib_grpc)
# Here we are trying to build a binary tool grpc_cpp_plugin in case of cross-compilation.
# We need this file only during compilation process itself so we need it for our "host"
# platform, not "target" platform.
# If we are doing normal compilation this file will be produced in grpc.cmake.
#
# All code inside this block looks so weird because cmake fundametally doesn't
# support different toolchains for different targets. So we just running it
# in "bash script" fashion with different (actually without, i.e. default) toolchain.
#
# FIXME Sorry, I don't know cmake.
if (NOT CMAKE_HOST_SYSTEM_NAME STREQUAL CMAKE_SYSTEM_NAME
OR NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL CMAKE_SYSTEM_PROCESSOR)
set (GRPC_CPP_PLUGIN_BUILD_DIR "${_gRPC_BINARY_DIR}/build")
execute_process(
COMMAND mkdir -p ${GRPC_CPP_PLUGIN_BUILD_DIR}
COMMAND_ECHO STDOUT
)
set(abseil_source_dir "${ClickHouse_SOURCE_DIR}/contrib/abseil-cpp")
set(protobuf_source_dir "${ClickHouse_SOURCE_DIR}/contrib/google-protobuf")
set(re2_source_dir "${ClickHouse_SOURCE_DIR}/contrib/re2")
set(ssl_source_dir "${ClickHouse_SOURCE_DIR}/contrib/openssl")
set(zlib_source_dir "${ClickHouse_SOURCE_DIR}/contrib/zlib-ng")
# For some reason config exists only in this directory
set(zlib_config_source_dir "${ClickHouse_BINARY_DIR}/contrib/zlib-ng-cmake")
set(cares_source_dir "${ClickHouse_SOURCE_DIR}/contrib/c-ares")
execute_process(
COMMAND ${CMAKE_COMMAND}
"-G${CMAKE_GENERATOR}"
"-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}"
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DABSL_ROOT_DIR=${abseil_source_dir}"
"-DCMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES=${zlib_config_source_dir}"
"-DgRPC_INSTALL=0"
"-DABSL_ENABLE_INSTALL=1"
"-DPROTOBUF_ROOT_DIR=${protobuf_source_dir}"
"-DRE2_ROOT_DIR=${re2_source_dir}"
"-DCARES_ROOT_DIR=${cares_source_dir}"
"-DBORINGSSL_ROOT_DIR=${ssl_source_dir}"
"-DZLIB_ROOT_DIR=${zlib_source_dir}"
"${_gRPC_SOURCE_DIR}"
WORKING_DIRECTORY "${GRPC_CPP_PLUGIN_BUILD_DIR}"
COMMAND_ECHO STDOUT)
execute_process(
COMMAND ${CMAKE_COMMAND} --build "${GRPC_CPP_PLUGIN_BUILD_DIR}"
COMMAND_ECHO STDOUT)
add_executable(grpc_cpp_plugin IMPORTED GLOBAL)
set_target_properties (grpc_cpp_plugin PROPERTIES IMPORTED_LOCATION "${GRPC_CPP_PLUGIN_BUILD_DIR}/grpc_cpp_plugin")
add_dependencies(grpc_cpp_plugin "${GRPC_CPP_PLUGIN_BUILD_DIR}/grpc_cpp_plugin")
endif()

View File

@ -1829,6 +1829,8 @@ target_link_libraries(grpc_plugin_support
${_gRPC_PROTOBUF_PROTOC_LIBRARIES}
)
if (CMAKE_HOST_SYSTEM_NAME STREQUAL CMAKE_SYSTEM_NAME
AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL CMAKE_SYSTEM_PROCESSOR)
add_executable(grpc_cpp_plugin
${_gRPC_SOURCE_DIR}/src/compiler/cpp_plugin.cc
@ -1852,3 +1854,5 @@ target_link_libraries(grpc_cpp_plugin
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_plugin_support
)
endif()