Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ If you experience network issues when downloading dependencies, you can customiz
- `ICEBERG_UTF8PROC_URL`: utf8proc tarball URL
- `ICEBERG_NLOHMANN_JSON_URL`: nlohmann-json tarball URL
- `ICEBERG_SPDLOG_URL`: spdlog tarball URL
- `ICEBERG_ZSTD_URL`: zstd tarball URL
- `ICEBERG_CPR_URL`: cpr tarball URL

Example:
Expand Down
113 changes: 107 additions & 6 deletions cmake_modules/IcebergThirdpartyToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ function(resolve_arrow_dependency)
set(AWSSDK_SOURCE "SYSTEM")
endif()
set(ZLIB_SOURCE "SYSTEM")
# Link Arrow to the zstd that core uses instead of building another copy.
set(zstd_SOURCE "SYSTEM")
if(ICEBERG_ZSTD_TARGET STREQUAL "zstd::libzstd_shared")
set(ARROW_ZSTD_USE_SHARED ON)
else()
set(ARROW_ZSTD_USE_SHARED OFF)
endif()
set(ARROW_VERBOSE_THIRDPARTY_BUILD OFF)
set(CMAKE_CXX_STANDARD 20)

Expand Down Expand Up @@ -898,16 +905,109 @@ endfunction()

# ----------------------------------------------------------------------
# Zstd
#

function(resolve_zstd_dependency)
find_package(zstd CONFIG)
if(zstd_FOUND)
prepare_fetchcontent()

set(ZSTD_BUILD_PROGRAMS OFF)
set(ZSTD_BUILD_TESTS OFF)
set(ZSTD_BUILD_SHARED OFF)
set(ZSTD_BUILD_STATIC ON)
set(ZSTD_MULTITHREAD_SUPPORT OFF)
# zstd creates an "uninstall" target unless one exists, and the Thrift that vendored
# Arrow builds later creates one unconditionally. Define a placeholder that only
# zstd's directories can see, so that zstd skips its own.
set(ICEBERG_ZSTD_PROJECT_INCLUDE
"${CMAKE_CURRENT_BINARY_DIR}/iceberg_zstd_project.cmake")
file(WRITE "${ICEBERG_ZSTD_PROJECT_INCLUDE}"
"if(NOT TARGET uninstall)\n add_library(uninstall INTERFACE IMPORTED)\nendif()\n")
set(CMAKE_PROJECT_zstd_INCLUDE "${ICEBERG_ZSTD_PROJECT_INCLUDE}")

set(ICEBERG_ZSTD_BUILD_VERSION "1.5.7")
set(ICEBERG_ZSTD_BUILD_SHA256_CHECKSUM
"eb33e51f49a15e023950cd7825ca74a4a2b43db8354825ac24fc1b7ee09e6fa3")

if(DEFINED ENV{ICEBERG_ZSTD_URL})
set(ZSTD_URL "$ENV{ICEBERG_ZSTD_URL}")
else()
set(ZSTD_URL
"https://github.com/facebook/zstd/releases/download/v${ICEBERG_ZSTD_BUILD_VERSION}/zstd-${ICEBERG_ZSTD_BUILD_VERSION}.tar.gz"
)
endif()

fetchcontent_declare(zstd
${FC_DECLARE_COMMON_OPTIONS}
URL ${ZSTD_URL}
URL_HASH "SHA256=${ICEBERG_ZSTD_BUILD_SHA256_CHECKSUM}"
SOURCE_SUBDIR
build/cmake
FIND_PACKAGE_ARGS
NAMES
zstd
CONFIG)
fetchcontent_makeavailable(zstd)
Comment thread
proost marked this conversation as resolved.
Resolved

