From 236b6652d42fa8858e5e07286c393fe0dac95c01 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Tue, 8 Apr 2025 17:59:57 +0800 Subject: [PATCH 1/2] feat: add nlohmann/json library --- .../IcebergThirdpartyToolchain.cmake | 28 +++++++++++++++++++ src/iceberg/CMakeLists.txt | 12 +++++--- src/iceberg/arrow_c_data_internal.cc | 9 ++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/cmake_modules/IcebergThirdpartyToolchain.cmake b/cmake_modules/IcebergThirdpartyToolchain.cmake index 783d99c4b..c4b188b4d 100644 --- a/cmake_modules/IcebergThirdpartyToolchain.cmake +++ b/cmake_modules/IcebergThirdpartyToolchain.cmake @@ -226,3 +226,31 @@ function(resolve_nanoarrow_dependency) endfunction() resolve_nanoarrow_dependency() + +# ---------------------------------------------------------------------- +# nlohmann-json + +function(resolve_nlohmann_json_dependency) + prepare_fetchcontent() + + set(JSON_BuildTests + OFF + CACHE BOOL "" FORCE) + + fetchcontent_declare(nlohmann_json + ${FC_DECLARE_COMMON_OPTIONS} + URL "https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz" + ) + fetchcontent_makeavailable(nlohmann_json) + + set_target_properties(nlohmann_json + PROPERTIES OUTPUT_NAME "iceberg_vendored_nlohmann_json" + POSITION_INDEPENDENT_CODE ON) + install(TARGETS nlohmann_json + EXPORT iceberg_targets + RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}" + ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}") +endfunction() + +resolve_nlohmann_json_dependency() diff --git a/src/iceberg/CMakeLists.txt b/src/iceberg/CMakeLists.txt index fec895240..ace33fb09 100644 --- a/src/iceberg/CMakeLists.txt +++ b/src/iceberg/CMakeLists.txt @@ -33,10 +33,14 @@ set(ICEBERG_SHARED_BUILD_INTERFACE_LIBS) set(ICEBERG_STATIC_INSTALL_INTERFACE_LIBS) set(ICEBERG_SHARED_INSTALL_INTERFACE_LIBS) -list(APPEND ICEBERG_STATIC_BUILD_INTERFACE_LIBS nanoarrow::nanoarrow) -list(APPEND ICEBERG_SHARED_BUILD_INTERFACE_LIBS nanoarrow::nanoarrow) -list(APPEND ICEBERG_STATIC_INSTALL_INTERFACE_LIBS "Iceberg::nanoarrow") -list(APPEND ICEBERG_SHARED_INSTALL_INTERFACE_LIBS "Iceberg::nanoarrow") +list(APPEND ICEBERG_STATIC_BUILD_INTERFACE_LIBS nanoarrow::nanoarrow + nlohmann_json::nlohmann_json) +list(APPEND ICEBERG_SHARED_BUILD_INTERFACE_LIBS nanoarrow::nanoarrow + nlohmann_json::nlohmann_json) +list(APPEND ICEBERG_STATIC_INSTALL_INTERFACE_LIBS "Iceberg::nanoarrow" + "Iceberg::nlohmann_json") +list(APPEND ICEBERG_SHARED_INSTALL_INTERFACE_LIBS "Iceberg::nanoarrow" + "Iceberg::nlohmann_json") add_iceberg_lib(iceberg SOURCES diff --git a/src/iceberg/arrow_c_data_internal.cc b/src/iceberg/arrow_c_data_internal.cc index 9716b25a4..ec9068bdc 100644 --- a/src/iceberg/arrow_c_data_internal.cc +++ b/src/iceberg/arrow_c_data_internal.cc @@ -23,6 +23,8 @@ #include #include +#include + namespace iceberg::internal { std::pair CreateExampleArrowSchemaAndArrayByNanoarrow() { @@ -73,4 +75,11 @@ std::pair CreateExampleArrowSchemaAndArrayByNanoarrow() return {out_schema, out_array}; } +void TestNlohmannJsonCompile() { + nlohmann::json j; + j["name"] = "foo"; + j["age"] = 30; + j["city"] = "New York"; +} + } // namespace iceberg::internal From 8a387e0505490356f4f5eae7d42c3557a9c434ad Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Tue, 8 Apr 2025 22:11:06 +0800 Subject: [PATCH 2/2] fix windows build and update LICENSE --- LICENSE | 27 +++++++++++++++++++ .../IcebergThirdpartyToolchain.cmake | 5 ++++ 2 files changed, 32 insertions(+) diff --git a/LICENSE b/LICENSE index 1c8702596..c23c810d3 100644 --- a/LICENSE +++ b/LICENSE @@ -227,3 +227,30 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +-------------------------------------------------------------------------------- + +3rdparty dependency nlohmann-json is statically linked in certain binary +distributions. nlohmann-json has the following license: + +MIT License + +Copyright (c) 2013-2022 Niels Lohmann + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/cmake_modules/IcebergThirdpartyToolchain.cmake b/cmake_modules/IcebergThirdpartyToolchain.cmake index c4b188b4d..b2e2a5534 100644 --- a/cmake_modules/IcebergThirdpartyToolchain.cmake +++ b/cmake_modules/IcebergThirdpartyToolchain.cmake @@ -246,6 +246,11 @@ function(resolve_nlohmann_json_dependency) set_target_properties(nlohmann_json PROPERTIES OUTPUT_NAME "iceberg_vendored_nlohmann_json" POSITION_INDEPENDENT_CODE ON) + if(MSVC_TOOLCHAIN) + set(NLOHMANN_NATVIS_FILE ${nlohmann_json_SOURCE_DIR}/nlohmann_json.natvis) + install(FILES ${NLOHMANN_NATVIS_FILE} DESTINATION .) + endif() + install(TARGETS nlohmann_json EXPORT iceberg_targets RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"