From f62ca21dd11fcf7a6f4658a4859838f76730547e Mon Sep 17 00:00:00 2001 From: Paul Dreik Date: Tue, 10 Nov 2020 19:55:04 +0100 Subject: [PATCH] enable boost json (#1292) * bump boost.json and see if it works in simdjson CI * enable boost json * clean up * add boost json to deps * use boost if std::string_view is available * add build with c++20 * use docker image which has the proper libc++ installed --- .drone.yml | 21 +++++++++++++++++++++ benchmark/parsingcompetition.cpp | 10 ++-------- dependencies/CMakeLists.txt | 21 ++++++++++++--------- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/.drone.yml b/.drone.yml index 738de635..e55b44f2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -183,6 +183,27 @@ steps: - ASAN_OPTIONS="detect_leaks=0" ctest $CTEST_FLAGS -LE "acceptance|per_implementation" # Everything we haven't run yet, run now. --- kind: pipeline +name: cpp20-clang11-libcpp +platform: { os: linux, arch: amd64 } +steps: +- name: Build and Test + image: pauldreik/llvm-11 + user: root + environment: + CC: clang-11 + CXX: clang++-11 + CMAKE_FLAGS: -GNinja + BUILD_FLAGS: + CTEST_FLAGS: -j4 --output-on-failure -E checkperf + CXXFLAGS: -std=c++20 -stdlib=libc++ + commands: + - mkdir build + - cd build + - cmake $CMAKE_FLAGS .. + - cmake --build . $BUILD_FLAGS + - ctest $CTEST_FLAGS +--- +kind: pipeline name: arm64-gcc8 platform: { os: linux, arch: arm64 } steps: diff --git a/benchmark/parsingcompetition.cpp b/benchmark/parsingcompetition.cpp index 25c3d331..4a2f2192 100644 --- a/benchmark/parsingcompetition.cpp +++ b/benchmark/parsingcompetition.cpp @@ -27,13 +27,7 @@ SIMDJSON_PUSH_DISABLE_ALL_WARNINGS #include using json = nlohmann::json; -#if defined(__clang__) -// Under some clang/libc++ configurations, boost json fails -// to build. -#define DISABLE_BOOST_JSON -#endif - -#ifndef DISABLE_BOOST_JSON +#ifdef HAS_BOOST_JSON #include #include #endif @@ -185,7 +179,7 @@ bool bench(const char *filename, bool verbose, bool just_data, std::memcpy(buffer, p.data(), p.size()) && (buffer[p.size()] = '\0'), repeat, volume, !just_data); -#ifndef DISABLE_BOOST_JSON +#ifdef HAS_BOOST_JSON { const boost::json::string_view sv(p.data(), p.size()); boost::json::parser p; diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt index 8ec83bcb..51ab3a31 100644 --- a/dependencies/CMakeLists.txt +++ b/dependencies/CMakeLists.txt @@ -14,13 +14,15 @@ endif() # This prevents variables declared with set() from unnecessarily escaping and # should not be called more than once function(competition_scope_) - # Boost JSON is not compatible with some clang/libc++ configurations. - if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") - import_dependency(boostjson CPPAlliance/json a0983f7) - add_library(boostjson STATIC "${boostjson_SOURCE_DIR}/src/src.cpp") - target_compile_definitions(boostjson PUBLIC BOOST_JSON_STANDALONE) - target_include_directories(boostjson SYSTEM PUBLIC - "${boostjson_SOURCE_DIR}/include") + # boost json in standalone mode requires C++17 string_view + include(CheckCXXSourceCompiles) + check_cxx_source_compiles("#include \n#if __cpp_lib_string_view < 201606\n#error no string view support\n#endif\nint main(){}" USE_BOOST_JSON) + if(USE_BOOST_JSON) + import_dependency(boostjson boostorg/json ee8d72d8502b409b5561200299cad30ccdb91415) + add_library(boostjson STATIC "${boostjson_SOURCE_DIR}/src/src.cpp") + target_compile_definitions(boostjson PUBLIC BOOST_JSON_STANDALONE) + target_include_directories(boostjson SYSTEM PUBLIC + "${boostjson_SOURCE_DIR}/include") endif() import_dependency(cjson DaveGamble/cJSON c69134d) @@ -87,8 +89,9 @@ function(competition_scope_) add_library(competition-core INTERFACE) target_link_libraries(competition-core INTERFACE nlohmann_json rapidjson sajson cjson jsmn yyjson) - if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") - target_link_libraries(competition-core INTERFACE boostjson) + if(USE_BOOST_JSON) + target_compile_definitions(boostjson INTERFACE HAS_BOOST_JSON) + target_link_libraries(competition-core INTERFACE boostjson) endif() add_library(competition-all INTERFACE)