Skip to content

Commit 185274e

Browse files
authored
Let us see if we can test with libc++. (simdjson#732)
* Let us see if we can test with libc++. * Fixed spacing.
1 parent f0ac55e commit 185274e

File tree

4 files changed

+96
-18
lines changed

4 files changed

+96
-18
lines changed

.circleci/config.yml

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ executors:
2525
CXX: g++
2626
BUILD_FLAGS: -j
2727
CTEST_FLAGS: -j4 --output-on-failure
28+
clang9:
29+
docker:
30+
- image: conanio/clang9
31+
environment:
32+
CXX: clang++-9
33+
BUILD_FLAGS: -j
34+
CTEST_FLAGS: -j4 --output-on-failure
2835

2936
clang6:
3037
docker:
@@ -50,10 +57,13 @@ commands:
5057
- run: make test
5158
- run: make checkperf
5259

53-
cmake_prep:
60+
install_cmake:
5461
steps:
5562
- run: apt-get update -qq
5663
- run: apt-get install -y cmake
64+
65+
cmake_prep:
66+
steps:
5767
- checkout
5868

5969
cmake_build:
@@ -78,6 +88,7 @@ commands:
7888
- run: SIMDJSON_FORCE_IMPLEMENTATION=fallback ctest $CTEST_FLAGS -L per_implementation
7989
- run: ctest $CTEST_FLAGS -LE "acceptance|per_implementation" # Everything we haven't run yet, run now.
8090

91+
8192
# we not only want cmake to build and run tests, but we want also a successful installation from which we can build, link and run programs
8293
cmake_install_test: # this version builds, install, test and then verify from the installation
8394
steps:
@@ -91,60 +102,65 @@ jobs:
91102
description: Build and run tests on GCC 7 and AVX 2 with a cmake static build
92103
executor: gcc7
93104
environment: { CMAKE_FLAGS: -DSIMDJSON_GOOGLE_BENCHMARKS=ON }
94-
steps: [ cmake_test_all, cmake_install_test ]
105+
steps: [ install_cmake, cmake_test_all, cmake_install_test ]
95106
clang6:
96107
description: Build and run tests on clang 6 and AVX 2 with a cmake static build
97108
executor: clang6
98109
environment: { CMAKE_FLAGS: -DSIMDJSON_GOOGLE_BENCHMARKS=ON }
99-
steps: [ init_clang6, cmake_test_all, cmake_install_test ]
100-
110+
steps: [ init_clang6, install_cmake, cmake_test_all, cmake_install_test ]
111+
# libcpp
112+
libcpp-clang9:
113+
description: Build and run tests on clang 6 and AVX 2 with a cmake static build and libc++
114+
executor: clang9
115+
environment: { CMAKE_FLAGS: -DSIMDJSON_USE_LIBCPP=ON }
116+
steps: [ cmake_test_all, cmake_install_test ]
101117
# sanitize
102118
sanitize-gcc9:
103119
description: Build and run tests on GCC 9 and AVX 2 with a cmake sanitize build
104120
executor: gcc9
105121
environment: { CMAKE_FLAGS: -DSIMDJSON_BUILD_STATIC=OFF -DSIMDJSON_SANITIZE=ON, CTEST_FLAGS: -j4 --output-on-failure -E checkperf }
106-
steps: [ cmake_test_all ]
122+
steps: [ install_cmake, cmake_test_all ]
107123
sanitize-clang6:
108124
description: Build and run tests on clang 6 and AVX 2 with a cmake sanitize build
109125
executor: clang6
110126
environment: { CMAKE_FLAGS: -DSIMDJSON_BUILD_STATIC=OFF -DSIMDJSON_SANITIZE=ON, CTEST_FLAGS: -j4 --output-on-failure -E checkperf }
111-
steps: [ init_clang6, cmake_test_all ]
127+
steps: [ init_clang6, install_cmake, cmake_test_all ]
112128

113129
# dynamic
114130
dynamic-gcc7:
115131
description: Build and run tests on GCC 7 and AVX 2 with a cmake dynamic build
116132
executor: gcc7
117133
environment: { CMAKE_FLAGS: -DSIMDJSON_BUILD_STATIC=OFF }
118-
steps: [ cmake_test, cmake_install_test ]
134+
steps: [ install_cmake, cmake_test, cmake_install_test ]
119135
dynamic-clang6:
120136
description: Build and run tests on clang 6 and AVX 2 with a cmake dynamic build
121137
executor: clang6
122138
environment: { CMAKE_FLAGS: -DSIMDJSON_BUILD_STATIC=OFF }
123-
steps: [ init_clang6, cmake_test, cmake_install_test ]
139+
steps: [ init_clang6, install_cmake, cmake_test, cmake_install_test ]
124140

125141
# unthreaded
126142
unthreaded-gcc7:
127143
description: Build and run tests on GCC 7 and AVX 2 *without* threads
128144
executor: gcc7
129145
environment: { CMAKE_FLAGS: -DSIMDJSON_ENABLE_THREADS=OFF }
130-
steps: [ cmake_test, cmake_install_test ]
146+
steps: [ install_cmake, cmake_test, cmake_install_test ]
131147
unthreaded-clang6:
132148
description: Build and run tests on Clang 6 and AVX 2 *without* threads
133149
executor: clang6
134150
environment: { CMAKE_FLAGS: -DSIMDJSON_ENABLE_THREADS=OFF }
135-
steps: [ init_clang6, cmake_test, cmake_install_test ]
151+
steps: [ init_clang6, install_cmake, cmake_test, cmake_install_test ]
136152

137153
# noexcept
138154
noexcept-gcc7:
139155
description: Build and run tests on GCC 7 and AVX 2 with exceptions off
140156
executor: gcc7
141157
environment: { CMAKE_FLAGS: -DSIMDJSON_EXCEPTIONS=OFF }
142-
steps: [ cmake_test, cmake_install_test ]
158+
steps: [ install_cmake, cmake_test, cmake_install_test ]
143159
noexcept-clang6:
144160
description: Build and run tests on GCC 7 and AVX 2 with exceptions off
145161
executor: clang6
146162
environment: { CMAKE_FLAGS: -DSIMDJSON_EXCEPTIONS=OFF }
147-
steps: [ init_clang6, cmake_test, cmake_install_test ]
163+
steps: [ init_clang6, install_cmake, cmake_test, cmake_install_test ]
148164

149165
#
150166
# Misc.
@@ -174,7 +190,10 @@ workflows:
174190
# full multi-implementation tests
175191
- gcc7
176192
- clang6
177-
193+
194+
# libc++
195+
- libcpp-clang9
196+
178197
# full single-implementation tests
179198
- sanitize-gcc9
180199
- sanitize-clang6

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ if(MSVC)
2525
else()
2626
option(SIMDJSON_BUILD_STATIC "Build a static library" OFF) # turning it on disables the production of a dynamic library
2727
option(SIMDJSON_COMPETITION "Compile competitive benchmarks" ON)
28+
option(SIMDJSON_USE_LIBCPP "Use the libc++ library" OFF)
2829
endif()
2930
option(SIMDJSON_GOOGLE_BENCHMARKS "compile the Google Benchmark benchmarks" OFF)
3031

3132
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake")
3233

34+
3335
# We compile tools, tests, etc. with C++ 17. Override yourself if you need on a target.
3436
set(CMAKE_CXX_STANDARD 17)
3537
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -38,6 +40,7 @@ set(CMAKE_MACOSX_RPATH OFF)
3840
set(CMAKE_THREAD_PREFER_PTHREAD ON)
3941
set(THREADS_PREFER_PTHREAD_FLAG ON)
4042

43+
4144
# LTO seems to create all sorts of fun problems. Let us
4245
# disable temporarily.
4346
#include(CheckIPOSupported)
@@ -58,6 +61,17 @@ else()
5861
target_compile_options(simdjson-flags INTERFACE -Werror -Wall -Wextra -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self)
5962
endif()
6063

64+
65+
if(SIMDJSON_USE_LIBCPP)
66+
target_link_libraries(simdjson-flags INTERFACE -stdlib=libc++ -lc++abi)
67+
# instead of the above line, we could have used
68+
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
69+
# The next line is needed empirically.
70+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
71+
# we update CMAKE_SHARED_LINKER_FLAGS, this gets updated later as well
72+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lc++abi")
73+
endif(SIMDJSON_USE_LIBCPP)
74+
6175
# Optional flags
6276
option(SIMDJSON_IMPLEMENTATION_HASWELL "Include the haswell implementation" ON)
6377
if(NOT SIMDJSON_IMPLEMENTATION_HASWELL)

examples/quickstart/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
#
44

55
# TODO haven't quite decided the right way to run quickstart on Windows. Needs README update.
6-
if (NOT MSVC)
6+
#
7+
# Note: on macOS and other platforms, the 'command' described below may not work even if the cmake builds.
8+
# For example, it may be necessary to specify the sysroot, which CMake does, but the 'command' does not
9+
# handle such niceties. On a case-by-case basis it is fixable but it requires work that CMake knows how
10+
# to do but that is not trivial.
11+
#
12+
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
713
# TODO run amalgamate first!
814
function(add_quickstart_test TEST_NAME SOURCE_FILE)
915
# Second argument is C++ standard name

include/simdjson/common_defs.h

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,57 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
121121

122122
#endif // MSC_VER
123123

124+
125+
126+
// C++17 requires string_view.
127+
#if SIMDJSON_CPLUSPLUS17
128+
#define SIMDJSON_HAS_STRING_VIEW
129+
#endif
130+
131+
// This macro (__cpp_lib_string_view) has to be defined
132+
// for C++17 and better, but if it is otherwise defined,
133+
// we are going to assume that string_view is available
134+
// even if we do not have C++17 support.
135+
#ifdef __cpp_lib_string_view
136+
#define SIMDJSON_HAS_STRING_VIEW
137+
#endif
138+
139+
// Some systems have string_view even if we do not have C++17 support,
140+
// and even if __cpp_lib_string_view is undefined, it is the case
141+
// with Apple clang version 11.
142+
// We must handle it. *This is important.*
143+
#ifndef SIMDJSON_HAS_STRING_VIEW
144+
#if defined __has_include
145+
// do not combine the next #if with the previous one (unsafe)
146+
#if __has_include (<string_view>)
147+
// now it is safe to trigger the include
148+
#include <string_view> // though the file is there, it does not follow that we got the implementation
149+
#if defined(_LIBCPP_STRING_VIEW)
150+
// Ah! So we under libc++ which under its Library Fundamentals Technical Specification, which preceeded C++17,
151+
// included string_view.
152+
// This means that we have string_view *even though* we may not have C++17.
153+
#define SIMDJSON_HAS_STRING_VIEW
154+
#endif // _LIBCPP_STRING_VIEW
155+
#endif // __has_include (<string_view>)
156+
#endif // defined __has_include
157+
#endif // def SIMDJSON_HAS_STRING_VIEW
158+
// end of complicated but important routine to try to detect string_view.
159+
124160
//
125-
// Backfill std::string_view using nonstd::string_view on C++11
161+
// Backfill std::string_view using nonstd::string_view on systems where
162+
// we expect that string_view is missing. Important: if we get this wrong,
163+
// we will end up with two string_view definitions and potential trouble.
164+
// That is why we work so hard above to avoid it.
126165
//
127-
#if (!SIMDJSON_CPLUSPLUS17)
128-
166+
#ifndef SIMDJSON_HAS_STRING_VIEW
129167
SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
130168
#include "simdjson/nonstd/string_view.hpp"
131169
SIMDJSON_POP_DISABLE_WARNINGS
132170

133171
namespace std {
134172
using string_view = nonstd::string_view;
135173
}
136-
#endif // if (SIMDJSON_CPLUSPLUS < 201703L)
174+
#endif // SIMDJSON_HAS_STRING_VIEW
175+
#undef SIMDJSON_HAS_STRING_VIEW // We are not going to need this macro anymore.
137176

138177
#endif // SIMDJSON_COMMON_DEFS_H

0 commit comments

Comments
 (0)