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

minio-cpp: add package #5019

Merged
merged 17 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
42 changes: 42 additions & 0 deletions packages/m/minio-cpp/patches/0.3.0/cmake-pkgconfig-find-deps.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c2610db..abee1c8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -57,15 +57,16 @@ endif()
# ------------

find_package(OpenSSL REQUIRED)
-find_package(unofficial-curlpp CONFIG REQUIRED)
-find_package(unofficial-inih CONFIG REQUIRED)
+find_package(CURL REQUIRED)
+include(FindPkgConfig)
+pkg_search_module(curlpp REQUIRED IMPORTED_TARGET curlpp)
+pkg_search_module(inih REQUIRED IMPORTED_TARGET inih)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(pugixml CONFIG REQUIRED)
find_package(ZLIB REQUIRED)

list(APPEND MINIO_CPP_LIBS
- unofficial::curlpp::curlpp
- unofficial::inih::inireader
+ PkgConfig::curlpp CURL::libcurl PkgConfig::inih
nlohmann_json::nlohmann_json
pugixml
OpenSSL::SSL OpenSSL::Crypto
@@ -115,7 +116,7 @@ set(MINIO_CPP_HEADERS
include/miniocpp/utils.h
)

-add_library(miniocpp STATIC ${MINIO_CPP_SOURCES} ${MINIO_CPP_HEADERS})
+add_library(miniocpp ${MINIO_CPP_SOURCES} ${MINIO_CPP_HEADERS})
target_compile_options(miniocpp PRIVATE ${MINIO_CPP_CFLAGS})
target_compile_features(miniocpp PUBLIC cxx_std_${MINIO_CPP_STD})
target_include_directories(miniocpp PUBLIC
@@ -124,7 +125,6 @@ target_include_directories(miniocpp PUBLIC
)
target_link_libraries(miniocpp PUBLIC ${MINIO_CPP_LIBS})
set_target_properties(miniocpp PROPERTIES VERSION "${MINIO_CPP_VERSION_STRING}")
-set_target_properties(miniocpp PROPERTIES POSITION_INDEPENDENT_CODE ON)

# Add a cmake alias - this is how users should use minio-cpp in their cmake projects.
add_library(miniocpp::miniocpp ALIAS miniocpp)
15 changes: 15 additions & 0 deletions packages/m/minio-cpp/patches/0.3.0/macos-unistd.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/src/utils.cc b/src/utils.cc
index 05cb8e2..6f16a66 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -24,6 +24,10 @@
#include <corecrt.h>
#endif

+#ifndef _MSC_VER
+#include <unistd.h>
+#endif
+
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/crypto.h>
56 changes: 56 additions & 0 deletions packages/m/minio-cpp/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package("minio-cpp")
set_homepage("https://minio-cpp.min.io/")
set_description("MinIO C++ Client SDK for Amazon S3 Compatible Cloud Storage")
set_license("Apache-2.0")

add_urls("https://github.com/minio/minio-cpp/archive/refs/tags/$(version).tar.gz",
"https://github.com/minio/minio-cpp.git")

add_versions("v0.3.0", "da0f2f54bf169ad9e5e9368cc9143df4db056fc5c05bb55d8c1d9065e7211f7c")

add_patches("0.3.0", "patches/0.3.0/cmake-pkgconfig-find-deps.patch", "53a0a5a300c896ad92dbaf3b96fa25556a2f555e84ce07deb7b7b1562ddac9e5")
add_patches("0.3.0", "patches/0.3.0/macos-unistd.patch", "cd50e5d3cb5ceda7d606dc15f90ab4764b34a61a96a3be83f02688329843ef1f")

add_deps("cmake")
if is_host("windows") then
add_deps("pkgconf")
else
add_deps("pkg-config")
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块感觉可以塞进 cmake 里面去。。

Copy link
Contributor Author

@star-hengxing star-hengxing Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前是因为 patch 了 cmake,走 pkgconfig 找 xrepo 包才加,不知道有没有必要也加在 cmake。
另外我发现 cmake + pkgconfig + import target 这套好像挺稳定,或许可以用来改进 xrepo_cmake 和生成 cmakelists。


add_deps("nlohmann_json", {configs = {cmake = true}})
add_deps("inih", {configs = {ini_parser = true}})
add_deps("curlpp", "pugixml", "zlib")

on_load(function (package)
-- xrepo package: curlpp -> libcurl -> openssl
if package:is_plat("linux") then
package:add("deps", "openssl")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥其他平台用 openssl3 就不会冲突?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libcurl 在 linux 默认启用 openssl

-- we init all configurations in on_load, because package("curl") need it.
on_load(function (package)
if package:is_plat("linux", "android", "cross") then
package:config_set("openssl", true)
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那可以用 if package:dep("libcurl"):config("openssl") then 是不是更准点?

另外,既然这个包 openssl 也可以,直接全用 openssl dep 呢

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那可以用 if package:dep("libcurl"):config("openssl") then 是不是更准点?

哦哦,这个可以。

另外,既然这个包 openssl 也可以,直接全用 openssl dep 呢

一个大问题是不稳定。
库代码用到 #include <openssl/types.h> 这个是 openssl3 才有。但即使 patch 了这个头文件,ci 在某些平台会因为没找到符号报错。

else
package:add("deps", "openssl3")
end
end)

on_install("windows", "linux", "macosx", "mingw", function (package)
if package:is_plat("linux") then
io.replace("src/utils.cc", "#include <openssl/types.h>", "", {plain = true})
end

local configs = {}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
if package:is_plat("windows") and package:config("shared") then
table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
end
import("package.tools.cmake").install(package, configs)
end)

on_test(function (package)
assert(package:check_cxxsnippets({test = [[
void test() {
minio::s3::BaseUrl base_url("play.min.io");
minio::creds::StaticProvider provider("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
minio::s3::Client client(base_url, &provider);
}
]]}, {configs = {languages = "c++17"}, includes = "miniocpp/client.h"}))
end)
2 changes: 1 addition & 1 deletion packages/p/pkgconf/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ package("pkgconf")
end
end)

on_install("@macosx", "@linux", "@bsd", function(package)
on_install("@macosx", "@linux", "@bsd", "@msys", "@cygwin", function(package)
import("package.tools.autoconf").install(package)
end)

Expand Down
Loading