-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #704 from theirix/simdjson
Add simdjson/0.2.1
- Loading branch information
Showing
7 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.9) | ||
|
||
project(cmake_wrapper) | ||
|
||
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") | ||
conan_basic_setup() | ||
|
||
add_subdirectory(source_subfolder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sources: | ||
"0.2.1": | ||
url: "https://github.com/lemire/simdjson/archive/v0.2.1.tar.gz" | ||
sha256: "361ad30048005421073b284e6e0c1dcfe46daeecca32e6b5a5a5e7e31df1fdb5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import os | ||
from conans import ConanFile, CMake, tools | ||
from conans.errors import ConanInvalidConfiguration | ||
from conans.tools import Version | ||
|
||
|
||
class SimdjsonConan(ConanFile): | ||
name = "simdjson" | ||
description = "Parsing gigabytes of JSON per second" | ||
topics = ("conan", "json", "parser", "simd", "format") | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://github.com/lemire/simdjson" | ||
license = "Apache-2.0" | ||
exports_sources = ["CMakeLists.txt"] | ||
generators = "cmake" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = {"shared": [True, False], | ||
"fPIC": [True, False], | ||
"threads": [True, False], | ||
"avx": [True, False]} | ||
default_options = {'shared': False, | ||
'fPIC': True, | ||
'threads': True, | ||
'avx': True} | ||
_source_subfolder = "source_subfolder" | ||
|
||
@property | ||
def _supported_cppstd(self): | ||
return ["17", "gnu17", "20", "gnu20"] | ||
|
||
def _has_support_for_cpp17(self): | ||
supported_compilers = [("apple-clang", 10), ("clang", 6), ("gcc", 7), ("Visual Studio", 15.7)] | ||
compiler, version = self.settings.compiler, Version(self.settings.compiler.version) | ||
return any(compiler == sc[0] and version >= sc[1] for sc in supported_compilers) | ||
|
||
def configure(self): | ||
if self.settings.compiler == "Visual Studio": | ||
self.options.remove("fPIC") | ||
if self.settings.compiler.cppstd and \ | ||
not self.settings.compiler.cppstd in self._supported_cppstd: | ||
raise ConanInvalidConfiguration("This library requires c++17 standard or higher." | ||
" {} required." | ||
.format(self.settings.compiler.cppstd)) | ||
|
||
if not self._has_support_for_cpp17(): | ||
raise ConanInvalidConfiguration("This library requires C++17 or higher support standard." | ||
" {} {} is not supported." | ||
.format(self.settings.compiler, self.settings.compiler.version)) | ||
|
||
def source(self): | ||
tools.get(**self.conan_data["sources"][self.version]) | ||
extracted_dir = self.name + "-" + self.version | ||
os.rename(extracted_dir, self._source_subfolder) | ||
|
||
# In version 0.2.1 CMAKE_CXX_FLAGS are ignored | ||
tools.replace_in_file(os.path.join(self._source_subfolder, 'tools', 'cmake', 'FindOptions.cmake'), | ||
'set(CMAKE_CXX_FLAGS "${CXXSTD_FLAGS}', | ||
'set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXSTD_FLAGS}', | ||
strict=False) | ||
|
||
# Generating export files by CMake via __export_def (enabled by property WINDOWS_EXPORT_ALL_SYMBOLS) | ||
# does not work with whole program optimization. | ||
# So disable INTERPROCEDURAL_OPTIMIZATION | ||
if self.settings.compiler == "Visual Studio" and self.options.shared: | ||
tools.replace_in_file(os.path.join(self._source_subfolder, 'CMakeLists.txt'), | ||
'set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)', | ||
'set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)') | ||
|
||
def _configure_cmake(self): | ||
cmake = CMake(self) | ||
cmake.definitions['SIMDJSON_BUILD_STATIC'] = not self.options.shared | ||
cmake.definitions['SIMDJSON_ENABLE_THREADS'] = self.options.threads | ||
cmake.definitions['SIMDJSON_DISABLE_AVX'] = not self.options.avx | ||
cmake.definitions['SIMDJSON_SANITIZE'] = False | ||
cmake.definitions['ENABLE_FUZZING'] = False | ||
cmake.configure() | ||
return cmake | ||
|
||
def build(self): | ||
cmake = self._configure_cmake() | ||
cmake.build() | ||
|
||
def package(self): | ||
cmake = self._configure_cmake() | ||
cmake.install() | ||
# remove unneeded directories | ||
tools.rmdir(os.path.join(self.package_folder, 'lib', 'cmake')) | ||
tools.rmdir(os.path.join(self.package_folder, 'lib', 'pkgconfig')) | ||
|
||
self.copy("license", src=self._source_subfolder, dst="licenses", ignore_case=True, keep_path=False) | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = ['simdjson'] | ||
if self.settings.os == "Linux": | ||
self.cpp_info.system_libs = ["m"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cmake_minimum_required(VERSION 3.9) | ||
project(test_package) | ||
|
||
set(CMAKE_VERBOSE_MAKEFILE TRUE) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
|
||
add_executable(${PROJECT_NAME} test_package.cpp) | ||
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) | ||
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from conans import ConanFile, CMake, tools | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake" | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not tools.cross_building(self.settings): | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run(bin_path, run_environment=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include "simdjson/jsonparser.h" | ||
|
||
int main() { | ||
std::string mystring = "{ \"hello\": \"simdjson\" }"; | ||
simdjson::ParsedJson pj = simdjson::build_parsed_json(mystring); | ||
if (!pj.is_valid()) { | ||
// something went wrong | ||
std::cout << pj.get_error_message() << std::endl; | ||
return 1; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"0.2.1": | ||
folder: all |