Skip to content

Commit

Permalink
enhance: add rapidjson module (milvus-io#43)
Browse files Browse the repository at this point in the history
Signed-off-by: luzhang <luzhang@zilliz.com>
Co-authored-by: luzhang <luzhang@zilliz.com>
  • Loading branch information
zhagnlu and luzhang authored Aug 20, 2024
1 parent 2ed6e59 commit b7463e2
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 0 deletions.
17 changes: 17 additions & 0 deletions rapidjson/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
sources:
"1.1.0":
url: "https://github.com/Tencent/rapidjson/archive/v1.1.0.tar.gz"
sha256: bf7ced29704a1e696fbccf2a2b4ea068e7774fa37f6d7dd4039d0787f8bed98e
# More recent unofficial releases based on commits
"cci.20230929":
url: "https://github.com/Tencent/rapidjson/archive/f9d53419e912910fd8fa57d5705fa41425428c35.tar.gz"
sha256: "2b521dba5c22eaae6e6e7d4d304cb317e2cf8c687c70046b02792c02f78c127e"
"cci.20220822":
url: "https://github.com/Tencent/rapidjson/archive/06d58b9e848c650114556a23294d0b6440078c61.tar.gz"
sha256: 30d28bbe0bfff9d8dc5d3cf62799b6ee550499cc1520e44bdece81e002480d19
"cci.20211112":
url: "https://github.com/Tencent/rapidjson/archive/0d4517f15a8d7167ba9ae67f3f22a559ca841e3b.tar.gz"
sha256: 3697fdcea30dc7c2b2bb68d2521a6b8793f4d3269de751eed2c5fd477ff329ce
"cci.20200410":
url: "https://github.com/Tencent/rapidjson/archive/8f4c021fa2f1e001d2376095928fc0532adf2ae6.zip"
sha256: e6fc99c7df7f29995838a764dd68df87b71db360f7727ace467b21b82c85efda
43 changes: 43 additions & 0 deletions rapidjson/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from conan import ConanFile
from conan.tools.files import get, copy
from conan.tools.layout import basic_layout
import os

required_conan_version = ">=1.50.0"


class RapidjsonConan(ConanFile):
name = "rapidjson"
description = "A fast JSON parser/generator for C++ with both SAX/DOM style API"
topics = ("rapidjson", "json", "parser", "generator")
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://rapidjson.org"
license = "MIT"
package_type = "header-library"
package_id_embed_mode = "minor_mode"
settings = "os", "arch", "compiler", "build_type"
no_copy_source = True

def layout(self):
basic_layout(self, src_folder="src")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True,
destination=self.source_folder)

def package(self):
copy(self, pattern="license.txt", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, pattern="*", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include"))

def package_id(self):
self.info.clear()

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "RapidJSON")
self.cpp_info.set_property("cmake_target_name", "rapidjson")
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.names["cmake_find_package"] = "RapidJSON"
self.cpp_info.names["cmake_find_package_multi"] = "RapidJSON"
8 changes: 8 additions & 0 deletions rapidjson/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(test_package)

find_package(RapidJSON CONFIG REQUIRED)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE rapidjson)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
26 changes: 26 additions & 0 deletions rapidjson/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout

required_conan_version = ">=1.50.0"

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
self.run(os.path.join(self.cpp.build.bindirs[0], "test_package"), env="conanrun")
23 changes: 23 additions & 0 deletions rapidjson/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"

#include <iostream>

using namespace rapidjson;

int main() {
const char* json = "{\"working\":\"false\"}";
Document d;
d.Parse(json);

Value& w = d["working"];
w.SetString("true", 4);

StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
d.Accept(writer);

std::cout << buffer.GetString() << std::endl;
return 0;
}
11 changes: 11 additions & 0 deletions rapidjson/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.8)
project(test_package)

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

find_package(RapidJSON CONFIG REQUIRED)

add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE RapidJSON::RapidJSON)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
17 changes: 17 additions & 0 deletions rapidjson/all/test_v1_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", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
11 changes: 11 additions & 0 deletions rapidjson/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
versions:
"1.1.0":
folder: "all"
"cci.20230929":
folder: "all"
"cci.20220822":
folder: "all"
"cci.20211112":
folder: "all"
"cci.20200410":
folder: "all"

0 comments on commit b7463e2

Please sign in to comment.