Skip to content

Commit

Permalink
add vendored yyjson as default json parser
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrush committed Jan 10, 2025
1 parent 1a70f21 commit 476df6e
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions COPYRIGHT
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
15 changes: 8 additions & 7 deletions src/cmake/Setup3rdParty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
1 change: 1 addition & 0 deletions src/docs/sphinx/licenses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/libs/conduit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

#
Expand Down Expand Up @@ -160,6 +159,10 @@ if(OPENMP_FOUND)
list(APPEND conduit_thirdparty_libs ${conduit_blt_openmp_deps})
endif()

if(ENABLE_YYJSON)
list(APPEND conduit_sources $<TARGET_OBJECTS:conduit_yyjson>)
endif()

#
# Setup the conduit lib
#
Expand Down
3 changes: 3 additions & 0 deletions src/libs/conduit/conduit_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@

#cmakedefine CONDUIT_USE_CXX14

#cmakedefine CONDUIT_USE_YYJSON

#cmakedefine CONDUIT_USE_CALIPER

#cmakedefine CONDUIT_USE_OPENMP
Expand All @@ -58,6 +60,7 @@

#cmakedefine CONDUIT_USE_TOTALVIEW


#endif


15 changes: 12 additions & 3 deletions src/libs/conduit/conduit_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
///
//-----------------------------------------------------------------------------
#include "conduit_generator.hpp"

#include "conduit_config.hpp"

//-----------------------------------------------------------------------------
// -- standard lib includes --
Expand All @@ -17,9 +17,18 @@
#include <cstdlib>

//-----------------------------------------------------------------------------
// -- 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 --
Expand Down
12 changes: 10 additions & 2 deletions src/tests/conduit/t_conduit_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@

//-----------------------------------------------------------------------------
///
/// file: conduit_node.cpp
/// file: t_conduit_node.cpp
///
//-----------------------------------------------------------------------------

#include "conduit.hpp"

#include <iostream>
#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)
{
Expand Down
1 change: 0 additions & 1 deletion src/tests/conduit/t_conduit_node_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include <iostream>
#include "gtest/gtest.h"
#include "conduit_json.hpp"
using namespace conduit;

//-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/tests/conduit/t_conduit_node_to_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <iostream>
#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
Expand Down
1 change: 0 additions & 1 deletion src/tests/conduit/t_conduit_node_type_dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include <iostream>
#include "gtest/gtest.h"
#include "conduit_json.hpp"
using namespace conduit;
using namespace conduit::utils;

Expand Down
1 change: 0 additions & 1 deletion src/tests/conduit/t_conduit_node_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include <iostream>
#include "gtest/gtest.h"
#include "conduit_json.hpp"
using namespace conduit;

//-----------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion src/tests/docs/t_conduit_docs_tutorial_basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include <iostream>
#include "gtest/gtest.h"
#include "conduit_json.hpp"

using namespace conduit;

Expand Down
11 changes: 9 additions & 2 deletions src/tests/thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_OBJECTS:conduit_yyjson>
FOLDER tests/thirdparty)
else()
add_cpp_test(TEST t_rapidjson_smoke
FOLDER tests/thirdparty)
endif()


add_cpp_test(TEST t_libb64_smoke
SOURCES $<TARGET_OBJECTS:conduit_b64>
Expand Down
10 changes: 5 additions & 5 deletions src/tests/thirdparty/t_rapidjson_smoke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit 476df6e

Please sign in to comment.