Skip to content

Commit 341f8d5

Browse files
authored
feat: add cpr dependency for rest catalog client (#236)
1 parent e7509f2 commit 341f8d5

File tree

11 files changed

+212
-2
lines changed

11 files changed

+212
-2
lines changed

.github/workflows/cpp-linter.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ jobs:
3434
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3535
with:
3636
fetch-depth: 0
37+
- name: Install dependencies
38+
shell: bash
39+
run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev
3740
- name: Run build
3841
run: |
3942
mkdir build && cd build

.github/workflows/sanitizer_test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ jobs:
4242
steps:
4343
- name: Checkout iceberg-cpp
4444
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
45+
- name: Install dependencies
46+
shell: bash
47+
run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev
4548
- name: Configure and Build with ASAN & UBSAN
4649
run: |
4750
mkdir build && cd build

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ jobs:
4848
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
4949
with:
5050
fetch-depth: 0
51+
- name: Install dependencies
52+
shell: bash
53+
run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev
5154
- name: Build Iceberg
5255
shell: bash
5356
run: ci/scripts/build_iceberg.sh $(pwd)
@@ -85,7 +88,7 @@ jobs:
8588
- name: Install dependencies
8689
shell: cmd
8790
run: |
88-
vcpkg install zlib:x64-windows nlohmann-json:x64-windows nanoarrow:x64-windows roaring:x64-windows
91+
vcpkg install zlib:x64-windows nlohmann-json:x64-windows nanoarrow:x64-windows roaring:x64-windows cpr:x64-windows
8992
- name: Build Iceberg
9093
shell: cmd
9194
run: |

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ option(ICEBERG_BUILD_STATIC "Build static library" ON)
3838
option(ICEBERG_BUILD_SHARED "Build shared library" OFF)
3939
option(ICEBERG_BUILD_TESTS "Build tests" ON)
4040
option(ICEBERG_BUILD_BUNDLE "Build the battery included library" ON)
41+
option(ICEBERG_BUILD_REST "Build rest catalog client" ON)
4142
option(ICEBERG_ENABLE_ASAN "Enable Address Sanitizer" OFF)
4243
option(ICEBERG_ENABLE_UBSAN "Enable Undefined Behavior Sanitizer" OFF)
4344

cmake_modules/IcebergThirdpartyToolchain.cmake

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,58 @@ function(resolve_zlib_dependency)
429429

430430
endfunction()
431431

432+
# ----------------------------------------------------------------------
433+
# cpr (C++ Requests)
434+
435+
function(resolve_cpr_dependency)
436+
prepare_fetchcontent()
437+
438+
set(CPR_BUILD_TESTS OFF)
439+
set(CPR_ENABLE_CURL_HTTP_ONLY ON)
440+
set(CPR_ENABLE_SSL ON)
441+
set(CPR_USE_SYSTEM_CURL ON)
442+
443+
fetchcontent_declare(cpr
444+
${FC_DECLARE_COMMON_OPTIONS}
445+
URL https://github.com/libcpr/cpr/archive/refs/tags/1.12.0.tar.gz
446+
FIND_PACKAGE_ARGS
447+
NAMES
448+
cpr
449+
CONFIG)
450+
451+
fetchcontent_makeavailable(cpr)
452+
453+
if(cpr_SOURCE_DIR)
454+
if(NOT TARGET cpr::cpr)
455+
add_library(cpr::cpr INTERFACE IMPORTED)
456+
target_link_libraries(cpr::cpr INTERFACE cpr)
457+
target_include_directories(cpr::cpr INTERFACE ${cpr_BINARY_DIR}
458+
${cpr_SOURCE_DIR}/include)
459+
endif()
460+
461+
set(CPR_VENDORED TRUE)
462+
set_target_properties(cpr PROPERTIES OUTPUT_NAME "iceberg_vendored_cpr"
463+
POSITION_INDEPENDENT_CODE ON)
464+
add_library(Iceberg::cpr ALIAS cpr)
465+
install(TARGETS cpr
466+
EXPORT iceberg_targets
467+
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
468+
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
469+
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
470+
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES OpenSSL)
471+
else()
472+
set(CPR_VENDORED FALSE)
473+
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES cpr)
474+
endif()
475+
476+
set(ICEBERG_SYSTEM_DEPENDENCIES
477+
${ICEBERG_SYSTEM_DEPENDENCIES}
478+
PARENT_SCOPE)
479+
set(CPR_VENDORED
480+
${CPR_VENDORED}
481+
PARENT_SCOPE)
482+
endfunction()
483+
432484
# ----------------------------------------------------------------------
433485
# Zstd
434486

@@ -454,3 +506,7 @@ if(ICEBERG_BUILD_BUNDLE)
454506
resolve_avro_dependency()
455507
resolve_zstd_dependency()
456508
endif()
509+
510+
if(ICEBERG_BUILD_REST)
511+
resolve_cpr_dependency()
512+
endif()

