Skip to content

Commit fd78a4a

Browse files
committed
feat: add cpr and curl dependency for REST catalog
1 parent 8779c20 commit fd78a4a

File tree

8 files changed

+175
-121
lines changed

8 files changed

+175
-121
lines changed

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: 35 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -431,87 +431,31 @@ function(resolve_zlib_dependency)
431431
endfunction()
432432

433433
# ----------------------------------------------------------------------
434-
# CURL
434+
# CURL (for cpr)
435435

436436
function(resolve_curl_dependency)
437437
prepare_fetchcontent()
438438

439-
set(BUILD_CURL_EXE
440-
OFF
441-
CACHE BOOL "" FORCE)
442-
set(BUILD_TESTING
443-
OFF
444-
CACHE BOOL "" FORCE)
445-
set(CURL_ENABLE_EXPORT_TARGET
446-
OFF
447-
CACHE BOOL "" FORCE)
448-
set(BUILD_SHARED_LIBS
449-
OFF
450-
CACHE BOOL "" FORCE)
451-
set(CURL_STATICLIB
452-
ON
453-
CACHE BOOL "" FORCE)
454-
set(HTTP_ONLY
455-
ON
456-
CACHE BOOL "" FORCE)
457-
set(CURL_DISABLE_LDAP
458-
ON
459-
CACHE BOOL "" FORCE)
460-
set(CURL_DISABLE_LDAPS
461-
ON
462-
CACHE BOOL "" FORCE)
463-
set(CURL_DISABLE_RTSP
464-
ON
465-
CACHE BOOL "" FORCE)
466-
set(CURL_DISABLE_FTP
467-
ON
468-
CACHE BOOL "" FORCE)
469-
set(CURL_DISABLE_FILE
470-
ON
471-
CACHE BOOL "" FORCE)
472-
set(CURL_DISABLE_TELNET
473-
ON
474-
CACHE BOOL "" FORCE)
475-
set(CURL_DISABLE_DICT
476-
ON
477-
CACHE BOOL "" FORCE)
478-
set(CURL_DISABLE_TFTP
479-
ON
480-
CACHE BOOL "" FORCE)
481-
set(CURL_DISABLE_GOPHER
482-
ON
483-
CACHE BOOL "" FORCE)
484-
set(CURL_DISABLE_POP3
485-
ON
486-
CACHE BOOL "" FORCE)
487-
set(CURL_DISABLE_IMAP
488-
ON
489-
CACHE BOOL "" FORCE)
490-
set(CURL_DISABLE_SMTP
491-
ON
492-
CACHE BOOL "" FORCE)
493-
set(CURL_DISABLE_SMB
494-
ON
495-
CACHE BOOL "" FORCE)
496-
set(CURL_CA_BUNDLE
497-
"auto"
498-
CACHE STRING "" FORCE)
499-
set(USE_LIBIDN2
500-
OFF
501-
CACHE BOOL "" FORCE)
502-
503-
fetchcontent_declare(CURL
439+
set(BUILD_CURL_EXE OFF)
440+
set(BUILD_SHARED_LIBS OFF)
441+
set(BUILD_TESTING OFF)
442+
set(CURL_CA_BUNDLE "auto")
443+
set(CURL_ENABLE_EXPORT_TARGET OFF)
444+
set(CURL_STATICLIB ON)
445+
set(HTTP_ONLY ON)
446+
set(USE_LIBIDN2 OFF)
447+
448+
fetchcontent_declare(curl
504449
${FC_DECLARE_COMMON_OPTIONS}
505-
GIT_REPOSITORY https://github.com/curl/curl.git
506-
GIT_TAG curl-8_11_0
507-
FIND_PACKAGE_ARGS
508-
NAMES
509-
CURL
510-
CONFIG)
450+
URL https://curl.se/download/curl-8.11.0.tar.gz FIND_PACKAGE_ARGS
451+
NAMES curl)
511452

512453
fetchcontent_makeavailable(CURL)
513454

514455
if(curl_SOURCE_DIR)
456+
set(CURL_VERSION_STRING
457+
"8.11.0"
458+
PARENT_SCOPE)
515459
if(NOT TARGET CURL::libcurl)
516460
add_library(CURL::libcurl INTERFACE IMPORTED)
517461
target_link_libraries(CURL::libcurl INTERFACE libcurl_static)
@@ -529,6 +473,9 @@ function(resolve_curl_dependency)
529473
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
530474
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
531475
message(STATUS "Use vendored CURL")
476+
477+
# curl depends on the system installed OpenSSL
478+
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES OpenSSL)
532479
else()
533480
set(CURL_VENDORED FALSE)
534481
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES CURL)
@@ -544,53 +491,27 @@ function(resolve_curl_dependency)
544491
endfunction()
545492

