Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pulsar-client-cpp] New port #35579

Merged
merged 13 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions ports/pulsar-client-cpp/0001-use-find-package.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fb4f1b1..1bcfd47 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -96,6 +96,7 @@ if (APPLE AND NOT LINK_STATIC)
else ()
set(LATEST_PROTOBUF FALSE)
endif ()
+set(LATEST_PROTOBUF FALSE)

if (NOT CMAKE_CXX_STANDARD)
if (LATEST_PROTOBUF)
@@ -157,14 +158,15 @@ if (LATEST_PROTOBUF)
# Use Config mode to avoid FindProtobuf.cmake does not find the Abseil library
find_package(Protobuf REQUIRED CONFIG)
else ()
- find_package(Protobuf REQUIRED)
+ find_package(protobuf CONFIG REQUIRED)
+ set(Protobuf_LIBRARIES protobuf::libprotobuf)
endif ()
message("Protobuf_INCLUDE_DIRS: " ${Protobuf_INCLUDE_DIRS})
message("Protobuf_LIBRARIES: " ${Protobuf_LIBRARIES})

# NOTE: CMake might not find curl and zlib on some platforms like Ubuntu, in this case, find them manually
set(CURL_NO_CURL_CMAKE ON)
-find_package(curl QUIET)
+find_package(CURL REQUIRED)
if (NOT CURL_FOUND)
find_path(CURL_INCLUDE_DIRS NAMES curl/curl.h)
find_library(CURL_LIBRARIES NAMES curl curllib libcurl_imp curllib_static libcurl)
@@ -175,7 +177,7 @@ if (NOT CURL_INCLUDE_DIRS OR NOT CURL_LIBRARIES)
message(FATAL_ERROR "Could not find libcurl")
endif ()

-find_package(zlib QUIET)
+find_package(ZLIB REQUIRED)
if (NOT ZLIB_FOUND)
find_path(ZLIB_INCLUDE_DIRS NAMES zlib.h)
find_library(ZLIB_LIBRARIES NAMES z zlib zdll zlib1 zlibstatic)
@@ -226,6 +228,17 @@ elseif (LINK_STATIC AND VCPKG_TRIPLET)
if (LIB_SNAPPY)
message(STATUS "Found Snappy library: ${LIB_SNAPPY}")
endif ()
+elseif (1)
+ find_package(zstd CONFIG REQUIRED)
+ set(HAS_ZSTD 1)
+ set(LIB_ZSTD
+ $<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>)
+ find_package(Snappy CONFIG REQUIRED)
+ set(HAS_SNAPPY 1)
+ set(LIB_SNAPPY Snappy::snappy)
+ if (MSVC)
+ find_package(dlfcn-win32 CONFIG REQUIRED)
+ endif ()
else()
if (MSVC AND (${CMAKE_BUILD_TYPE} STREQUAL Debug))
find_library(LIB_ZSTD zstdd HINTS "${VCPKG_DEBUG_ROOT}/lib")
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 8bd9749..551ac0c 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -31,12 +31,14 @@ include_directories(${LIB_AUTOGEN_DIR})
# Using custom command for now
set(PROTO_SOURCES ${LIB_AUTOGEN_DIR}/PulsarApi.pb.cc ${LIB_AUTOGEN_DIR}/PulsarApi.pb.h)
set(PULSAR_SOURCES ${PULSAR_SOURCES} ${PROTO_SOURCES})
-ADD_CUSTOM_COMMAND(
- OUTPUT ${PROTO_SOURCES}
- COMMAND ${PROTOC_PATH} -I ../proto ../proto/PulsarApi.proto --cpp_out=${LIB_AUTOGEN_DIR}
- DEPENDS
- ../proto/PulsarApi.proto
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+
+add_library(proto-objects OBJECT "${CMAKE_SOURCE_DIR}/proto/PulsarApi.proto")
+target_link_libraries(proto-objects PUBLIC protobuf::libprotobuf)
+target_include_directories(proto-objects PUBLIC "${LIB_AUTOGEN_DIR}")
+protobuf_generate(
+ TARGET proto-objects
+ IMPORT_DIRS "${CMAKE_SOURCE_DIR}/proto"
+ PROTOC_OUT_DIR "${LIB_AUTOGEN_DIR}")

set(LIBRARY_VERSION $ENV{PULSAR_LIBRARY_VERSION})
if (NOT LIBRARY_VERSION)
35 changes: 35 additions & 0 deletions ports/pulsar-client-cpp/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO apache/pulsar-client-cpp
REF "v${VERSION}"
SHA512 b1f56ca8d5edb7faaba68eb4e04fcb4e458ccf2c7a5b0fb6d66868c6507081344fb3f0ebb29afe9aef567295a249b09cdeb3fb00285746767bbccef65a0f6e70
HEAD_REF main
PATCHES
0001-use-find-package.patch
)

string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" BUILD_STATIC_LIB)
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" BUILD_DYNAMIC_LIB)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DBUILD_TESTS=OFF
-DBUILD_PERF_TOOLS=OFF
-DBUILD_DYNAMIC_LIB=${BUILD_DYNAMIC_LIB}
-DBUILD_STATIC_LIB=${BUILD_STATIC_LIB}
)

vcpkg_cmake_install()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin")
endif()

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
configure_file("${CMAKE_CURRENT_LIST_DIR}/usage" "${CURRENT_PACKAGES_DIR}/share/${PORT}/usage" COPYONLY)

