Skip to content

Commit 3ece184

Browse files
committed
fix: update vcpkg to get avro-cpp 1.12.1 for fmt v12 compatibility
- Update vcpkg submodule to f9d8eecab9 which has avro-cpp 1.12.1 - Update vcpkg.json baseline to match - Update setup.py VCPKG_SHA to match - Add version check in FindDepsKafkaAdapter.cmake to gracefully skip Kafka adapter on Windows if avro-cpp < 1.12.1 Signed-off-by: Krzysztof Milde <Krzysztof.Milde@Point72.com>
1 parent f064828 commit 3ece184

5 files changed

Lines changed: 49 additions & 81 deletions

File tree

cpp/cmake/modules/FindAvro.cmake

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,30 @@ find_path(Avro_INCLUDE_DIR NAMES avro/Encoder.hh)
22
find_library(Avro_LIBRARY NAMES avrocpp libavrocpp)
33

44
# =============================================================================
5-
# Extract version from library soname and check compatibility on Windows
5+
# Check for conda-forge avro-cpp fmt::formatter incompatibility on Windows
66
# =============================================================================
7-
# avro-cpp versions <= 1.12.0 have fmt::formatter with non-const format()
8-
# methods, but fmt v12+ requires const. This causes MSVC error C2766.
9-
# Require avro-cpp >= 1.12.1 on Windows which has the fix.
7+
# conda-forge's avro-cpp has fmt::formatter specializations with non-const
8+
# format() methods, but fmt v12+ requires const. This causes MSVC error C2766.
9+
#
10+
# If detected, Avro_FOUND is set to FALSE and Kafka adapter will be disabled.
1011
# =============================================================================
1112

1213
set(Avro_COMPATIBLE TRUE)
13-
set(Avro_VERSION "")
1414

15-
if(Avro_LIBRARY)
16-
get_filename_component(_avro_realpath "${Avro_LIBRARY}" REALPATH)
17-
if(_avro_realpath MATCHES "libavrocpp\\.so\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)")
18-
set(Avro_VERSION_MAJOR "${CMAKE_MATCH_1}")
19-
set(Avro_VERSION_MINOR "${CMAKE_MATCH_2}")
20-
set(Avro_VERSION_PATCH "${CMAKE_MATCH_3}")
21-
set(Avro_VERSION "${Avro_VERSION_MAJOR}.${Avro_VERSION_MINOR}.${Avro_VERSION_PATCH}")
22-
elseif(_avro_realpath MATCHES "avrocpp\\.dll")
23-
# Windows DLL doesn't have version in filename - try library name
24-
if(_avro_realpath MATCHES "([0-9]+)\\.([0-9]+)\\.([0-9]+)")
25-
set(Avro_VERSION_MAJOR "${CMAKE_MATCH_1}")
26-
set(Avro_VERSION_MINOR "${CMAKE_MATCH_2}")
27-
set(Avro_VERSION_PATCH "${CMAKE_MATCH_3}")
28-
set(Avro_VERSION "${Avro_VERSION_MAJOR}.${Avro_VERSION_MINOR}.${Avro_VERSION_PATCH}")
29-
endif()
30-
endif()
31-
32-
if(WIN32 AND NOT CSP_USE_VCPKG)
33-
if(NOT Avro_VERSION)
34-
# Could not detect version - assume buggy and skip
35-
set(Avro_COMPATIBLE FALSE)
36-
message(WARNING
37-
"Could not detect avro-cpp version on Windows. "
38-
"Kafka adapter will be disabled to avoid potential fmt::formatter incompatibility. "
39-
"Use vcpkg or upgrade to avro-cpp >= 1.12.1.")
40-
elseif(Avro_VERSION VERSION_LESS "1.12.1")
41-
set(Avro_COMPATIBLE FALSE)
42-
message(WARNING
43-
"avro-cpp ${Avro_VERSION} has incompatible fmt::formatter on Windows. "
44-
"Kafka adapter will be disabled. Upgrade to avro-cpp >= 1.12.1.")
15+
if(WIN32 AND Avro_INCLUDE_DIR AND NOT CSP_USE_VCPKG)
16+
set(_avro_node_hh "${Avro_INCLUDE_DIR}/avro/Node.hh")
17+
if(EXISTS "${_avro_node_hh}")
18+
file(READ "${_avro_node_hh}" _node_hh_content)
19+
string(FIND "${_node_hh_content}" "fmt::formatter<avro::Name>" _has_formatter)
20+
if(NOT _has_formatter EQUAL -1)
21+
# Check for non-const format() - the bug pattern
22+
string(REGEX MATCH "auto format\\([^)]+\\)[^c]*\\{" _buggy_pattern "${_node_hh_content}")
23+
if(_buggy_pattern)
24+
set(Avro_COMPATIBLE FALSE)
25+
message(WARNING
26+
"avro-cpp has incompatible fmt::formatter (non-const format()). "
27+
"Kafka adapter will be disabled. Update avro-cpp when conda-forge releases a fix.")
28+
endif()
4529
endif()
4630
endif()
4731
endif()
Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,33 @@
11
cmake_minimum_required(VERSION 3.7.2)
22

