Skip to content

Commit f62ca21

Browse files
authored
enable boost json (simdjson#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
1 parent 553befa commit f62ca21

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

.drone.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,27 @@ steps:
183183
- ASAN_OPTIONS="detect_leaks=0" ctest $CTEST_FLAGS -LE "acceptance|per_implementation" # Everything we haven't run yet, run now.
184184
---
185185
kind: pipeline
186+
name: cpp20-clang11-libcpp
187+
platform: { os: linux, arch: amd64 }
188+
steps:
189+
- name: Build and Test
190+
image: pauldreik/llvm-11
191+
user: root
192+
environment:
193+
CC: clang-11
194+
CXX: clang++-11
195+
CMAKE_FLAGS: -GNinja
196+
BUILD_FLAGS:
197+
CTEST_FLAGS: -j4 --output-on-failure -E checkperf
198+
CXXFLAGS: -std=c++20 -stdlib=libc++
199+
commands:
200+
- mkdir build
201+
- cd build
202+
- cmake $CMAKE_FLAGS ..
203+
- cmake --build . $BUILD_FLAGS
204+
- ctest $CTEST_FLAGS
205+
---
206+
kind: pipeline
186207
name: arm64-gcc8
187208
platform: { os: linux, arch: arm64 }
188209
steps:

benchmark/parsingcompetition.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
2727
#include <nlohmann/json.hpp>
2828
using json = nlohmann::json;
2929

30-
#if defined(__clang__)
31-
// Under some clang/libc++ configurations, boost json fails
32-
// to build.
33-
#define DISABLE_BOOST_JSON
34-
#endif
35-
36-
#ifndef DISABLE_BOOST_JSON
30+
#ifdef HAS_BOOST_JSON
3731
#include <boost/json/parser.hpp>
3832
#include <boost/json/monotonic_resource.hpp>
3933
#endif
@@ -185,7 +179,7 @@ bool bench(const char *filename, bool verbose, bool just_data,
185179
std::memcpy(buffer, p.data(), p.size()) &&
186180
(buffer[p.size()] = '\0'),
187181
repeat, volume, !just_data);
188-
#ifndef DISABLE_BOOST_JSON
182+
#ifdef HAS_BOOST_JSON
189183
{
190184
const boost::json::string_view sv(p.data(), p.size());
191185
boost::json::parser p;

dependencies/CMakeLists.txt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ endif()
1414
# This prevents variables declared with set() from unnecessarily escaping and
1515
# should not be called more than once
1616
function(competition_scope_)
17-
# Boost JSON is not compatible with some clang/libc++ configurations.
18-
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
19-
import_dependency(boostjson CPPAlliance/json a0983f7)
20-
add_library(boostjson STATIC "${boostjson_SOURCE_DIR}/src/src.cpp")
21-
target_compile_definitions(boostjson PUBLIC BOOST_JSON_STANDALONE)
22-
target_include_directories(boostjson SYSTEM PUBLIC
23-
"${boostjson_SOURCE_DIR}/include")
17+
# boost json in standalone mode requires C++17 string_view
18+
include(CheckCXXSourceCompiles)
19+
check_cxx_source_compiles("#include <string_view>\n#if __cpp_lib_string_view < 201606\n#error no string view support\n#endif\nint main(){}" USE_BOOST_JSON)
20+
if(USE_BOOST_JSON)
21+
import_dependency(boostjson boostorg/json ee8d72d8502b409b5561200299cad30ccdb91415)
22+
add_library(boostjson STATIC "${boostjson_SOURCE_DIR}/src/src.cpp")
23+
target_compile_definitions(boostjson PUBLIC BOOST_JSON_STANDALONE)
24+
target_include_directories(boostjson SYSTEM PUBLIC
25+
"${boostjson_SOURCE_DIR}/include")
2426
endif()
2527

2628
import_dependency(cjson DaveGamble/cJSON c69134d)
@@ -87,8 +89,9 @@ function(competition_scope_)
8789

8890
add_library(competition-core INTERFACE)
8991
target_link_libraries(competition-core INTERFACE nlohmann_json rapidjson sajson cjson jsmn yyjson)
90-
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
91-
target_link_libraries(competition-core INTERFACE boostjson)
92+
if(USE_BOOST_JSON)
93+
target_compile_definitions(boostjson INTERFACE HAS_BOOST_JSON)
94+
target_link_libraries(competition-core INTERFACE boostjson)
9295
endif()
9396

9497
add_library(competition-all INTERFACE)

0 commit comments

Comments
 (0)