546493
# ----------------------------------------------------------------------
547-
# cpr
494+
# cpr (C++ Requests)
548495

549496
function(resolve_cpr_dependency)
550497
prepare_fetchcontent()
551498

552-
set(CPR_BUILD_TESTS
553-
OFF
554-
CACHE BOOL "" FORCE)
555-
set(CPR_BUILD_TESTS_SSL
556-
OFF
557-
CACHE BOOL "" FORCE)
558-
set(CPR_ENABLE_SSL
559-
ON
560-
CACHE BOOL "" FORCE)
561-
set(CPR_USE_SYSTEM_CURL
562-
ON
563-
CACHE BOOL "" FORCE)
564-
set(CPR_CURL_NOSIGNAL
565-
ON
566-
CACHE BOOL "" FORCE)
567-
568-
set(CURL_VERSION_STRING
569-
"8.11.0"
570-
CACHE STRING "" FORCE)
571-
set(CURL_LIB
572-
"CURL::libcurl"
573-
CACHE STRING "" FORCE)
499+
set(CPR_BUILD_TESTS OFF)
500+
set(CPR_BUILD_TESTS_SSL OFF)
501+
set(CPR_ENABLE_SSL ON)
502+
set(CPR_USE_SYSTEM_CURL ON)
503+
set(CPR_CURL_NOSIGNAL ON)
574504

575505
fetchcontent_declare(cpr
576506
${FC_DECLARE_COMMON_OPTIONS}
577-
GIT_REPOSITORY https://github.com/libcpr/cpr.git
578-
GIT_TAG 1.11.0
579-
FIND_PACKAGE_ARGS
580-
NAMES
581-
cpr
582-
CONFIG)
583-
584-
# Create a custom install command that does nothing
585-
# function(install)
586-
# # Do nothing - effectively disables install
587-
# endfunction()
507+
URL https://github.com/libcpr/cpr/archive/refs/tags/1.12.0.tar.gz
508+
FIND_PACKAGE_ARGS
509+
NAMES
510+
cpr
511+
CONFIG)
588512

589513
fetchcontent_makeavailable(cpr)
590514

591-
# Restore the original install function
592-
# unset(install)
593-
594515
if(cpr_SOURCE_DIR)
595516
if(NOT TARGET cpr::cpr)
596517
add_library(cpr::cpr INTERFACE IMPORTED)
@@ -641,11 +562,13 @@ resolve_croaring_dependency()
641562
resolve_nlohmann_json_dependency()
642563
resolve_spdlog_dependency()
643564

