Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simdjson/0.2.1 #704

Merged
merged 14 commits into from
Jan 29, 2020
8 changes: 8 additions & 0 deletions recipes/simdjson/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.9)
uilianries marked this conversation as resolved.
Show resolved Hide resolved

project(cmake_wrapper)

include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup()

add_subdirectory(source_subfolder)
4 changes: 4 additions & 0 deletions recipes/simdjson/all/conandata.yml
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"
95 changes: 95 additions & 0 deletions recipes/simdjson/all/conanfile.py
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']
theirix marked this conversation as resolved.
Show resolved Hide resolved
if self.settings.os == "Linux":
self.cpp_info.system_libs = ["m"]
11 changes: 11 additions & 0 deletions recipes/simdjson/all/test_package/CMakeLists.txt
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)
17 changes: 17 additions & 0 deletions recipes/simdjson/all/test_package/conanfile.py
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)
14 changes: 14 additions & 0 deletions recipes/simdjson/all/test_package/test_package.cpp
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;
}
3 changes: 3 additions & 0 deletions recipes/simdjson/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.2.1":
folder: all