example/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ find_package(Iceberg CONFIG REQUIRED)
2626

2727
add_executable(demo_example demo_example.cc)
2828

29-
target_link_libraries(demo_example PRIVATE Iceberg::iceberg_bundle_static)
29+
target_link_libraries(demo_example PRIVATE Iceberg::iceberg_bundle_static
30+
Iceberg::iceberg_rest_static)

src/iceberg/IcebergConfig.cmake.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
# Iceberg::iceberg_static
2727
# Iceberg::iceberg_bundle_shared
2828
# Iceberg::iceberg_bundle_static
29+
# Iceberg::iceberg_rest_shared
30+
# Iceberg::iceberg_rest_static
2931

3032
@PACKAGE_INIT@
3133

@@ -79,6 +81,10 @@ if(NOT TARGET roaring::roaring-headers-cpp)
7981
add_library(roaring::roaring-headers-cpp INTERFACE IMPORTED)
8082
endif()
8183

84+
if(NOT TARGET CURL::libcurl)
85+
add_library(CURL::libcurl INTERFACE IMPORTED)
86+
endif()
87+
8288
include("${CMAKE_CURRENT_LIST_DIR}/IcebergTargets.cmake")
8389

8490
if(TARGET Iceberg::arrow_static)

src/iceberg/catalog/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@
1616
# under the License.
1717

1818
iceberg_install_all_headers(iceberg/catalog)
19+
20+
if(ICEBERG_BUILD_REST)
21+
add_subdirectory(rest)
22+
endif()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
set(ICEBERG_REST_SOURCES rest_catalog.cc)
19+
20+
set(ICEBERG_REST_STATIC_BUILD_INTERFACE_LIBS)
21+
set(ICEBERG_REST_SHARED_BUILD_INTERFACE_LIBS)
22+
set(ICEBERG_REST_STATIC_INSTALL_INTERFACE_LIBS)
23+
set(ICEBERG_REST_SHARED_INSTALL_INTERFACE_LIBS)
24+
25+
list(APPEND ICEBERG_REST_STATIC_BUILD_INTERFACE_LIBS
26+
"$<IF:$<TARGET_EXISTS:iceberg_static>,iceberg_static,iceberg_shared>" cpr::cpr)
27+
list(APPEND ICEBERG_REST_SHARED_BUILD_INTERFACE_LIBS
28+
"$<IF:$<TARGET_EXISTS:iceberg_shared>,iceberg_shared,iceberg_static>" cpr::cpr)
29+
list(APPEND
30+
ICEBERG_REST_STATIC_INSTALL_INTERFACE_LIBS
31+
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_static>,Iceberg::iceberg_static,Iceberg::iceberg_shared>"
32+
"$<IF:$<BOOL:${CPR_VENDORED}>,Iceberg::cpr,cpr::cpr>")
33+
list(APPEND
34+
ICEBERG_REST_SHARED_INSTALL_INTERFACE_LIBS
35+
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_shared>,Iceberg::iceberg_shared,Iceberg::iceberg_static>"
36+
"$<IF:$<BOOL:${CPR_VENDORED}>,Iceberg::cpr,cpr::cpr>")
37+
38+
add_iceberg_lib(iceberg_rest
39+
SOURCES
40+
${ICEBERG_REST_SOURCES}
41+
SHARED_LINK_LIBS
42+
${ICEBERG_REST_SHARED_BUILD_INTERFACE_LIBS}
43+
STATIC_LINK_LIBS
44+
${ICEBERG_REST_STATIC_BUILD_INTERFACE_LIBS}
45+
STATIC_INSTALL_INTERFACE_LIBS
46+
${ICEBERG_REST_STATIC_INSTALL_INTERFACE_LIBS}
47+
SHARED_INSTALL_INTERFACE_LIBS
48+
${ICEBERG_REST_SHARED_INSTALL_INTERFACE_LIBS})
49+
50+
iceberg_install_all_headers(iceberg/catalog/rest)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#include "iceberg/catalog/rest/rest_catalog.h"
21+
22+
#include <utility>
23+
24+
#include <cpr/cpr.h>
25+
26+
namespace iceberg::catalog::rest {
27+
28+
RestCatalog::RestCatalog(const std::string& base_url) : base_url_(std::move(base_url)) {}
29+
30+
cpr::Response RestCatalog::GetConfig() {
31+
cpr::Url url = cpr::Url{base_url_ + "/v1/config"};
32+
cpr::Response r = cpr::Get(url);
33+
return r;
34+
}
35+
36+
cpr::Response RestCatalog::ListNamespaces() {
37+
cpr::Url url = cpr::Url{base_url_ + "/v1/namespaces"};
38+
cpr::Response r = cpr::Get(url);
39+
return r;
40+
}
41+
42+
} // namespace iceberg::catalog::rest

0 commit comments

Comments
 (0)