From ffddc694f343aae3a73075bb6819fccb828a41a3 Mon Sep 17 00:00:00 2001 From: Thomas Devoogdt Date: Tue, 25 Jul 2023 09:10:41 +0200 Subject: [PATCH 1/5] lib: librdkafka: CMakeLists.txt: allow compilation without CXX support #7741 e.g. fluent-bit is a c-only library, so allow compilation without cxx Upstream: https://github.com/confluentinc/librdkafka/pull/4366 Signed-off-by: Thomas Devoogdt --- lib/librdkafka-2.4.0/CMakeLists.txt | 18 ++++++++++-- lib/librdkafka-2.4.0/examples/CMakeLists.txt | 31 +++++++++++++------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/lib/librdkafka-2.4.0/CMakeLists.txt b/lib/librdkafka-2.4.0/CMakeLists.txt index 7f3dd0fc68a..c1ee93062bd 100644 --- a/lib/librdkafka-2.4.0/CMakeLists.txt +++ b/lib/librdkafka-2.4.0/CMakeLists.txt @@ -3,7 +3,12 @@ cmake_minimum_required(VERSION 3.2) include("packaging/cmake/parseversion.cmake") parseversion("src/rdkafka.h") -project(RdKafka VERSION ${RDKAFKA_VERSION}) +project(RdKafka VERSION ${RDKAFKA_VERSION} LANGUAGES C) + +option(RDKAFKA_BUILD_CXX "Enable CXX support" ON) +if(RDKAFKA_BUILD_CXX) + enable_language(CXX) +endif() set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/packaging/cmake/Modules/") @@ -181,7 +186,11 @@ endif() option(RDKAFKA_BUILD_STATIC "Build static rdkafka library" OFF) option(RDKAFKA_BUILD_EXAMPLES "Build examples" ON) -option(RDKAFKA_BUILD_TESTS "Build tests" ON) + +if(RDKAFKA_BUILD_CXX) + option(RDKAFKA_BUILD_TESTS "Build tests" ON) +endif() + if(WIN32) option(WITHOUT_WIN32_CONFIG "Avoid including win32_config.h on cmake builds" ON) endif(WIN32) @@ -279,7 +288,10 @@ install( ) add_subdirectory(src) -add_subdirectory(src-cpp) + +if(RDKAFKA_BUILD_CXX) + add_subdirectory(src-cpp) +endif() if(RDKAFKA_BUILD_EXAMPLES) add_subdirectory(examples) diff --git a/lib/librdkafka-2.4.0/examples/CMakeLists.txt b/lib/librdkafka-2.4.0/examples/CMakeLists.txt index 8c0079abeea..c9336b72926 100644 --- a/lib/librdkafka-2.4.0/examples/CMakeLists.txt +++ b/lib/librdkafka-2.4.0/examples/CMakeLists.txt @@ -5,8 +5,10 @@ endif(WIN32) add_executable(producer producer.c ${win32_sources}) target_link_libraries(producer PUBLIC rdkafka) -add_executable(producer_cpp producer.cpp ${win32_sources}) -target_link_libraries(producer_cpp PUBLIC rdkafka++) +if(RDKAFKA_BUILD_CXX) + add_executable(producer_cpp producer.cpp ${win32_sources}) + target_link_libraries(producer_cpp PUBLIC rdkafka++) +endif() add_executable(consumer consumer.c ${win32_sources}) target_link_libraries(consumer PUBLIC rdkafka) @@ -14,14 +16,20 @@ target_link_libraries(consumer PUBLIC rdkafka) add_executable(rdkafka_performance rdkafka_performance.c ${win32_sources}) target_link_libraries(rdkafka_performance PUBLIC rdkafka) -add_executable(rdkafka_example_cpp rdkafka_example.cpp ${win32_sources}) -target_link_libraries(rdkafka_example_cpp PUBLIC rdkafka++) +if(RDKAFKA_BUILD_CXX) + add_executable(rdkafka_example_cpp rdkafka_example.cpp ${win32_sources}) + target_link_libraries(rdkafka_example_cpp PUBLIC rdkafka++) +endif() -add_executable(rdkafka_complex_consumer_example_cpp rdkafka_complex_consumer_example.cpp ${win32_sources}) -target_link_libraries(rdkafka_complex_consumer_example_cpp PUBLIC rdkafka++) +if(RDKAFKA_BUILD_CXX) + add_executable(rdkafka_complex_consumer_example_cpp rdkafka_complex_consumer_example.cpp ${win32_sources}) + target_link_libraries(rdkafka_complex_consumer_example_cpp PUBLIC rdkafka++) +endif() -add_executable(openssl_engine_example_cpp openssl_engine_example.cpp ${win32_sources}) -target_link_libraries(openssl_engine_example_cpp PUBLIC rdkafka++) +if(RDKAFKA_BUILD_CXX) + add_executable(openssl_engine_example_cpp openssl_engine_example.cpp ${win32_sources}) + target_link_libraries(openssl_engine_example_cpp PUBLIC rdkafka++) +endif() add_executable(misc misc.c ${win32_sources}) target_link_libraries(misc PUBLIC rdkafka) @@ -70,7 +78,8 @@ if(NOT WIN32) add_executable(rdkafka_complex_consumer_example rdkafka_complex_consumer_example.c) target_link_libraries(rdkafka_complex_consumer_example PUBLIC rdkafka) - add_executable(kafkatest_verifiable_client kafkatest_verifiable_client.cpp) - target_link_libraries(kafkatest_verifiable_client PUBLIC rdkafka++) - + if(RDKAFKA_BUILD_CXX) + add_executable(kafkatest_verifiable_client kafkatest_verifiable_client.cpp) + target_link_libraries(kafkatest_verifiable_client PUBLIC rdkafka++) + endif() endif(NOT WIN32) From 82358e0cba8bd2a4a2ebed129dde6bfadb6bb324 Mon Sep 17 00:00:00 2001 From: Thomas Devoogdt Date: Tue, 25 Jul 2023 10:00:36 +0200 Subject: [PATCH 2/5] build: disable cxx support for librdkafka #7741 Fluent-bit is c only, so no need to compile cxx. This fixes also a compile error in buildroot. Signed-off-by: Thomas Devoogdt --- cmake/kafka.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/kafka.cmake b/cmake/kafka.cmake index 3a0ebfed23c..af0e2f46018 100644 --- a/cmake/kafka.cmake +++ b/cmake/kafka.cmake @@ -1,4 +1,5 @@ # kafka cmake +FLB_OPTION(RDKAFKA_BUILD_CXX Off) FLB_OPTION(RDKAFKA_BUILD_STATIC On) FLB_OPTION(RDKAFKA_BUILD_EXAMPLES Off) FLB_OPTION(RDKAFKA_BUILD_TESTS Off) From cbe8b9a56531fbb883ed569f0a65ead5ba9763c0 Mon Sep 17 00:00:00 2001 From: Thomas Devoogdt Date: Sun, 25 Aug 2024 20:09:21 +0200 Subject: [PATCH 3/5] lib: nghttp2: CMakeLists.txt: do not require a CXX compiler Upstream: https://github.com/nghttp2/nghttp2/commit/d9d266124c9f851bab7927321da6637d930367e2 Signed-off-by: Thomas Devoogdt --- lib/nghttp2/CMakeLists.txt | 50 ++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/lib/nghttp2/CMakeLists.txt b/lib/nghttp2/CMakeLists.txt index ee4cb0a4a11..90c00b1dddc 100644 --- a/lib/nghttp2/CMakeLists.txt +++ b/lib/nghttp2/CMakeLists.txt @@ -24,7 +24,7 @@ cmake_minimum_required(VERSION 3.0) # XXX using 1.8.90 instead of 1.9.0-DEV -project(nghttp2 VERSION 1.58.90) +project(nghttp2 VERSION 1.58.90 LANGUAGES C) # See versioning rule: # https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html @@ -122,29 +122,31 @@ else() set(HINT_NORETURN) endif() -include(ExtractValidFlags) -foreach(_cxx1x_flag -std=c++14) - extract_valid_cxx_flags(_cxx1x_flag_supported ${_cxx1x_flag}) - if(_cxx1x_flag_supported) - set(CXX1XCXXFLAGS ${_cxx1x_flag}) - break() - endif() -endforeach() +if(NOT ENABLE_LIB_ONLY) + include(ExtractValidFlags) + foreach(_cxx1x_flag -std=c++14) + extract_valid_cxx_flags(_cxx1x_flag_supported ${_cxx1x_flag}) + if(_cxx1x_flag_supported) + set(CXX1XCXXFLAGS ${_cxx1x_flag}) + break() + endif() + endforeach() -include(CMakePushCheckState) -include(CheckCXXSourceCompiles) -cmake_push_check_state() -set(CMAKE_REQUIRED_DEFINITIONS "${CXX1XCXXFLAGS}") -# Check that std::future is available. -check_cxx_source_compiles(" -#include -#include -int main() { std::vector> v; }" HAVE_STD_FUTURE) -# Check that std::map::emplace is available for g++-4.7. -check_cxx_source_compiles(" -#include -int main() { std::map().emplace(1, 2); }" HAVE_STD_MAP_EMPLACE) -cmake_pop_check_state() + include(CMakePushCheckState) + include(CheckCXXSourceCompiles) + cmake_push_check_state() + set(CMAKE_REQUIRED_DEFINITIONS "${CXX1XCXXFLAGS}") + # Check that std::future is available. + check_cxx_source_compiles(" + #include + #include + int main() { std::vector> v; }" HAVE_STD_FUTURE) + # Check that std::map::emplace is available for g++-4.7. + check_cxx_source_compiles(" + #include + int main() { std::map().emplace(1, 2); }" HAVE_STD_MAP_EMPLACE) + cmake_pop_check_state() +endif() # Checks for libraries. @@ -177,7 +179,7 @@ endif() # openssl (for src) include(CheckSymbolExists) set(HAVE_OPENSSL ${OPENSSL_FOUND}) -if(OPENSSL_FOUND) +if(NOT ENABLE_LIB_ONLY AND OPENSSL_FOUND) set(OPENSSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR}) cmake_push_check_state() set(CMAKE_REQUIRED_INCLUDES "${OPENSSL_INCLUDE_DIR}") From dd9387e30e506b4722bc13c72f220123fc567b20 Mon Sep 17 00:00:00 2001 From: Thomas Devoogdt Date: Sun, 25 Aug 2024 20:10:27 +0200 Subject: [PATCH 4/5] lib: luajit-cmake: CMakeLists.txt: do not require a CXX compiler Signed-off-by: Thomas Devoogdt --- lib/luajit-cmake/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/luajit-cmake/CMakeLists.txt b/lib/luajit-cmake/CMakeLists.txt index 7baf878c775..051a800f524 100644 --- a/lib/luajit-cmake/CMakeLists.txt +++ b/lib/luajit-cmake/CMakeLists.txt @@ -13,7 +13,7 @@ endif() get_directory_property(hasParent PARENT_DIRECTORY) if(LUAJIT_DIR) - project(luajit) + project(luajit LANGUAGES C) include(LuaJIT.cmake) if (hasParent) set(LUA_TARGET $ PARENT_SCOPE) @@ -24,7 +24,7 @@ if(LUAJIT_DIR) endif() endif() elseif(LUA_DIR) - project(lua) + project(lua LANGUAGES C) include(lua.cmake) if (hasParent) set(LUA_TARGET $ PARENT_SCOPE) From 539bf0a853941dfaf4f5a44577e6534b379384c8 Mon Sep 17 00:00:00 2001 From: Thomas Devoogdt Date: Sun, 25 Aug 2024 20:25:19 +0200 Subject: [PATCH 5/5] workflows: add sanity check for toolchains w/ CXX support Fluent-bit is written in C, so don't require CXX, also not from the libs. Signed-off-by: Thomas Devoogdt --- .github/workflows/pr-compile-check.yaml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/workflows/pr-compile-check.yaml b/.github/workflows/pr-compile-check.yaml index 42381a8a1d1..e0ca3592148 100644 --- a/.github/workflows/pr-compile-check.yaml +++ b/.github/workflows/pr-compile-check.yaml @@ -78,3 +78,26 @@ jobs: run: | ldd ./bin/fluent-bit working-directory: build + + # Sanity check for compilation w/ CXX support + pr-compile-without-cxx: + runs-on: ubuntu-latest + timeout-minutes: 60 + strategy: + fail-fast: false + steps: + - name: Setup environment + run: | + sudo apt-get update + sudo apt-get install -y bison cmake flex gcc libssl-dev libyaml-dev + + - name: Checkout Fluent Bit code + uses: actions/checkout@v4 + + - name: Compile w/ CXX support + run: | + export CXX=/bin/false + export nparallel=$(( $(getconf _NPROCESSORS_ONLN) > 8 ? 8 : $(getconf _NPROCESSORS_ONLN) )) + cmake ../ + make -j $nparallel + working-directory: build