From 3f3e77e7e98f14e64d54932744d1e4b15ca60bca Mon Sep 17 00:00:00 2001 From: Ilya Konyukhov Date: Wed, 15 May 2019 18:07:25 +0300 Subject: [PATCH 1/7] Add librdkafka dependency as submodule --- .gitmodules | 3 +++ librdkafka | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 librdkafka diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..0f9c2de --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "librdkafka"] + path = librdkafka + url = https://github.com/edenhill/librdkafka.git diff --git a/librdkafka b/librdkafka new file mode 160000 index 0000000..8695b9d --- /dev/null +++ b/librdkafka @@ -0,0 +1 @@ +Subproject commit 8695b9d63ac0fe1b891b511d5b36302ffc84d4e2 From 5a2d440fb79bae1a0ea49dfbffc67e91a2a23290 Mon Sep 17 00:00:00 2001 From: Ilya Konyukhov Date: Wed, 22 May 2019 10:31:18 +0300 Subject: [PATCH 2/7] Link rdkafka statically with BUNDLE_RDKAFKA option --- CMakeLists.txt | 9 +++++++-- cmake/FindRdKafka.cmake | 6 ++++++ kafka/CMakeLists.txt | 10 +++++++++- rockspecs/kafka-scm-1.rockspec | 3 --- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6390d8a..98505e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,8 +17,13 @@ if(${tntver} VERSION_LESS 1.7.4.291) message(FATAL_ERROR "Tarantool >= 1.7.4-291 is required") endif() -set(RDKAFKA_FIND_REQUIRED ON) -find_package(RdKafka) +if(BUNDLE_RDKAFKA) + include(buildRdKafka) + buildrdkafka() +else() + set(RDKAFKA_FIND_REQUIRED ON) + find_package(RdKafka) +endif() include_directories(${TARANTOOL_INCLUDE_DIRS}) diff --git a/cmake/FindRdKafka.cmake b/cmake/FindRdKafka.cmake index 5ef53e5..653f1a5 100644 --- a/cmake/FindRdKafka.cmake +++ b/cmake/FindRdKafka.cmake @@ -6,11 +6,17 @@ find_path(RDKAFKA_INCLUDE_DIR NAMES librdkafka/rdkafka.h HINTS ${RDKAFKA_ROOT_DIR}/include ) + find_library(RDKAFKA_LIBRARY NAMES ${CMAKE_SHARED_LIBRARY_PREFIX}rdkafka${CMAKE_SHARED_LIBRARY_SUFFIX} rdkafka HINTS ${RDKAFKA_ROOT_DIR}/lib ) +find_library(RDKAFKA_STATIC + NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}rdkafka${CMAKE_STATIC_LIBRARY_SUFFIX} rdkafka + HINTS ${RDKAFKA_ROOT_DIR}/lib + ) + include(FindPackageHandleStandardArgs) find_package_handle_standard_args(RDKAFKA DEFAULT_MSG RDKAFKA_LIBRARY diff --git a/kafka/CMakeLists.txt b/kafka/CMakeLists.txt index effa4df..9d8cd4d 100644 --- a/kafka/CMakeLists.txt +++ b/kafka/CMakeLists.txt @@ -7,8 +7,16 @@ if (APPLE) -undefined suppress -flat_namespace") endif(APPLE) -target_link_libraries(tntkafka ${RDKAFKA_LIBRARY} pthread) +target_link_libraries(tntkafka pthread) + +if (BUNDLE_RDKAFKA) + add_dependencies(tntkafka rdkafka) + target_link_libraries(tntkafka ${CMAKE_SOURCE_DIR}/librdkafka/src/librdkafka.a) +else() + target_link_libraries(tntkafka ${RDKAFKA_LIBRARY}) +endif() set_target_properties(tntkafka PROPERTIES PREFIX "" OUTPUT_NAME "tntkafka") + install(TARGETS tntkafka LIBRARY DESTINATION ${TARANTOOL_INSTALL_LIBDIR}/kafka) install(FILES init.lua DESTINATION ${TARANTOOL_INSTALL_LUADIR}/kafka) diff --git a/rockspecs/kafka-scm-1.rockspec b/rockspecs/kafka-scm-1.rockspec index 51a2e4d..ec342b8 100644 --- a/rockspecs/kafka-scm-1.rockspec +++ b/rockspecs/kafka-scm-1.rockspec @@ -15,9 +15,6 @@ dependencies = { external_dependencies = { TARANTOOL = { header = 'tarantool/module.h' - }, - RDKAFKA = { - header = 'librdkafka/rdkafka.h' } } build = { From 201f14f4e08edbe7e75f8e8eba347e5e4839bc42 Mon Sep 17 00:00:00 2001 From: Ilya Konyukhov Date: Wed, 22 May 2019 10:51:03 +0300 Subject: [PATCH 3/7] Bypass BUILD_RDKAFKA from rockspec to cmake --- rockspecs/kafka-scm-1.rockspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rockspecs/kafka-scm-1.rockspec b/rockspecs/kafka-scm-1.rockspec index ec342b8..367d034 100644 --- a/rockspecs/kafka-scm-1.rockspec +++ b/rockspecs/kafka-scm-1.rockspec @@ -23,6 +23,7 @@ build = { CMAKE_BUILD_TYPE="RelWithDebInfo", TARANTOOL_DIR="$(TARANTOOL_DIR)", TARANTOOL_INSTALL_LIBDIR="$(LIBDIR)", - TARANTOOL_INSTALL_LUADIR="$(LUADIR)" + TARANTOOL_INSTALL_LUADIR="$(LUADIR)", + BUNDLE_RDKAFKA="$(BUNDLE_RDKAFKA)" } } \ No newline at end of file From 6261ca7e4a8042c4865e6d39c2f9d0f92292b3db Mon Sep 17 00:00:00 2001 From: Ilya Konyukhov Date: Wed, 22 May 2019 10:57:11 +0300 Subject: [PATCH 4/7] Add cmake build script for rdkafka --- cmake/buildRdKafka.cmake | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 cmake/buildRdKafka.cmake diff --git a/cmake/buildRdKafka.cmake b/cmake/buildRdKafka.cmake new file mode 100644 index 0000000..7afbabc --- /dev/null +++ b/cmake/buildRdKafka.cmake @@ -0,0 +1,10 @@ +macro(buildrdkafka) + add_custom_target( + rdkafka + COMMAND ./configure + COMMAND make + COMMAND make install + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/librdkafka + VERBATIM + ) +endmacro() From cda420b86411a7db6d85a13adbf129ca30bc6271 Mon Sep 17 00:00:00 2001 From: Ilya Konyukhov Date: Thu, 23 May 2019 13:35:15 +0300 Subject: [PATCH 5/7] Update readme with new cmake option --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 7a76589..ae19069 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,14 @@ non critical errors as strings which allows you to decide how to handle it. tarantoolctl rocks install https://raw.githubusercontent.com/tarantool/tnt-kafka/master/rockspecs/kafka-scm-1.rockspec ``` +## Build module with statically linked librdkafka + +To install kafka module with builtin librdkafka dependency, use option `BUNDLE_RDKAFKA`: + +```bash +tarantoolctl rocks BUNDLE_RDKAFKA=ON install https://raw.githubusercontent.com/tarantool/tnt-kafka/master/rockspecs/tnt-kafka-scm-1.rockspec +``` + # Examples ## Consumer From abe4ee960201865b55d62d891447fb8897f62d2d Mon Sep 17 00:00:00 2001 From: Ilya Konyukhov Date: Thu, 23 May 2019 23:10:18 +0300 Subject: [PATCH 6/7] cmake: Rename BUNDLE_RDKAFKA option to STATIC_BUILD --- CMakeLists.txt | 2 +- README.md | 4 ++-- kafka/CMakeLists.txt | 2 +- rockspecs/kafka-scm-1.rockspec | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 98505e1..0570cac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ if(${tntver} VERSION_LESS 1.7.4.291) message(FATAL_ERROR "Tarantool >= 1.7.4-291 is required") endif() -if(BUNDLE_RDKAFKA) +if(STATIC_BUILD) include(buildRdKafka) buildrdkafka() else() diff --git a/README.md b/README.md index ae19069..fd34e24 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,10 @@ non critical errors as strings which allows you to decide how to handle it. ## Build module with statically linked librdkafka -To install kafka module with builtin librdkafka dependency, use option `BUNDLE_RDKAFKA`: +To install kafka module with builtin librdkafka dependency, use option `STATIC_BUILD`: ```bash -tarantoolctl rocks BUNDLE_RDKAFKA=ON install https://raw.githubusercontent.com/tarantool/tnt-kafka/master/rockspecs/tnt-kafka-scm-1.rockspec +tarantoolctl rocks STATIC_BUILD=ON install https://raw.githubusercontent.com/tarantool/tnt-kafka/master/rockspecs/tnt-kafka-scm-1.rockspec ``` # Examples diff --git a/kafka/CMakeLists.txt b/kafka/CMakeLists.txt index 9d8cd4d..c4417f6 100644 --- a/kafka/CMakeLists.txt +++ b/kafka/CMakeLists.txt @@ -9,7 +9,7 @@ endif(APPLE) target_link_libraries(tntkafka pthread) -if (BUNDLE_RDKAFKA) +if (STATIC_BUILD) add_dependencies(tntkafka rdkafka) target_link_libraries(tntkafka ${CMAKE_SOURCE_DIR}/librdkafka/src/librdkafka.a) else() diff --git a/rockspecs/kafka-scm-1.rockspec b/rockspecs/kafka-scm-1.rockspec index 367d034..94c3b84 100644 --- a/rockspecs/kafka-scm-1.rockspec +++ b/rockspecs/kafka-scm-1.rockspec @@ -24,6 +24,6 @@ build = { TARANTOOL_DIR="$(TARANTOOL_DIR)", TARANTOOL_INSTALL_LIBDIR="$(LIBDIR)", TARANTOOL_INSTALL_LUADIR="$(LUADIR)", - BUNDLE_RDKAFKA="$(BUNDLE_RDKAFKA)" + STATIC_BUILD="$(STATIC_BUILD)" } } \ No newline at end of file From 1984c62d1855f1717641e593a8edfb73f2855db9 Mon Sep 17 00:00:00 2001 From: Ilya Konyukhov Date: Fri, 24 May 2019 11:20:43 +0300 Subject: [PATCH 7/7] Update url to rockspec from README example --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fd34e24..68c69d5 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ non critical errors as strings which allows you to decide how to handle it. # Installation ```bash - tarantoolctl rocks install https://raw.githubusercontent.com/tarantool/tnt-kafka/master/rockspecs/kafka-scm-1.rockspec + tarantoolctl rocks install https://raw.githubusercontent.com/tarantool/kafka/master/rockspecs/kafka-scm-1.rockspec ``` ## Build module with statically linked librdkafka @@ -30,7 +30,7 @@ non critical errors as strings which allows you to decide how to handle it. To install kafka module with builtin librdkafka dependency, use option `STATIC_BUILD`: ```bash -tarantoolctl rocks STATIC_BUILD=ON install https://raw.githubusercontent.com/tarantool/tnt-kafka/master/rockspecs/tnt-kafka-scm-1.rockspec +tarantoolctl rocks STATIC_BUILD=ON install https://raw.githubusercontent.com/tarantool/kafka/master/rockspecs/kafka-scm-1.rockspec ``` # Examples