This is an automated email from the ASF dual-hosted git repository.

fokko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-cpp.git


The following commit(s) were added to refs/heads/main by this push:
     new 341f8d5  feat: add cpr dependency for rest catalog client (#236)
341f8d5 is described below

commit 341f8d586722557691346e233600c27d3b808d8d
Author: Li Feiyang <lifeiy...@zju.edu.cn>
AuthorDate: Thu Sep 25 17:38:36 2025 +0800

    feat: add cpr dependency for rest catalog client (#236)
---
 .github/workflows/cpp-linter.yml               |  3 ++
 .github/workflows/sanitizer_test.yml           |  3 ++
 .github/workflows/test.yml                     |  5 ++-
 CMakeLists.txt                                 |  1 +
 cmake_modules/IcebergThirdpartyToolchain.cmake | 56 ++++++++++++++++++++++++++
 example/CMakeLists.txt                         |  3 +-
 src/iceberg/IcebergConfig.cmake.in             |  6 +++
 src/iceberg/catalog/CMakeLists.txt             |  4 ++
 src/iceberg/catalog/rest/CMakeLists.txt        | 50 +++++++++++++++++++++++
 src/iceberg/catalog/rest/rest_catalog.cc       | 42 +++++++++++++++++++
 src/iceberg/catalog/rest/rest_catalog.h        | 41 +++++++++++++++++++
 11 files changed, 212 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml
index 3a4a6d2..7899f31 100644
--- a/.github/workflows/cpp-linter.yml
+++ b/.github/workflows/cpp-linter.yml
@@ -34,6 +34,9 @@ jobs:
         uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # 
v5.0.0
         with:
           fetch-depth: 0
+      - name: Install dependencies
+        shell: bash
+        run: sudo apt-get update && sudo apt-get install -y 
libcurl4-openssl-dev
       - name: Run build
         run: |
           mkdir build && cd build
diff --git a/.github/workflows/sanitizer_test.yml 
b/.github/workflows/sanitizer_test.yml
index 11fda10..66760dd 100644
--- a/.github/workflows/sanitizer_test.yml
+++ b/.github/workflows/sanitizer_test.yml
@@ -42,6 +42,9 @@ jobs:
     steps:
       - name: Checkout iceberg-cpp
         uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # 
v5.0.0
+      - name: Install dependencies
+        shell: bash
+        run: sudo apt-get update && sudo apt-get install -y 
libcurl4-openssl-dev
       - name: Configure and Build with ASAN & UBSAN
         run: |
           mkdir build && cd build
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 7b383b2..15daa87 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -48,6 +48,9 @@ jobs:
         uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # 
v5.0.0
         with:
           fetch-depth: 0
+      - name: Install dependencies
+        shell: bash
+        run: sudo apt-get update && sudo apt-get install -y 
libcurl4-openssl-dev
       - name: Build Iceberg
         shell: bash
         run: ci/scripts/build_iceberg.sh $(pwd)
@@ -85,7 +88,7 @@ jobs:
       - name: Install dependencies
         shell: cmd
         run: |
-          vcpkg install zlib:x64-windows nlohmann-json:x64-windows 
nanoarrow:x64-windows roaring:x64-windows
+          vcpkg install zlib:x64-windows nlohmann-json:x64-windows 
nanoarrow:x64-windows roaring:x64-windows cpr:x64-windows
       - name: Build Iceberg
         shell: cmd
         run: |
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f5f7643..57ce410 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -38,6 +38,7 @@ option(ICEBERG_BUILD_STATIC "Build static library" ON)
 option(ICEBERG_BUILD_SHARED "Build shared library" OFF)
 option(ICEBERG_BUILD_TESTS "Build tests" ON)
 option(ICEBERG_BUILD_BUNDLE "Build the battery included library" ON)
+option(ICEBERG_BUILD_REST "Build rest catalog client" ON)
 option(ICEBERG_ENABLE_ASAN "Enable Address Sanitizer" OFF)
 option(ICEBERG_ENABLE_UBSAN "Enable Undefined Behavior Sanitizer" OFF)
 
diff --git a/cmake_modules/IcebergThirdpartyToolchain.cmake 
b/cmake_modules/IcebergThirdpartyToolchain.cmake
index 3f3abf5..793af7f 100644
--- a/cmake_modules/IcebergThirdpartyToolchain.cmake
+++ b/cmake_modules/IcebergThirdpartyToolchain.cmake
@@ -429,6 +429,58 @@ function(resolve_zlib_dependency)
 
 endfunction()
 
+# ----------------------------------------------------------------------
+# cpr (C++ Requests)
+
+function(resolve_cpr_dependency)
+  prepare_fetchcontent()
+
+  set(CPR_BUILD_TESTS OFF)
+  set(CPR_ENABLE_CURL_HTTP_ONLY ON)
+  set(CPR_ENABLE_SSL ON)
+  set(CPR_USE_SYSTEM_CURL ON)
+
+  fetchcontent_declare(cpr
+                       ${FC_DECLARE_COMMON_OPTIONS}
+                       URL 
https://github.com/libcpr/cpr/archive/refs/tags/1.12.0.tar.gz
+                           FIND_PACKAGE_ARGS
+                           NAMES
+                           cpr
+                           CONFIG)
+
+  fetchcontent_makeavailable(cpr)
+
+  if(cpr_SOURCE_DIR)
+    if(NOT TARGET cpr::cpr)
+      add_library(cpr::cpr INTERFACE IMPORTED)
+      target_link_libraries(cpr::cpr INTERFACE cpr)
+      target_include_directories(cpr::cpr INTERFACE ${cpr_BINARY_DIR}
+                                                    ${cpr_SOURCE_DIR}/include)
+    endif()
+
+    set(CPR_VENDORED TRUE)
+    set_target_properties(cpr PROPERTIES OUTPUT_NAME "iceberg_vendored_cpr"
+                                         POSITION_INDEPENDENT_CODE ON)
+    add_library(Iceberg::cpr ALIAS cpr)
+    install(TARGETS cpr
+            EXPORT iceberg_targets
+            RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
+            ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
+            LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
+    list(APPEND ICEBERG_SYSTEM_DEPENDENCIES OpenSSL)
+  else()
+    set(CPR_VENDORED FALSE)
+    list(APPEND ICEBERG_SYSTEM_DEPENDENCIES cpr)
+  endif()
+
+  set(ICEBERG_SYSTEM_DEPENDENCIES
+      ${ICEBERG_SYSTEM_DEPENDENCIES}
+      PARENT_SCOPE)
+  set(CPR_VENDORED
+      ${CPR_VENDORED}
+      PARENT_SCOPE)
+endfunction()
+
 # ----------------------------------------------------------------------
 # Zstd
 
@@ -454,3 +506,7 @@ if(ICEBERG_BUILD_BUNDLE)
   resolve_avro_dependency()
   resolve_zstd_dependency()
 endif()
+
+if(ICEBERG_BUILD_REST)
+  resolve_cpr_dependency()
+endif()
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index 3e178a8..d120d50 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -26,4 +26,5 @@ find_package(Iceberg CONFIG REQUIRED)
 
 add_executable(demo_example demo_example.cc)
 
-target_link_libraries(demo_example PRIVATE Iceberg::iceberg_bundle_static)
+target_link_libraries(demo_example PRIVATE Iceberg::iceberg_bundle_static
+                                           Iceberg::iceberg_rest_static)
diff --git a/src/iceberg/IcebergConfig.cmake.in 
b/src/iceberg/IcebergConfig.cmake.in
index c22682d..5858566 100644
--- a/src/iceberg/IcebergConfig.cmake.in
+++ b/src/iceberg/IcebergConfig.cmake.in
@@ -26,6 +26,8 @@
 #   Iceberg::iceberg_static
 #   Iceberg::iceberg_bundle_shared
 #   Iceberg::iceberg_bundle_static
+#   Iceberg::iceberg_rest_shared
+#   Iceberg::iceberg_rest_static
 
 @PACKAGE_INIT@
 
@@ -79,6 +81,10 @@ if(NOT TARGET roaring::roaring-headers-cpp)
   add_library(roaring::roaring-headers-cpp INTERFACE IMPORTED)
 endif()
 
+if(NOT TARGET CURL::libcurl)
+  add_library(CURL::libcurl INTERFACE IMPORTED)
+endif()
+
 include("${CMAKE_CURRENT_LIST_DIR}/IcebergTargets.cmake")
 
 if(TARGET Iceberg::arrow_static)
diff --git a/src/iceberg/catalog/CMakeLists.txt 
b/src/iceberg/catalog/CMakeLists.txt
index ec53e84..9e11eee 100644
--- a/src/iceberg/catalog/CMakeLists.txt
+++ b/src/iceberg/catalog/CMakeLists.txt
@@ -16,3 +16,7 @@
 # under the License.
 
 iceberg_install_all_headers(iceberg/catalog)
+
+if(ICEBERG_BUILD_REST)
+  add_subdirectory(rest)
+endif()
diff --git a/src/iceberg/catalog/rest/CMakeLists.txt 
b/src/iceberg/catalog/rest/CMakeLists.txt
new file mode 100644
index 0000000..f18859c
--- /dev/null
+++ b/src/iceberg/catalog/rest/CMakeLists.txt
@@ -0,0 +1,50 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set(ICEBERG_REST_SOURCES rest_catalog.cc)
+
+set(ICEBERG_REST_STATIC_BUILD_INTERFACE_LIBS)
+set(ICEBERG_REST_SHARED_BUILD_INTERFACE_LIBS)
+set(ICEBERG_REST_STATIC_INSTALL_INTERFACE_LIBS)
+set(ICEBERG_REST_SHARED_INSTALL_INTERFACE_LIBS)
+
+list(APPEND ICEBERG_REST_STATIC_BUILD_INTERFACE_LIBS
+     "$<IF:$<TARGET_EXISTS:iceberg_static>,iceberg_static,iceberg_shared>" 
cpr::cpr)
+list(APPEND ICEBERG_REST_SHARED_BUILD_INTERFACE_LIBS
+     "$<IF:$<TARGET_EXISTS:iceberg_shared>,iceberg_shared,iceberg_static>" 
cpr::cpr)
+list(APPEND
+     ICEBERG_REST_STATIC_INSTALL_INTERFACE_LIBS
+     
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_static>,Iceberg::iceberg_static,Iceberg::iceberg_shared>"
+     "$<IF:$<BOOL:${CPR_VENDORED}>,Iceberg::cpr,cpr::cpr>")
+list(APPEND
+     ICEBERG_REST_SHARED_INSTALL_INTERFACE_LIBS
+     
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_shared>,Iceberg::iceberg_shared,Iceberg::iceberg_static>"
+     "$<IF:$<BOOL:${CPR_VENDORED}>,Iceberg::cpr,cpr::cpr>")
+
+add_iceberg_lib(iceberg_rest
+                SOURCES
+                ${ICEBERG_REST_SOURCES}
+                SHARED_LINK_LIBS
+                ${ICEBERG_REST_SHARED_BUILD_INTERFACE_LIBS}
+                STATIC_LINK_LIBS
+                ${ICEBERG_REST_STATIC_BUILD_INTERFACE_LIBS}
+                STATIC_INSTALL_INTERFACE_LIBS
+                ${ICEBERG_REST_STATIC_INSTALL_INTERFACE_LIBS}
+                SHARED_INSTALL_INTERFACE_LIBS
+                ${ICEBERG_REST_SHARED_INSTALL_INTERFACE_LIBS})
+
+iceberg_install_all_headers(iceberg/catalog/rest)
diff --git a/src/iceberg/catalog/rest/rest_catalog.cc 
b/src/iceberg/catalog/rest/rest_catalog.cc
new file mode 100644
index 0000000..a9b18b5
--- /dev/null
+++ b/src/iceberg/catalog/rest/rest_catalog.cc
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "iceberg/catalog/rest/rest_catalog.h"
+
+#include <utility>
+
+#include <cpr/cpr.h>
+
+namespace iceberg::catalog::rest {
+
+RestCatalog::RestCatalog(const std::string& base_url) : 
base_url_(std::move(base_url)) {}
+
+cpr::Response RestCatalog::GetConfig() {
+  cpr::Url url = cpr::Url{base_url_ + "/v1/config"};
+  cpr::Response r = cpr::Get(url);
+  return r;
+}
+
+cpr::Response RestCatalog::ListNamespaces() {
+  cpr::Url url = cpr::Url{base_url_ + "/v1/namespaces"};
+  cpr::Response r = cpr::Get(url);
+  return r;
+}
+
+}  // namespace iceberg::catalog::rest
diff --git a/src/iceberg/catalog/rest/rest_catalog.h 
b/src/iceberg/catalog/rest/rest_catalog.h
new file mode 100644
index 0000000..7b3e205
--- /dev/null
+++ b/src/iceberg/catalog/rest/rest_catalog.h
@@ -0,0 +1,41 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <string>
+
+#include <cpr/cpr.h>
+
+#include "iceberg/catalog/rest/iceberg_rest_export.h"
+
+namespace iceberg::catalog::rest {
+
+class ICEBERG_REST_EXPORT RestCatalog {
+ public:
+  explicit RestCatalog(const std::string& base_url);
+  ~RestCatalog() = default;
+
+  cpr::Response GetConfig();
+
+  cpr::Response ListNamespaces();
+
+ private:
+  std::string base_url_;
+};
+
+}  // namespace iceberg::catalog::rest

Reply via email to