if(zstd_SOURCE_DIR)
set(ZSTD_VENDORED TRUE)
# FetchContent supports EXCLUDE_FROM_ALL only since CMake 3.28. Exclude the zstd
# directory here as well, so that older CMake versions skip zstd's own install
# rules.
set_property(DIRECTORY "${zstd_SOURCE_DIR}/build/cmake" PROPERTY EXCLUDE_FROM_ALL
TRUE)
set_target_properties(libzstd_static PROPERTIES OUTPUT_NAME "iceberg_vendored_zstd"
POSITION_INDEPENDENT_CODE ON)
install(TARGETS libzstd_static
Comment thread
proost marked this conversation as resolved.
Resolved
EXPORT iceberg_targets
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
install(FILES "${zstd_SOURCE_DIR}/LICENSE"
DESTINATION "${ICEBERG_INSTALL_DOCDIR}"
RENAME "LICENSE.zstd")
# Arrow and Avro link zstd::libzstd_static. Unlike an ALIAS, an imported target
# is exported by name, so Arrow's exports do not depend on libzstd_static, which
# zstd also adds to its own export set.
if(NOT TARGET zstd::libzstd_static)
add_library(zstd::libzstd_static INTERFACE IMPORTED)
target_link_libraries(zstd::libzstd_static INTERFACE libzstd_static)
endif()
# Let find_package(zstd) in Arrow and Avro find this build. FetchContent does not
# write this redirect with FETCHCONTENT_TRY_FIND_PACKAGE_MODE=NEVER.
if(NOT EXISTS "${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/zstd-config.cmake"
AND NOT EXISTS "${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/zstdConfig.cmake")
file(WRITE "${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/zstd-config.cmake" "")
endif()
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/zstd-config-version.cmake"
VERSION ${ICEBERG_ZSTD_BUILD_VERSION}
COMPATIBILITY AnyNewerVersion)
set(ICEBERG_ZSTD_TARGET zstd::libzstd_static)
else()
set(ZSTD_VENDORED FALSE)
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES zstd)
message(STATUS "Found zstd, version: ${zstd_VERSION}")
set(ICEBERG_SYSTEM_DEPENDENCIES
${ICEBERG_SYSTEM_DEPENDENCIES}
PARENT_SCOPE)
# Prefer the shared library so that all of them link
# the same one. zstd::libzstd is only defined by zstd 1.5.6 and later.
if(TARGET zstd::libzstd_shared)
set(ICEBERG_ZSTD_TARGET zstd::libzstd_shared)
elseif(TARGET zstd::libzstd_static)
set(ICEBERG_ZSTD_TARGET zstd::libzstd_static)
else()
set(ICEBERG_ZSTD_TARGET zstd::libzstd)
endif()
endif()

set(ICEBERG_SYSTEM_DEPENDENCIES
${ICEBERG_SYSTEM_DEPENDENCIES}
PARENT_SCOPE)
set(ZSTD_VENDORED
${ZSTD_VENDORED}
PARENT_SCOPE)
set(ICEBERG_ZSTD_TARGET
${ICEBERG_ZSTD_TARGET}
PARENT_SCOPE)
endfunction()

# ----------------------------------------------------------------------
Expand Down Expand Up @@ -966,6 +1066,8 @@ resolve_nanoarrow_dependency()
resolve_croaring_dependency()
resolve_utf8proc_dependency()
resolve_nlohmann_json_dependency()
# Resolve zstd before Arrow and Avro, which reuse it.
resolve_zstd_dependency()

# Scan scheduling needs threading primitives even when spdlog is disabled.
find_package(Threads REQUIRED)
Expand Down Expand Up @@ -993,7 +1095,6 @@ if(ICEBERG_BUILD_BUNDLE)
resolve_aws_sdk_dependency()
endif()
resolve_avro_dependency()
resolve_zstd_dependency()
endif()

