Skip to content

Commit e4fc53c

Browse files
committed
fix: check avro-cpp version instead of code pattern, make Avro optional
- Extract version from library soname on conda-forge - Skip Kafka adapter on Windows if avro-cpp < 1.12.1 or version unknown - Make Avro compilation conditional with CSP_USE_AVRO define - Add vcpkg.json override to use avro-cpp 1.12.1 without full submodule update - Rename CSP_AVRO_TARGET to AVRO_LIBRARIES for consistency Signed-off-by: Krzysztof Milde <Krzysztof.Milde@Point72.com>
1 parent d2e8cf7 commit e4fc53c

7 files changed

Lines changed: 60 additions & 18 deletions

File tree

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,48 @@
11
cmake_minimum_required(VERSION 3.7.2)
22

3+
# RdKafka is required for Kafka adapter
4+
find_package(RdKafka REQUIRED)
5+
6+
# On Windows with vcpkg, librdkafka with SSL requires explicit OpenSSL linking
7+
# because vcpkg's static library transitive dependencies don't propagate properly
8+
if(WIN32 AND CSP_USE_VCPKG)
9+
find_package(OpenSSL REQUIRED)
10+
set(KAFKA_OPENSSL_LIBRARIES OpenSSL::SSL OpenSSL::Crypto CACHE INTERNAL "")
11+
else()
12+
set(KAFKA_OPENSSL_LIBRARIES "" CACHE INTERNAL "")
13+
endif()
14+
15+
# Avro is optional - Kafka adapter works with JSON/raw bytes without it
16+
set(CSP_KAFKA_ENABLE_AVRO FALSE)
17+
318
if (CSP_USE_VCPKG)
4-
find_package(RdKafka CONFIG REQUIRED)
5-
find_package(unofficial-avro-cpp CONFIG REQUIRED)
6-
if(NOT WIN32)
19+
find_package(unofficial-avro-cpp CONFIG)
20+
21+
if(unofficial-avro-cpp_FOUND)
22+
# Check avro-cpp version on Windows - require >= 1.12.1 for fmt compatibility
23+
if(WIN32 AND unofficial-avro-cpp_VERSION VERSION_LESS "1.12.1")
24+
message(WARNING
25+
"avro-cpp ${unofficial-avro-cpp_VERSION} has incompatible fmt::formatter on Windows. "
26+
"Kafka Avro support will be disabled. Update vcpkg to get avro-cpp >= 1.12.1.")
27+
else()
28+
set(CSP_KAFKA_ENABLE_AVRO TRUE)
29+
set(AVRO_LIBRARIES unofficial::avro-cpp::avrocpp CACHE INTERNAL "")
30+
endif()
31+
endif()
32+
33+
if(NOT WIN32 AND CSP_KAFKA_ENABLE_AVRO)
734
# Bad, but a temporary workaround for
835
# https://github.com/microsoft/vcpkg/issues/40320
936
link_directories(${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib)
1037
endif()
11-
set(AVRO_LIBRARIES unofficial::avro-cpp::avrocpp CACHE INTERNAL "")
12-
set(DepsKafkaAdapter_FOUND TRUE)
1338
else()
14-
find_package(RdKafka REQUIRED)
1539
find_package(Avro)
16-
if(NOT Avro_FOUND)
17-
set(DepsKafkaAdapter_FOUND FALSE)
18-
else()
40+
41+
if(Avro_FOUND)
42+
set(CSP_KAFKA_ENABLE_AVRO TRUE)
1943
set(AVRO_LIBRARIES Avro::avrocpp CACHE INTERNAL "")
20-
set(DepsKafkaAdapter_FOUND TRUE)
2144
endif()
2245
endif()
46+
47+
# Kafka adapter is available if RdKafka is found
48+
set(DepsKafkaAdapter_FOUND TRUE)

cpp/csp/adapters/kafka/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ set_target_properties(csp_kafka_adapter PROPERTIES PUBLIC_HEADER "${KAFKA_HEADER
2222

2323
find_package(DepsKafkaAdapter REQUIRED)
2424

25-
target_link_libraries(csp_kafka_adapter PUBLIC csp_adapter_utils RdKafka::rdkafka RdKafka::rdkafka++)
25+
target_link_libraries(csp_kafka_adapter PUBLIC csp_adapter_utils RdKafka::rdkafka RdKafka::rdkafka++ ${KAFKA_OPENSSL_LIBRARIES})
2626

27-
target_link_libraries(csp_kafka_adapter PUBLIC ${AVRO_LIBRARIES})
27+
if(CSP_KAFKA_ENABLE_AVRO)
28+
target_link_libraries(csp_kafka_adapter PUBLIC ${AVRO_LIBRARIES})
29+
endif()
2830

2931
install(TARGETS csp_kafka_adapter
3032
PUBLIC_HEADER DESTINATION include/csp/adapters/kafka

cpp/csp/adapters/kafka/KafkaPublisher.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include <csp/adapters/kafka/KafkaPublisher.h>
44
#include <csp/adapters/utils/MessageWriter.h>
55
#include <csp/adapters/utils/JSONMessageWriter.h>
6+
#ifdef CSP_USE_AVRO
67
#include <csp/adapters/utils/AvroMessageWriter.h>
8+
#endif
79

810
#include <librdkafka/rdkafkacpp.h>
911

@@ -18,8 +20,10 @@ KafkaPublisher::KafkaPublisher( KafkaAdapterManager * mgr, const Dictionary & pr
1820
auto protocol = properties.get<std::string>( "protocol" );
1921
if( protocol == "JSON" )
2022
m_msgWriter = std::make_shared<utils::JSONMessageWriter>( properties );
23+
#ifdef CSP_USE_AVRO
2124
else if( protocol == "AVRO" )
2225
m_msgWriter = std::make_shared<utils::AvroMessageWriter>( properties );
26+
#endif
2327
else if( protocol != "RAW_BYTES" )
2428
CSP_THROW( NotImplemented, "msg protocol " << protocol << " not currently supported for kafka output adapters" );
2529
}

cpp/csp/adapters/utils/CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,26 @@ set(ADAPTER_UTILS_PUBLIC_HEADERS
1212
)
1313

1414
set(ADAPTER_UTILS_FILES
15-
AvroMessageStructConverter.cpp
1615
JSONMessageStructConverter.cpp
1716
MessageWriter.cpp
1817
MessageEnums.cpp
1918
MessageStructConverter.cpp
2019
RawBytesMessageStructConverter.cpp
2120
)
2221

22+
find_package(DepsKafkaAdapter REQUIRED)
23+
24+
if(CSP_KAFKA_ENABLE_AVRO)
25+
list(APPEND ADAPTER_UTILS_FILES AvroMessageStructConverter.cpp)
26+
endif()
27+
2328
add_library(csp_adapter_utils STATIC ${ADAPTER_UTILS_FILES})
2429
set_target_properties(csp_adapter_utils PROPERTIES PUBLIC_HEADER "${ADAPTER_UTILS_PUBLIC_HEADERS}" PREFIX lib)
2530

26-
find_package(DepsKafkaAdapter REQUIRED)
27-
28-
target_link_libraries(csp_adapter_utils PUBLIC ${AVRO_LIBRARIES})
31+
if(CSP_KAFKA_ENABLE_AVRO)
32+
target_compile_definitions(csp_adapter_utils PUBLIC CSP_USE_AVRO)
33+
target_link_libraries(csp_adapter_utils PUBLIC ${AVRO_LIBRARIES})
34+
endif()
2935

3036
install(TARGETS csp_adapter_utils
3137
PUBLIC_HEADER DESTINATION include/csp/adapters/utils

cpp/csp/adapters/utils/MessageStructConverter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <csp/adapters/utils/MessageStructConverter.h>
2+
#ifdef CSP_USE_AVRO
23
#include <csp/adapters/utils/AvroMessageStructConverter.h>
4+
#endif
35
#include <csp/adapters/utils/JSONMessageStructConverter.h>
46
#include <csp/adapters/utils/RawBytesMessageStructConverter.h>
57

@@ -16,7 +18,9 @@ MessageStructConverterCache::MessageStructConverterCache()
1618
{
1719
registerConverter( "RAW_BYTES", &RawBytesMessageStructConverter::create );
1820
registerConverter( "JSON", &JSONMessageStructConverter::create );
21+
#ifdef CSP_USE_AVRO
1922
registerConverter( "AVRO", &AvroMessageStructConverter::create );
23+
#endif
2024
}
2125

2226
bool MessageStructConverterCache::registerConverter( std::string protocol, Creator creator )

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
else:
3939
VCPKG_TRIPLET = None
4040

41-
VCPKG_SHA = "f9d8eecab99cb23e4befb7ea90b2f9504d311b54"
41+
VCPKG_SHA = "9c5c2a0ab75aff5bcd08142525f6ff7f6f7ddeee"
4242

4343
# This will be used for e.g. the sdist
4444
if CSP_USE_VCPKG:

vcpkg

Submodule vcpkg updated 4505 files

0 commit comments

Comments
 (0)