diff --git a/.gitmodules b/.gitmodules index e14eaf471a7..27dca31865e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -253,3 +253,4 @@ [submodule "contrib/BLAKE3"] path = contrib/BLAKE3 url = https://github.com/BoloniniD/BLAKE3.git + branch = RustFFI-compat diff --git a/CMakeLists.txt b/CMakeLists.txt index fdc9cfcd303..361c3b5685c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ include (cmake/target.cmake) include (cmake/tools.cmake) include (cmake/analysis.cmake) include (cmake/git_status.cmake) +include (cmake/build_rust_lib.cmake) # Ignore export() since we don't use it, # but it gets broken with a global targets via link_libraries() @@ -95,6 +96,14 @@ if (ENABLE_CHECK_HEAVY_BUILDS) set (CMAKE_CXX_COMPILER_LAUNCHER prlimit --as=${RLIMIT_AS} --data=${RLIMIT_DATA} --cpu=${RLIMIT_CPU} ${CMAKE_CXX_COMPILER_LAUNCHER}) endif () +if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CARGO_RELEASE_FLAG "" CACHE INTERNAL "") + set(TARGET_DIR "debug" CACHE INTERNAL "") +else () + set(CARGO_RELEASE_FLAG "--release" CACHE INTERNAL "") + set(TARGET_DIR "release" CACHE INTERNAL "") +endif () + if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "None") set (CMAKE_BUILD_TYPE "RelWithDebInfo") message (STATUS "CMAKE_BUILD_TYPE is not set, set to default = ${CMAKE_BUILD_TYPE}") diff --git a/cmake/build_rust_lib.cmake b/cmake/build_rust_lib.cmake new file mode 100755 index 00000000000..77fcac183de --- /dev/null +++ b/cmake/build_rust_lib.cmake @@ -0,0 +1,39 @@ +function(build_cargo target_name project_dir) + set(output_library ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_DIR}/lib${target_name}.a) + file(GLOB sources ${project_dir}/src/**/*.rs) + + set(compile_message "Compiling ${target_name}") + + if(CARGO_RELEASE_FLAG STREQUAL "--release") + set(compile_message "${compile_message} in release mode") + endif() + + add_custom_command( + COMMENT ${compile_message} + COMMAND env CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR} cargo build ${CARGO_RELEASE_FLAG} + COMMAND cp ${output_library} ${CMAKE_CURRENT_BINARY_DIR} + OUTPUT ${output_library} + WORKING_DIRECTORY ${project_dir}) + + if(NOT TARGET ${target_name}-target) + add_custom_target(${target_name}-target ALL DEPENDS ${output_library}) + endif() + + set_property( + TARGET ${target_name}-target + APPEND PROPERTY + INTERFACE_DEPENDENCIES ${output_library} + ) + + set_target_properties(${target_name}-target PROPERTIES LOCATION ${output_library}) + + add_library(${target_name} STATIC IMPORTED GLOBAL) + + add_dependencies(${target_name} ${target_name}-target) + + set_target_properties(${target_name} + PROPERTIES + IMPORTED_LOCATION ${output_library} + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/include/) + +endfunction() diff --git a/contrib/BLAKE3 b/contrib/BLAKE3 index f1ebb28eb95..9f2ac62d469 160000 --- a/contrib/BLAKE3 +++ b/contrib/BLAKE3 @@ -1 +1 @@ -Subproject commit f1ebb28eb95652f92ec2c2f7763deca41b69d0fd +Subproject commit 9f2ac62d469bab150b6be7e05bf06b793d8d80cb diff --git a/contrib/BLAKE3-cmake/CMakeLists.txt b/contrib/BLAKE3-cmake/CMakeLists.txt deleted file mode 100644 index 81fb3fcb2aa..00000000000 --- a/contrib/BLAKE3-cmake/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set (LIBRARY_DIR ${ClickHouse_SOURCE_DIR}/contrib/BLAKE3) - -add_library (BLAKE3 ${SRCS}) - - -target_include_directories(BLAKE3 ${LIBRARY_DIR}/include) \ No newline at end of file diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 9eb3b145c85..c1ae4af9566 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -21,6 +21,8 @@ endif() set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL 1) +add_subdirectory (BLAKE3) + add_subdirectory (abseil-cpp-cmake) add_subdirectory (magic-enum-cmake) add_subdirectory (boost-cmake) diff --git a/docker/test/fasttest/run.sh b/docker/test/fasttest/run.sh index 24168cea330..2173f3cd77a 100755 --- a/docker/test/fasttest/run.sh +++ b/docker/test/fasttest/run.sh @@ -175,6 +175,7 @@ function clone_submodules contrib/NuRaft contrib/jemalloc contrib/replxx + contrib/BLAKE3 ) git submodule sync