644-
resolve_curl_dependency()
645-
resolve_cpr_dependency()
646-
647565
if(ICEBERG_BUILD_BUNDLE)
648566
resolve_arrow_dependency()
649567
resolve_avro_dependency()
650568
resolve_zstd_dependency()
651569
endif()
570+
571+
if(ICEBERG_BUILD_REST)
572+
resolve_curl_dependency()
573+
resolve_cpr_dependency()
574+
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/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,13 @@ if(ICEBERG_BUILD_BUNDLE)
133133
list(APPEND
134134
ICEBERG_BUNDLE_STATIC_BUILD_INTERFACE_LIBS
135135
"$<IF:$<TARGET_EXISTS:iceberg_static>,iceberg_static,iceberg_shared>"
136-
"$<IF:$<TARGET_EXISTS:CURL::libcurl>,CURL::libcurl,CURL::libcurl>"
137-
"$<IF:$<TARGET_EXISTS:cpr::cpr>,cpr::cpr,cpr::cpr>"
138136
"$<IF:$<TARGET_EXISTS:Arrow::arrow_static>,Arrow::arrow_static,Arrow::arrow_shared>"
139137
"$<IF:$<TARGET_EXISTS:Parquet::parquet_static>,Parquet::parquet_static,Parquet::parquet_shared>"
140138
"$<IF:$<TARGET_EXISTS:avro-cpp::avrocpp_static>,avro-cpp::avrocpp_static,avro-cpp::avrocpp_shared>"
141139
)
142140
list(APPEND
143141
ICEBERG_BUNDLE_SHARED_BUILD_INTERFACE_LIBS
144142
"$<IF:$<TARGET_EXISTS:iceberg_shared>,iceberg_shared,iceberg_static>"
145-
"$<IF:$<TARGET_EXISTS:CURL::libcurl>,CURL::libcurl,CURL::libcurl>"
146-
"$<IF:$<TARGET_EXISTS:cpr::cpr>,cpr::cpr,cpr::cpr>"
147143
"$<IF:$<TARGET_EXISTS:Arrow::arrow_shared>,Arrow::arrow_shared,Arrow::arrow_static>"
148144
"$<IF:$<TARGET_EXISTS:Parquet::parquet_shared>,Parquet::parquet_shared,Parquet::parquet_static>"
149145
"$<IF:$<TARGET_EXISTS:avro-cpp::avrocpp_shared>,avro-cpp::avrocpp_shared,avro-cpp::avrocpp_static>"
@@ -152,17 +148,13 @@ if(ICEBERG_BUILD_BUNDLE)
152148
list(APPEND
153149
ICEBERG_BUNDLE_STATIC_INSTALL_INTERFACE_LIBS
154150
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_static>,Iceberg::iceberg_static,Iceberg::iceberg_shared>"
155-
"$<IF:$<BOOL:${CURL_VENDORED}>,Iceberg::libcurl_static,$<IF:$<TARGET_EXISTS:CURL::libcurl>,CURL::libcurl,CURL::libcurl>>"
156-
"$<IF:$<BOOL:${CPR_VENDORED}>,Iceberg::cpr,$<IF:$<TARGET_EXISTS:cpr::cpr>,cpr::cpr,cpr::cpr>>"
157151
"$<IF:$<BOOL:${ARROW_VENDORED}>,Iceberg::arrow_static,$<IF:$<TARGET_EXISTS:Arrow::arrow_static>,Arrow::arrow_static,Arrow::arrow_shared>>"
158152
"$<IF:$<BOOL:${ARROW_VENDORED}>,Iceberg::parquet_static,$<IF:$<TARGET_EXISTS:Parquet::parquet_static>,Parquet::parquet_static,Parquet::parquet_shared>>"
159153
"$<IF:$<BOOL:${AVRO_VENDORED}>,Iceberg::avrocpp_s,$<IF:$<TARGET_EXISTS:avro-cpp::avrocpp_static>,avro-cpp::avrocpp_static,avro-cpp::avrocpp_shared>>"
160154
)
161155
list(APPEND
162156
ICEBERG_BUNDLE_SHARED_INSTALL_INTERFACE_LIBS
163157
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_shared>,Iceberg::iceberg_shared,Iceberg::iceberg_static>"
164-
"$<IF:$<BOOL:${CURL_VENDORED}>,Iceberg::libcurl_static,$<IF:$<TARGET_EXISTS:CURL::libcurl>,CURL::libcurl,CURL::libcurl>>"
165-
"$<IF:$<BOOL:${CPR_VENDORED}>,Iceberg::cpr,$<IF:$<TARGET_EXISTS:cpr::cpr>,cpr::cpr,cpr::cpr>>"
166158
"$<IF:$<BOOL:${ARROW_VENDORED}>,Iceberg::arrow_static,$<IF:$<TARGET_EXISTS:Arrow::arrow_shared>,Arrow::arrow_shared,Arrow::arrow_static>>"
167159
"$<IF:$<BOOL:${ARROW_VENDORED}>,Iceberg::parquet_static,$<IF:$<TARGET_EXISTS:Parquet::parquet_shared>,Parquet::parquet_shared,Parquet::parquet_static>>"
168160
"$<IF:$<BOOL:${AVRO_VENDORED}>,Iceberg::avrocpp_s,$<IF:$<TARGET_EXISTS:avro-cpp::avrocpp_shared>,avro-cpp::avrocpp_shared,avro-cpp::avrocpp_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
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
#pragma once
19+
20+
#include <string>
21+
22+
#include <cpr/cpr.h>
23+
24+
#include "iceberg/catalog/rest/iceberg_rest_export.h"
25+
26+
namespace iceberg::catalog::rest {
27+
28+
class ICEBERG_REST_EXPORT RestCatalog {
29+
public:
30+
explicit RestCatalog(const std::string& base_url);
31+
~RestCatalog() = default;
32+
33+
cpr::Response GetConfig();
34+
35+
cpr::Response ListNamespaces();
36+
37+
private:
38+
std::string base_url_;
39+
};
40+
41+
} // namespace iceberg::catalog::rest

0 commit comments

Comments
 (0)