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

Add iceberg_arrow library #6

Merged
merged 34 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
65021dc
Add iceberg_arrow library
wgtmac Dec 6, 2024
f84b307
fix linux build
wgtmac Dec 26, 2024
2cfd715
use internal cmake variables
wgtmac Dec 26, 2024
10ef3e5
fix windows build
wgtmac Dec 26, 2024
200bd2f
fix msvc build to not add _static suffix
wgtmac Dec 26, 2024
b750758
remove MSVC_TOOLCHAIN
wgtmac Dec 27, 2024
4e766d9
simplify ThirdpartyToolchain.cmake
wgtmac Dec 31, 2024
2866d6e
use same target
wgtmac Dec 31, 2024
5183981
simplify vendored lib
wgtmac Dec 31, 2024
312b13d
use PackageNameConfig
wgtmac Dec 31, 2024
3c5bdfb
Update README.md
wgtmac Dec 31, 2024
a6abfd4
Update cmake_modules/ThirdpartyToolchain.cmake
wgtmac Dec 31, 2024
8c09208
Update src/arrow/CMakeLists.txt
wgtmac Dec 31, 2024
80e0a4b
let libiceberg_arrow depend on libiceberg_core
wgtmac Jan 1, 2025
5a064c9
add back MSVC_TOOLCHAIN
wgtmac Jan 1, 2025
93c4228
try to fix windows build
wgtmac Jan 1, 2025
fdc0294
add visibility.h
wgtmac Jan 1, 2025
3f6df87
move iceberg_core location
wgtmac Jan 1, 2025
cbd661d
link core to puffin & arrow
wgtmac Jan 1, 2025
38a9259
let iceberg_arrow to call api from iceberg_core
wgtmac Jan 1, 2025
59bb135
remove api folder
wgtmac Jan 2, 2025
64c8e29
fix lint
wgtmac Jan 2, 2025
0d337bd
use generate_export_header
wgtmac Jan 2, 2025
149ed21
fix cmake lint
wgtmac Jan 2, 2025
2cb3dc9
add STATIC_DEFINE
wgtmac Jan 2, 2025
d88b5ee
try to fix windows export
wgtmac Jan 2, 2025
79bba23
try to fix windows export
wgtmac Jan 2, 2025
be17441
try to fix windows export
wgtmac Jan 2, 2025
254bebe
use instead of
wgtmac Jan 3, 2025
24acdac
remove definition of LIB_NAME_shared_EXPORTS
wgtmac Jan 3, 2025
e31ae78
Revert "remove definition of LIB_NAME_shared_EXPORTS"
wgtmac Jan 3, 2025
4553485
remove shared_EXPORTS
wgtmac Jan 6, 2025
9c065c6
fix lint
wgtmac Jan 6, 2025
343aa9b
Update cmake_modules/BuildUtils.cmake
wgtmac Jan 7, 2025
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
24 changes: 14 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules")
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules")

project(iceberg
project(Iceberg
VERSION 0.1.0
DESCRIPTION "Iceberg C++ Project"
LANGUAGES CXX)
Expand All @@ -36,22 +36,26 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
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_ARROW "Build Arrow" ON)

include(CMakePackageConfigHelpers)
include(CMakeParseArguments)
include(BuildUtils)
include(ExternalProject)
include(FindPackageHandleStandardArgs)
include(GNUInstallDirs)