3-
# RdKafka is required for Kafka adapter
4-
find_package(RdKafka REQUIRED)
5-
6-
# Workaround for vcpkg static library transitive dependencies not propagating properly
7-
# https://github.com/microsoft/vcpkg/issues/40320
8-
if(CSP_USE_VCPKG)
9-
link_directories(${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib)
10-
endif()
11-
12-
# Avro is optional - Kafka adapter works with JSON/raw bytes without it
13-
set(CSP_KAFKA_ENABLE_AVRO FALSE)
14-
153
if (CSP_USE_VCPKG)
16-
find_package(unofficial-avro-cpp CONFIG)
17-
18-
if(unofficial-avro-cpp_FOUND)
19-
# Check avro-cpp version on Windows - require >= 1.12.1 for fmt compatibility
20-
if(WIN32 AND unofficial-avro-cpp_VERSION VERSION_LESS "1.12.1")
21-
message(WARNING
22-
"avro-cpp ${unofficial-avro-cpp_VERSION} has incompatible fmt::formatter on Windows. "
23-
"Kafka Avro support will be disabled. Update vcpkg to get avro-cpp >= 1.12.1.")
24-
else()
25-
set(CSP_KAFKA_ENABLE_AVRO TRUE)
26-
set(AVRO_LIBRARIES unofficial::avro-cpp::avrocpp CACHE INTERNAL "")
27-
endif()
4+
find_package(RdKafka CONFIG REQUIRED)
5+
find_package(unofficial-avro-cpp CONFIG REQUIRED)
6+
7+
# Check avro-cpp version on Windows - require >= 1.12.1 for fmt v12 compatibility
8+
# avro-cpp 1.12.0 has fmt::formatter with non-const format() which causes MSVC C2766
9+
if(WIN32 AND unofficial-avro-cpp_VERSION VERSION_LESS "1.12.1")
10+
message(WARNING
11+
"avro-cpp ${unofficial-avro-cpp_VERSION} has incompatible fmt::formatter on Windows. "
12+
"Kafka adapter will be disabled. Update vcpkg to get avro-cpp >= 1.12.1.")
13+
set(DepsKafkaAdapter_FOUND FALSE)
14+
return()
2815
endif()
2916

17+
if(NOT WIN32)
18+
# Bad, but a temporary workaround for
19+
# https://github.com/microsoft/vcpkg/issues/40320
20+
link_directories(${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib)
21+
endif()
22+
set(CSP_AVRO_TARGET unofficial::avro-cpp::avrocpp CACHE INTERNAL "")
23+
set(DepsKafkaAdapter_FOUND TRUE)
3024
else()
25+
find_package(RdKafka REQUIRED)
3126
find_package(Avro)
32-
33-
if(Avro_FOUND)
34-
set(CSP_KAFKA_ENABLE_AVRO TRUE)
35-
set(AVRO_LIBRARIES Avro::avrocpp CACHE INTERNAL "")
27+
if(NOT Avro_FOUND)
28+
set(DepsKafkaAdapter_FOUND FALSE)
29+
else()
30+
set(CSP_AVRO_TARGET Avro::avrocpp CACHE INTERNAL "")
31+
set(DepsKafkaAdapter_FOUND TRUE)
3632
endif()
3733
endif()
38-
39-
# Kafka adapter is available if RdKafka is found
40-
set(DepsKafkaAdapter_FOUND TRUE)

cpp/csp/adapters/kafka/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ find_package(DepsKafkaAdapter REQUIRED)
2424

2525
target_link_libraries(csp_kafka_adapter PUBLIC csp_adapter_utils RdKafka::rdkafka RdKafka::rdkafka++)
2626

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

3129
install(TARGETS csp_kafka_adapter
3230
PUBLIC_HEADER DESTINATION include/csp/adapters/kafka

cpp/csp/adapters/kafka/KafkaPublisher.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
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
76
#include <csp/adapters/utils/AvroMessageWriter.h>
8-
#endif
97

108
#include <librdkafka/rdkafkacpp.h>
119

@@ -20,10 +18,8 @@ KafkaPublisher::KafkaPublisher( KafkaAdapterManager * mgr, const Dictionary & pr
2018
auto protocol = properties.get<std::string>( "protocol" );
2119
if( protocol == "JSON" )
2220
m_msgWriter = std::make_shared<utils::JSONMessageWriter>( properties );
23-
#ifdef CSP_USE_AVRO
2421
else if( protocol == "AVRO" )
2522
m_msgWriter = std::make_shared<utils::AvroMessageWriter>( properties );
26-
#endif
2723
else if( protocol != "RAW_BYTES" )
2824
CSP_THROW( NotImplemented, "msg protocol " << protocol << " not currently supported for kafka output adapters" );
2925
}

cpp/csp/adapters/utils/CMakeLists.txt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
set(ADAPTER_UTILS_PUBLIC_HEADERS
2-
AvroMessageStructConverter.h
3-
AvroMessageWriter.h
42
JSONMessageStructConverter.h
53
JSONMessageWriter.h
64
MessageEnums.h
@@ -19,18 +17,17 @@ set(ADAPTER_UTILS_FILES
1917
RawBytesMessageStructConverter.cpp
2018
)
2119

22-
find_package(DepsKafkaAdapter REQUIRED)
23-
24-
if(CSP_KAFKA_ENABLE_AVRO)
20+
if(CSP_BUILD_KAFKA_ADAPTER)
21+
list(APPEND ADAPTER_UTILS_PUBLIC_HEADERS AvroMessageStructConverter.h AvroMessageWriter.h)
2522
list(APPEND ADAPTER_UTILS_FILES AvroMessageStructConverter.cpp)
2623
endif()
2724

2825
add_library(csp_adapter_utils STATIC ${ADAPTER_UTILS_FILES})
2926
set_target_properties(csp_adapter_utils PROPERTIES PUBLIC_HEADER "${ADAPTER_UTILS_PUBLIC_HEADERS}" PREFIX lib)
3027

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})
28+
if(CSP_BUILD_KAFKA_ADAPTER)
29+
target_compile_definitions(csp_adapter_utils PRIVATE CSP_USE_AVRO)
30+
target_link_libraries(csp_adapter_utils PUBLIC ${CSP_AVRO_TARGET})
3431
endif()
3532

3633
install(TARGETS csp_adapter_utils

0 commit comments

Comments
 (0)