configure_file("${CMAKE_CURRENT_LIST_DIR}/unofficial-pulsar-config.cmake" "${CURRENT_PACKAGES_DIR}/share/unofficial-pulsar/unofficial-pulsar-config.cmake" @ONLY)

vcpkg_copy_pdbs()
58 changes: 58 additions & 0 deletions ports/pulsar-client-cpp/unofficial-pulsar-config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
if (NOT TARGET unofficial::pulsar::pulsar)
get_filename_component(VCPKG_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(VCPKG_IMPORT_PREFIX "${VCPKG_IMPORT_PREFIX}" PATH)
get_filename_component(VCPKG_IMPORT_PREFIX "${VCPKG_IMPORT_PREFIX}" PATH)

find_path(_pulsar_include_dir NAMES "pulsar/Client.h" PATH ${VCPKG_IMPORT_PREFIX})
BewareMyPower marked this conversation as resolved.
Show resolved Hide resolved
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(VCPKG_IMPORT_PREFIX "${VCPKG_IMPORT_PREFIX}/debug")
endif ()
BewareMyPower marked this conversation as resolved.
Show resolved Hide resolved
if ("@VCPKG_LIBRARY_LINKAGE@" STREQUAL "dynamic")
find_library(_pulsar_library NAMES libpulsar.so libpulsar.dylib pulsar.lib PATH ${VCPKG_IMPORT_PREFIX})
set(_pulsar_link_static_library OFF)
message(STATUS "Found dynamic _pulsar_library: ${_pulsar_library}")
else ()
find_library(_pulsar_library NAMES libpulsar.a pulsar-static.lib PATH ${VCPKG_IMPORT_PREFIX})
set(_pulsar_link_static_library ON)
message(STATUS "Found static _pulsar_library: ${_pulsar_library}")
endif ()
BewareMyPower marked this conversation as resolved.
Show resolved Hide resolved
if (NOT _pulsar_include_dir OR NOT _pulsar_library)
message(FATAL_ERROR "Broken installation of vcpkg port pulsar-client-cpp")
endif ()

include(CMakeFindDependencyMacro)
find_dependency(OpenSSL)
find_dependency(ZLIB)
find_dependency(protobuf CONFIG)
find_dependency(CURL CONFIG)
find_dependency(zstd CONFIG)
find_dependency(snappy CONFIG)
if (MSVC)
find_dependency(dlfcn-win32 CONFIG)
endif ()

add_library(unofficial::pulsar::pulsar INTERFACE IMPORTED)
BewareMyPower marked this conversation as resolved.
Show resolved Hide resolved
set_target_properties(unofficial::pulsar::pulsar PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_pulsar_include_dir}"
IMPORTED_LOCATION "${_pulsar_library}")
set(DEPENDENCIES
${_pulsar_library}
BewareMyPower marked this conversation as resolved.
Show resolved Hide resolved
OpenSSL::SSL
OpenSSL::Crypto
ZLIB::ZLIB
protobuf::libprotobuf
CURL::libcurl
$<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>
Snappy::snappy
)
if (MSVC)
set(DEPENDENCIES ${DEPENDENCIES} dlfcn-win32::dl)
endif ()
if (_pulsar_link_static_library)
BewareMyPower marked this conversation as resolved.
Show resolved Hide resolved
target_compile_definitions(unofficial::pulsar::pulsar INTERFACE PULSAR_STATIC)
BewareMyPower marked this conversation as resolved.
Show resolved Hide resolved
endif ()
target_link_libraries(unofficial::pulsar::pulsar INTERFACE ${DEPENDENCIES})
BewareMyPower marked this conversation as resolved.
Show resolved Hide resolved
unset(_pulsar_link_static_library)
unset(_pulsar_library)
unset(_pulsar_include_dir)
BewareMyPower marked this conversation as resolved.
Show resolved Hide resolved
endif ()
4 changes: 4 additions & 0 deletions ports/pulsar-client-cpp/usage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pulsar-client-cpp provides CMake targets:

find_package(unofficial-pulsar CONFIG REQUIRED)
target_link_libraries(main PRIVATE unofficial::pulsar::pulsar)
48 changes: 48 additions & 0 deletions ports/pulsar-client-cpp/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "pulsar-client-cpp",
"version": "3.4.2",
"description": "The Apache Pulsar C++ library",
"homepage": "https://github.com/apache/pulsar-client-cpp",
"license": "Apache-2.0",
"supports": "!(arm & windows) & !android",
"dependencies": [
"boost-accumulators",
"boost-algorithm",
"boost-any",
"boost-asio",
"boost-circular-buffer",
"boost-date-time",
"boost-predef",
"boost-property-tree",
"boost-random",
"boost-serialization",
"boost-xpressive",
{
"name": "curl",
"default-features": false,
"features": [
"openssl"
]
},
{
"name": "dlfcn-win32",
"platform": "windows"
},
"openssl",
{
"name": "protobuf",
"version>=": "3.21.12"
},
"snappy",
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
},
"zlib",
"zstd"
]
}
4 changes: 4 additions & 0 deletions versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -6852,6 +6852,10 @@
"baseline": "1.14",
"port-version": 0
},
"pulsar-client-cpp": {
"baseline": "3.4.2",
"port-version": 0
},
"pulzed-mini": {
"baseline": "0.9.14",
"port-version": 0
Expand Down
9 changes: 9 additions & 0 deletions versions/p-/pulsar-client-cpp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "96ce7cefca9a71540014b6f2f74ba70b6094c224",
"version": "3.4.2",
"port-version": 0
}
]
}