set(ICEBERG_API_DIR "${CMAKE_SOURCE_DIR}/api")
set(ICEBERG_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
set(ICEBERG_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}")
set(ICEBERG_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
set(ICEBERG_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake")
set(ICEBERG_INSTALL_DOCDIR "share/doc/${PROJECT_NAME}")

add_subdirectory(api)
if(WIN32 AND NOT MINGW)
set(MSVC_TOOLCHAIN TRUE)
else()
set(MSVC_TOOLCHAIN FALSE)
endif()

include(CMakeParseArguments)
include(BuildUtils)
include(ThirdpartyToolchain)
include(GenerateExportHeader)

add_subdirectory(src)

if(ICEBERG_BUILD_TESTS)
Expand Down
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,27 @@ C++ implementation of [Apache Iceberg™](https://iceberg.apache.org/).

```bash
cd iceberg-cpp
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/tmp/iceberg -DICEBERG_BUILD_STATIC=ON -DICEBERG_BUILD_SHARED=ON
cmake --build .
cmake --install .
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install -DICEBERG_BUILD_STATIC=ON -DICEBERG_BUILD_SHARED=ON
cmake --build build
cmake --install build
```

### Build and Install Iceberg Arrow Library

#### Vendored Apache Arrow (default)

```bash
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install -DICEBERG_ARROW=ON
cmake --build build
cmake --install build
```

#### Provided Apache Arrow

```bash
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install -DCMAKE_PREFIX_PATH=/path/to/arrow -DICEBERG_ARROW=ON
cmake --build build
cmake --install build
```

### Build Examples
Expand All @@ -44,9 +61,14 @@ After installing the core libraries, you can build the examples:

```bash
cd iceberg-cpp/example
mkdir build && cd build
cmake .. -DCMAKE_PREFIX_PATH=/tmp/iceberg
cmake --build .
cmake -S . -B build -DCMAKE_PREFIX_PATH=/path/to/install
cmake --build build
```

If you are using provided Apache Arrow, you need to include `/path/to/arrow` in `CMAKE_PREFIX_PATH` as below.

```bash
cmake -S . -B build -DCMAKE_PREFIX_PATH="/path/to/install;/path/to/arrow"
```

## Contribute
Expand Down
21 changes: 0 additions & 21 deletions api/CMakeLists.txt

This file was deleted.

50 changes: 42 additions & 8 deletions cmake_modules/BuildUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# Borrowed the file from Apache Arrow:
# https://github.com/apache/arrow/blob/main/cpp/cmake_modules/BuildUtils.cmake

include(CMakePackageConfigHelpers)

function(iceberg_install_cmake_package PACKAGE_NAME EXPORT_NAME)
set(CONFIG_CMAKE "${PACKAGE_NAME}Config.cmake")
set(BUILT_CONFIG_CMAKE "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_CMAKE}")
Expand All @@ -37,12 +39,11 @@ function(iceberg_install_cmake_package PACKAGE_NAME EXPORT_NAME)
FILE "${TARGETS_CMAKE}")
endfunction()

function(ADD_ICEBERG_LIB LIB_NAME)
function(add_iceberg_lib LIB_NAME)
set(options)
set(one_value_args
BUILD_SHARED
BUILD_STATIC
CMAKE_PACKAGE_NAME
INSTALL_ARCHIVE_DIR
INSTALL_LIBRARY_DIR
INSTALL_RUNTIME_DIR
Expand Down Expand Up @@ -146,8 +147,8 @@ function(ADD_ICEBERG_LIB LIB_NAME)
"$<INSTALL_INTERFACE:${ARG_SHARED_INSTALL_INTERFACE_LIBS}>"
PRIVATE ${ARG_SHARED_PRIVATE_LINK_LIBS})

install(TARGETS ${LIB_NAME}_shared ${INSTALL_IS_OPTIONAL}
EXPORT ${LIB_NAME}_targets
install(TARGETS ${LIB_NAME}_shared
EXPORT iceberg_targets
ARCHIVE DESTINATION ${INSTALL_ARCHIVE_DIR}
LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR}
RUNTIME DESTINATION ${INSTALL_RUNTIME_DIR}
Expand Down Expand Up @@ -201,17 +202,25 @@ function(ADD_ICEBERG_LIB LIB_NAME)
PUBLIC "$<BUILD_INTERFACE:${ARG_STATIC_LINK_LIBS}>")
endif()

install(TARGETS ${LIB_NAME}_static ${INSTALL_IS_OPTIONAL}
EXPORT ${LIB_NAME}_targets
install(TARGETS ${LIB_NAME}_static
EXPORT iceberg_targets
ARCHIVE DESTINATION ${INSTALL_ARCHIVE_DIR}
LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR}
RUNTIME DESTINATION ${INSTALL_RUNTIME_DIR}
INCLUDES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()

if(ARG_CMAKE_PACKAGE_NAME)
iceberg_install_cmake_package(${ARG_CMAKE_PACKAGE_NAME} ${LIB_NAME}_targets)
# generate export header file
if(BUILD_SHARED)
generate_export_header(${LIB_NAME}_shared BASE_NAME ${LIB_NAME})
if(BUILD_STATIC)
string(TOUPPER ${LIB_NAME} LIB_NAME_UPPER)
target_compile_definitions(${LIB_NAME}_static
PUBLIC ${LIB_NAME_UPPER}_STATIC_DEFINE)
endif()
elseif(BUILD_STATIC)
generate_export_header(${LIB_NAME}_static BASE_NAME ${LIB_NAME})
endif()

# Modify variable in calling scope
Expand All @@ -221,3 +230,28 @@ function(ADD_ICEBERG_LIB LIB_NAME)
PARENT_SCOPE)
endif()
endfunction()

function(iceberg_install_all_headers PATH)
set(options)
set(one_value_args)
set(multi_value_args PATTERN)
cmake_parse_arguments(ARG
"${options}"
"${one_value_args}"
"${multi_value_args}"
${ARGN})
if(NOT ARG_PATTERN)
set(ARG_PATTERN "*.h" "*.hpp")
endif()
file(GLOB CURRENT_DIRECTORY_HEADERS ${ARG_PATTERN})

set(PUBLIC_HEADERS)
foreach(HEADER ${CURRENT_DIRECTORY_HEADERS})
get_filename_component(HEADER_BASENAME ${HEADER} NAME)
if(HEADER_BASENAME MATCHES "internal")
continue()
endif()
list(APPEND PUBLIC_HEADERS ${HEADER})
endforeach()
install(FILES ${PUBLIC_HEADERS} DESTINATION "${ICEBERG_INSTALL_INCLUDEDIR}/${PATH}")
endfunction()
132 changes: 132 additions & 0 deletions cmake_modules/ThirdpartyToolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# 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.

# Accumulate all dependencies to provide suitable static link parameters to the
# third party libraries.
set(ICEBERG_SYSTEM_DEPENDENCIES)
set(ICEBERG_ARROW_INSTALL_INTERFACE_LIBS)

# ----------------------------------------------------------------------
# Versions and URLs for toolchain builds

set(ICEBERG_ARROW_BUILD_VERSION "18.1.0")
set(ICEBERG_ARROW_BUILD_SHA256_CHECKSUM
"2dc8da5f8796afe213ecc5e5aba85bb82d91520eff3cf315784a52d0fa61d7fc")

if(DEFINED ENV{ICEBERG_ARROW_URL})
set(ARROW_SOURCE_URL "$ENV{ICEBERG_ARROW_URL}")
else()
set(ARROW_SOURCE_URL
"https://www.apache.org/dyn/closer.lua?action=download&filename=/arrow/arrow-${ICEBERG_ARROW_BUILD_VERSION}/apache-arrow-${ICEBERG_ARROW_BUILD_VERSION}.tar.gz"
"https://downloads.apache.org/arrow/arrow-${ICEBERG_ARROW_BUILD_VERSION}/apache-arrow-${ICEBERG_ARROW_BUILD_VERSION}.tar.gz"
)
endif()

# ----------------------------------------------------------------------
# FetchContent

include(FetchContent)
set(FC_DECLARE_COMMON_OPTIONS)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28)
list(APPEND FC_DECLARE_COMMON_OPTIONS EXCLUDE_FROM_ALL TRUE)
endif()

macro(prepare_fetchcontent)
set(BUILD_SHARED_LIBS OFF)
set(BUILD_STATIC_LIBS ON)
set(CMAKE_COMPILE_WARNING_AS_ERROR FALSE)
set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY TRUE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endmacro()

# ----------------------------------------------------------------------
# Apache Arrow

function(resolve_arrow_dependency)
prepare_fetchcontent()

set(ARROW_BUILD_SHARED
OFF
CACHE BOOL "" FORCE)
set(ARROW_BUILD_STATIC
ON
CACHE BOOL "" FORCE)
set(ARROW_FILESYSTEM
OFF
CACHE BOOL "" FORCE)
set(ARROW_SIMD_LEVEL
"NONE"
CACHE STRING "" FORCE)
set(ARROW_RUNTIME_SIMD_LEVEL
"NONE"
CACHE STRING "" FORCE)
set(ARROW_POSITION_INDEPENDENT_CODE
ON
CACHE BOOL "" FORCE)
set(ARROW_DEPENDENCY_SOURCE
"AUTO"
CACHE STRING "" FORCE)

fetchcontent_declare(Arrow
wgtmac marked this conversation as resolved.
Show resolved Hide resolved
${FC_DECLARE_COMMON_OPTIONS}
URL ${ARROW_SOURCE_URL}
URL_HASH "SHA256=${ICEBERG_ARROW_BUILD_SHA256_CHECKSUM}"
SOURCE_SUBDIR
cpp
FIND_PACKAGE_ARGS
NAMES
Arrow
CONFIG)

# Add Arrow cmake modules to the search path
list(PREPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_BINARY_DIR}/_deps/arrow-src/cpp/cmake_modules)
wgtmac marked this conversation as resolved.
Show resolved Hide resolved

fetchcontent_makeavailable(Arrow)

if(arrow_SOURCE_DIR)
if(NOT TARGET Arrow::arrow_static)
add_library(Arrow::arrow_static INTERFACE IMPORTED)
target_link_libraries(Arrow::arrow_static INTERFACE arrow_static)
target_include_directories(Arrow::arrow_static
INTERFACE ${arrow_BINARY_DIR}/src
${arrow_SOURCE_DIR}/cpp/src)
endif()

set(ARROW_VENDORED TRUE)
set_target_properties(arrow_static PROPERTIES OUTPUT_NAME "iceberg_vendored_arrow")
install(TARGETS arrow_static
EXPORT iceberg_targets
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
else()
set(ARROW_VENDORED FALSE)
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES Arrow)
endif()

set(ICEBERG_SYSTEM_DEPENDENCIES
${ICEBERG_SYSTEM_DEPENDENCIES}
PARENT_SCOPE)
set(ARROW_VENDORED
${ARROW_VENDORED}
PARENT_SCOPE)
endfunction()

if(ICEBERG_ARROW)
resolve_arrow_dependency()
endif()
7 changes: 3 additions & 4 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ project(example)

set(CMAKE_CXX_STANDARD 20)

find_package(iceberg CONFIG REQUIRED)
find_package(puffin CONFIG REQUIRED)
find_package(Iceberg CONFIG REQUIRED)

add_executable(demo_example demo_example.cc)

target_link_libraries(demo_example PRIVATE iceberg::iceberg_core_static
puffin::iceberg_puffin_static)
target_link_libraries(demo_example PRIVATE Iceberg::iceberg_puffin_static
Iceberg::iceberg_arrow_static)
10 changes: 6 additions & 4 deletions example/demo_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@

#include <iostream>

#include "iceberg/puffin.h"
#include "iceberg/table.h"
#include "iceberg/arrow/demo_arrow.h"
#include "iceberg/demo_table.h"
#include "iceberg/puffin/demo_puffin.h"

int main() {
std::cout << iceberg::Table::create()->print() << std::endl;
std::cout << iceberg::Puffin::create()->print() << std::endl;
std::cout << iceberg::DemoTable().print() << std::endl;
std::cout << iceberg::puffin::DemoPuffin().print() << std::endl;
std::cout << iceberg::arrow::DemoArrow().print() << std::endl;
return 0;
}
Binary file added src/.DS_Store
Binary file not shown.
3 changes: 1 addition & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
# specific language governing permissions and limitations
# under the License.

add_subdirectory(core)
add_subdirectory(puffin)
add_subdirectory(iceberg)
Loading
Loading