if(ICEBERG_BUILD_REST)
Expand Down
1 change: 1 addition & 0 deletions dev/release/rat_exclude_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ dist/**
requirements.txt
test/resources/**
*.json
src/iceberg/test/resources/puffin/v1/*.bin
src/iceberg/util/murmurhash3_internal.*
src/iceberg/test/resources/encryption/**
1 change: 1 addition & 0 deletions mkdocs/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ If you experience network issues when downloading dependencies, you can override
| `ICEBERG_CROARING_URL` | CRoaring tarball |
| `ICEBERG_UTF8PROC_URL` | utf8proc tarball |
| `ICEBERG_NLOHMANN_JSON_URL` | nlohmann-json tarball |
| `ICEBERG_ZSTD_URL` | zstd tarball |
| `ICEBERG_CPR_URL` | cpr tarball |

Example:
Expand Down
15 changes: 11 additions & 4 deletions src/iceberg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ set(ICEBERG_SOURCES
util/type_util.cc
util/url_encoder.cc
util/uuid.cc
util/zstd_internal.cc
view/view_metadata.cc
view/view_version.cc)

Expand All @@ -194,26 +195,32 @@ list(APPEND
nlohmann_json::nlohmann_json
utf8proc::utf8proc
ZLIB::ZLIB
roaring::roaring)
roaring::roaring
${ICEBERG_ZSTD_TARGET})
list(APPEND
ICEBERG_SHARED_BUILD_INTERFACE_LIBS
"$<IF:$<BOOL:${NANOARROW_VENDORED}>,nanoarrow::nanoarrow_static,$<IF:$<TARGET_EXISTS:nanoarrow::nanoarrow_shared>,nanoarrow::nanoarrow_shared,nanoarrow::nanoarrow_static>>"
nlohmann_json::nlohmann_json
utf8proc::utf8proc
ZLIB::ZLIB
roaring::roaring)
roaring::roaring
${ICEBERG_ZSTD_TARGET})
list(APPEND
ICEBERG_STATIC_INSTALL_INTERFACE_LIBS
"$<IF:$<BOOL:${NANOARROW_VENDORED}>,iceberg::nanoarrow_static,$<IF:$<TARGET_EXISTS:nanoarrow::nanoarrow_static>,nanoarrow::nanoarrow_static,nanoarrow::nanoarrow_shared>>"
"$<IF:$<BOOL:${NLOHMANN_JSON_VENDORED}>,iceberg::nlohmann_json,$<IF:$<TARGET_EXISTS:nlohmann_json::nlohmann_json>,nlohmann_json::nlohmann_json,nlohmann_json::nlohmann_json>>"
"$<IF:$<BOOL:${UTF8PROC_VENDORED}>,iceberg::utf8proc,utf8proc::utf8proc>"
"$<IF:$<BOOL:${CROARING_VENDORED}>,iceberg::roaring,roaring::roaring>")
"$<IF:$<BOOL:${CROARING_VENDORED}>,iceberg::roaring,roaring::roaring>"
"$<IF:$<BOOL:${ZSTD_VENDORED}>,iceberg::libzstd_static,$<IF:$<TARGET_EXISTS:${ICEBERG_ZSTD_TARGET}>,${ICEBERG_ZSTD_TARGET},$<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,$<IF:$<TARGET_EXISTS:zstd::libzstd_static>,zstd::libzstd_static,zstd::libzstd>>>>"
)
list(APPEND
ICEBERG_SHARED_INSTALL_INTERFACE_LIBS
"$<IF:$<BOOL:${NANOARROW_VENDORED}>,iceberg::nanoarrow_static,$<IF:$<TARGET_EXISTS:nanoarrow::nanoarrow_shared>,nanoarrow::nanoarrow_shared,nanoarrow::nanoarrow_static>>"
"$<IF:$<BOOL:${NLOHMANN_JSON_VENDORED}>,iceberg::nlohmann_json,$<IF:$<TARGET_EXISTS:nlohmann_json::nlohmann_json>,nlohmann_json::nlohmann_json,nlohmann_json::nlohmann_json>>"
"$<IF:$<BOOL:${UTF8PROC_VENDORED}>,iceberg::utf8proc,utf8proc::utf8proc>"
"$<IF:$<BOOL:${CROARING_VENDORED}>,iceberg::roaring,roaring::roaring>")
"$<IF:$<BOOL:${CROARING_VENDORED}>,iceberg::roaring,roaring::roaring>"
"$<IF:$<BOOL:${ZSTD_VENDORED}>,iceberg::libzstd_static,$<IF:$<TARGET_EXISTS:${ICEBERG_ZSTD_TARGET}>,${ICEBERG_ZSTD_TARGET},$<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,$<IF:$<TARGET_EXISTS:zstd::libzstd_static>,zstd::libzstd_static,zstd::libzstd>>>>"
)

if(ICEBERG_SPDLOG)
set(ICEBERG_HAS_SPDLOG ON)
Expand Down
17 changes: 17 additions & 0 deletions src/iceberg/iceberg-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ iceberg_find_dependencies("${ICEBERG_SYSTEM_DEPENDENCIES}")

include("${CMAKE_CURRENT_LIST_DIR}/iceberg-targets.cmake")

# Vendored Arrow and Avro link zstd by the target names that zstd's package config
# defines. Point them at the vendored zstd, so that a zstd package that the
# consumer finds is not linked as well.
if(TARGET iceberg::libzstd_static)
foreach(_iceberg_target iceberg::arrow_static iceberg::avrocpp_s)
if(TARGET ${_iceberg_target})
get_target_property(_iceberg_libs ${_iceberg_target} INTERFACE_LINK_LIBRARIES)
string(REGEX REPLACE "zstd::libzstd(_shared|_static)?" "iceberg::libzstd_static"
_iceberg_libs "${_iceberg_libs}")
set_target_properties(${_iceberg_target} PROPERTIES INTERFACE_LINK_LIBRARIES
"${_iceberg_libs}")
endif()
endforeach()
unset(_iceberg_libs)
unset(_iceberg_target)
endif()

if(TARGET iceberg::arrow_static)
add_library(Arrow::arrow_static ALIAS iceberg::arrow_static)

Expand Down
7 changes: 5 additions & 2 deletions src/iceberg/puffin/puffin_format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <utility>
#include <vector>

#include "iceberg/util/zstd_internal.h"

namespace iceberg::puffin {

namespace {
Expand Down Expand Up @@ -57,7 +59,7 @@ Result<std::vector<std::byte>> Compress(PuffinCompressionCodec codec,
case PuffinCompressionCodec::kLz4:
return NotSupported("LZ4 compression is not yet supported");
case PuffinCompressionCodec::kZstd:
return NotSupported("Zstd compression is not yet supported");
return ZstdCompress(input);
}
std::unreachable();
}
Expand All @@ -70,7 +72,8 @@ Result<std::vector<std::byte>> Decompress(PuffinCompressionCodec codec,
case PuffinCompressionCodec::kLz4:
return NotSupported("LZ4 decompression is not yet supported");
case PuffinCompressionCodec::kZstd:
return NotSupported("Zstd decompression is not yet supported");
// The Puffin spec requires a single Zstandard frame with the content size present.
return ZstdDecompress(input);
}
std::unreachable();
}
Expand Down
Loading
Loading