From 476df6ee23c8a38b09fb2f71ae99acfbd5603612 Mon Sep 17 00:00:00 2001 From: Cyrus Harrison Date: Fri, 10 Jan 2025 12:09:37 -0800 Subject: [PATCH] add vendored yyjson as default json parser --- CHANGELOG.md | 1 + COPYRIGHT | 4 ++++ src/CMakeLists.txt | 3 +++ src/cmake/Setup3rdParty.cmake | 15 ++++++++------- src/docs/sphinx/licenses.rst | 1 + src/libs/conduit/CMakeLists.txt | 5 ++++- src/libs/conduit/conduit_config.h.in | 3 +++ src/libs/conduit/conduit_generator.cpp | 15 ++++++++++++--- src/tests/conduit/t_conduit_node.cpp | 12 ++++++++++-- src/tests/conduit/t_conduit_node_set.cpp | 1 - src/tests/conduit/t_conduit_node_to_array.cpp | 2 +- .../conduit/t_conduit_node_type_dispatch.cpp | 1 - src/tests/conduit/t_conduit_node_update.cpp | 1 - src/tests/docs/t_conduit_docs_tutorial_basics.cpp | 1 - src/tests/thirdparty/CMakeLists.txt | 11 +++++++++-- src/tests/thirdparty/t_rapidjson_smoke.cpp | 10 +++++----- 16 files changed, 61 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 118b1b14d..802879ff0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s #### Conduit - Changed the MPI CMake target used by conduit from `MPI:MPI_CXX` to `MPI:MPI_C` to provide better compatibility with downstream tools. +- Added vendored yyjson v0.10.0 as new and default JSON parser. yyjson has an MIT license that is compatible with Debian's Free Software Guidelines, where RapidJSON is not (https://wiki.debian.org/qa.debian.org/jsonevil). You can still use RapidJSON by setting the new CMake option `ENABLE_YYJSON` to `FALSE`. #### Blueprint - Certain algorithms that use MPI tags had their tag values lowered since some MPI implementations do not support large values. diff --git a/COPYRIGHT b/COPYRIGHT index c5e8ae7cc..adb575b83 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -21,6 +21,10 @@ PackageLicenseDeclared: BSD-3-Clause PackageName: libb64 PackageHomePage: http://libb64.sourceforge.net/ +PackageName: yyjson +PackageHomePage: https://github.com/ibireme/yyjson +PackageLicenseDeclared: MIT + PackageName: rapidjson PackageHomePage: http://rapidjson.org/ PackageLicenseDeclared: MIT diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 32a0abc31..219224cc2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,6 +32,7 @@ option(ENABLE_UTILS "Build Utilities" ON) option(ENABLE_DOCS "Build conduit documentation" ON) option(ENABLE_RELAY_WEBSERVER "Build Relay Web Server Support" ON) + option(ENABLE_COVERAGE "Build with coverage flags" OFF) option(ENABLE_PYTHON "Build Python Support" OFF) @@ -40,6 +41,8 @@ option(ENABLE_FORTRAN "Build Fortran Support" OFF) option(ENABLE_MPI "Build MPI Support" OFF) option(ENABLE_OPENMP "Build OpenMP Support" OFF) +option(ENABLE_YYJSON "Use yyjson for JSON Parsing" ON) + option(USE_SYSTEM_YYJSON "Use yyjson as a replacement for rapidjson." OFF) if(${USE_SYSTEM_YYJSON}) add_compile_definitions(USE_YYJSON) diff --git a/src/cmake/Setup3rdParty.cmake b/src/cmake/Setup3rdParty.cmake index 60d71b8a8..b31838ed5 100644 --- a/src/cmake/Setup3rdParty.cmake +++ b/src/cmake/Setup3rdParty.cmake @@ -23,15 +23,16 @@ if(UNIX AND NOT APPLE) endif() endif() - ################################ -# Setup includes for RapidJSON +# Setup and build json parsing +# yyjson or rapidjson ################################ -if(${USE_SYSTEM_YYJSON}) - find_package(yyjson REQUIRED) - link_libraries(yyjson::yyjson) - include_directories(thirdparty_builtin/yyjson) -else() +if(ENABLE_YYJSON) + message(STATUS "Using yyjson for JSON parsing") + add_subdirectory(thirdparty_builtin/yyjson) + include_directories(thirdparty_builtin/yyjson/) + set(CONDUIT_USE_YYJSON TRUE) +else() # rapidjson include(cmake/thirdparty/SetupRapidJSON.cmake) message(STATUS "Using RapidJSON Include: ${RAPIDJSON_INCLUDE_DIR}") include_directories(${RAPIDJSON_INCLUDE_DIR}) diff --git a/src/docs/sphinx/licenses.rst b/src/docs/sphinx/licenses.rst index e824e245b..1b3728278 100644 --- a/src/docs/sphinx/licenses.rst +++ b/src/docs/sphinx/licenses.rst @@ -20,6 +20,7 @@ C and C++ Libraries ===================== - *gtest*: From BLT - (BSD Style License) - *libb64*: src/thirdparty_builtin/libb64/LICENSE (Public Domain) +- *yyjson*: src/thirdparty_builtin/yyjson/LICENSE (MIT License) - *rapidjson*: src/thirdparty_builtin/rapidjson/license.txt (MIT License) - *civetweb*: src/thirdparty_builtin/civetweb-0a95342/LICENSE.md (MIT License) - *libyaml*: src/thirdparty_builtin/libyaml-690a781/LICENSE (MIT License) diff --git a/src/libs/conduit/CMakeLists.txt b/src/libs/conduit/CMakeLists.txt index 9941d54d7..61e0169ac 100644 --- a/src/libs/conduit/CMakeLists.txt +++ b/src/libs/conduit/CMakeLists.txt @@ -66,7 +66,6 @@ set(conduit_headers ${CMAKE_CURRENT_BINARY_DIR}/conduit_config.h conduit_config.hpp ${CMAKE_CURRENT_BINARY_DIR}/conduit_bitwidth_style_types.h - conduit_json.hpp ) # @@ -160,6 +159,10 @@ if(OPENMP_FOUND) list(APPEND conduit_thirdparty_libs ${conduit_blt_openmp_deps}) endif() +if(ENABLE_YYJSON) + list(APPEND conduit_sources $) +endif() + # # Setup the conduit lib # diff --git a/src/libs/conduit/conduit_config.h.in b/src/libs/conduit/conduit_config.h.in index 815ecadfd..528ef5ee1 100644 --- a/src/libs/conduit/conduit_config.h.in +++ b/src/libs/conduit/conduit_config.h.in @@ -50,6 +50,8 @@ #cmakedefine CONDUIT_USE_CXX14 +#cmakedefine CONDUIT_USE_YYJSON + #cmakedefine CONDUIT_USE_CALIPER #cmakedefine CONDUIT_USE_OPENMP @@ -58,6 +60,7 @@ #cmakedefine CONDUIT_USE_TOTALVIEW + #endif diff --git a/src/libs/conduit/conduit_generator.cpp b/src/libs/conduit/conduit_generator.cpp index 62919eb04..b250fa930 100644 --- a/src/libs/conduit/conduit_generator.cpp +++ b/src/libs/conduit/conduit_generator.cpp @@ -8,7 +8,7 @@ /// //----------------------------------------------------------------------------- #include "conduit_generator.hpp" - +#include "conduit_config.hpp" //----------------------------------------------------------------------------- // -- standard lib includes -- @@ -17,9 +17,18 @@ #include //----------------------------------------------------------------------------- -// -- rapidjson includes -- +// -- json includes and namespace -- //----------------------------------------------------------------------------- -#include "conduit_json.hpp" + +#ifdef CONDUIT_USE_YYJSON + #include "conduit_yyjson_interface.h" + namespace conduit_json = conduit_yyjson; +#else + #include "rapidjson/document.h" + #include "rapidjson/error/en.h" + namespace conduit_json = conduit_rapidjson; +#endif + //----------------------------------------------------------------------------- // -- libyaml includes -- diff --git a/src/tests/conduit/t_conduit_node.cpp b/src/tests/conduit/t_conduit_node.cpp index 26570baf7..b79f125b4 100644 --- a/src/tests/conduit/t_conduit_node.cpp +++ b/src/tests/conduit/t_conduit_node.cpp @@ -4,7 +4,7 @@ //----------------------------------------------------------------------------- /// -/// file: conduit_node.cpp +/// file: t_conduit_node.cpp /// //----------------------------------------------------------------------------- @@ -12,9 +12,17 @@ #include #include "gtest/gtest.h" -#include "conduit_json.hpp" using namespace conduit; +#ifdef CONDUIT_USE_YYJSON + #include "conduit_yyjson_interface.h" + namespace conduit_json = conduit_yyjson; +#else + #include "rapidjson/document.h" + #include "rapidjson/error/en.h" + namespace conduit_json = conduit_rapidjson; +#endif + //----------------------------------------------------------------------------- TEST(conduit_node, simple) { diff --git a/src/tests/conduit/t_conduit_node_set.cpp b/src/tests/conduit/t_conduit_node_set.cpp index 7d76b6bcc..1b60e2642 100644 --- a/src/tests/conduit/t_conduit_node_set.cpp +++ b/src/tests/conduit/t_conduit_node_set.cpp @@ -12,7 +12,6 @@ #include #include "gtest/gtest.h" -#include "conduit_json.hpp" using namespace conduit; //----------------------------------------------------------------------------- diff --git a/src/tests/conduit/t_conduit_node_to_array.cpp b/src/tests/conduit/t_conduit_node_to_array.cpp index c34a579f7..32ef036d4 100644 --- a/src/tests/conduit/t_conduit_node_to_array.cpp +++ b/src/tests/conduit/t_conduit_node_to_array.cpp @@ -12,7 +12,7 @@ #include #include "gtest/gtest.h" -#include "conduit_json.hpp" + using namespace conduit; // TODO(JRC): Figure out if there's any better way to facilitate these conversions diff --git a/src/tests/conduit/t_conduit_node_type_dispatch.cpp b/src/tests/conduit/t_conduit_node_type_dispatch.cpp index 5ca323546..71d41ce1e 100644 --- a/src/tests/conduit/t_conduit_node_type_dispatch.cpp +++ b/src/tests/conduit/t_conduit_node_type_dispatch.cpp @@ -12,7 +12,6 @@ #include #include "gtest/gtest.h" -#include "conduit_json.hpp" using namespace conduit; using namespace conduit::utils; diff --git a/src/tests/conduit/t_conduit_node_update.cpp b/src/tests/conduit/t_conduit_node_update.cpp index f169250a1..5209e45da 100644 --- a/src/tests/conduit/t_conduit_node_update.cpp +++ b/src/tests/conduit/t_conduit_node_update.cpp @@ -13,7 +13,6 @@ #include #include "gtest/gtest.h" -#include "conduit_json.hpp" using namespace conduit; //----------------------------------------------------------------------------- diff --git a/src/tests/docs/t_conduit_docs_tutorial_basics.cpp b/src/tests/docs/t_conduit_docs_tutorial_basics.cpp index 80778051d..31c9a1391 100644 --- a/src/tests/docs/t_conduit_docs_tutorial_basics.cpp +++ b/src/tests/docs/t_conduit_docs_tutorial_basics.cpp @@ -15,7 +15,6 @@ #include #include "gtest/gtest.h" -#include "conduit_json.hpp" using namespace conduit; diff --git a/src/tests/thirdparty/CMakeLists.txt b/src/tests/thirdparty/CMakeLists.txt index 2ba8be2a8..ac4c54611 100644 --- a/src/tests/thirdparty/CMakeLists.txt +++ b/src/tests/thirdparty/CMakeLists.txt @@ -9,8 +9,15 @@ message(STATUS "Adding thirdparty lib unit tests") -add_cpp_test(TEST t_rapidjson_smoke - FOLDER tests/thirdparty) +if(ENABLE_YYJSON) + add_cpp_test(TEST t_yyjson_smoke + SOURCES $ + FOLDER tests/thirdparty) +else() + add_cpp_test(TEST t_rapidjson_smoke + FOLDER tests/thirdparty) +endif() + add_cpp_test(TEST t_libb64_smoke SOURCES $ diff --git a/src/tests/thirdparty/t_rapidjson_smoke.cpp b/src/tests/thirdparty/t_rapidjson_smoke.cpp index d0abd6cf2..5dc741fc8 100644 --- a/src/tests/thirdparty/t_rapidjson_smoke.cpp +++ b/src/tests/thirdparty/t_rapidjson_smoke.cpp @@ -4,20 +4,20 @@ //----------------------------------------------------------------------------- /// -/// file: rapidjson_smoke.cpp +/// file: t_rapidjson_smoke.cpp /// //----------------------------------------------------------------------------- -#include "conduit_json.hpp" +#include "rapidjson/document.h" #include "gtest/gtest.h" //----------------------------------------------------------------------------- -TEST(json_smoke, basic_use) +TEST(rapidjson_smoke, basic_use) { const char json[] = "{ \"hello\" : \"world\" }"; - conduit_json::Document d; + conduit_rapidjson::Document d; d.Parse<0>(json); ASSERT_STREQ(d["hello"].GetString(),"world"); -} +} \ No newline at end of file