Skip to content

Commit

Permalink
Merge branch 'main' into f/avro
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzicheng1987 committed Dec 1, 2024
2 parents 687c881 + b98f0e5 commit 8f81ce1
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 18 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ jobs:
run: |
sudo apt update
sudo apt install -y ninja-build ${{ matrix.additional-dep }}
- name: Install Conan
run: |
sudo apt install -y pipx
pipx install conan
conan profile detect
- name: Make sure the library compiles with Conan
run: conan build . --build=missing -s compiler.cppstd=gnu20 -o *:with_cbor=True -o *:with_flatbuffers=True -o *:with_msgpack=True -o *:with_toml=True -o *:with_ubjson=True -o *:with_xml=True -o *:with_yaml=True
- name: Compile
run: |
if [[ "${{ matrix.compiler }}" == "llvm" ]]; then
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/macos-clang.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,19 @@ jobs:
create-symlink: true
- name: Run vcpkg
uses: lukka/run-vcpkg@v11
- name: Install Conan
run: |
brew install pipx
pipx install conan
conan profile detect
- name: Install ninja
run: brew install ninja
if: matrix.os == 'macos-latest'
- name: Make sure the library compiles with Conan
env:
CC: clang
CXX: clang++
run: conan build . --build=missing -s compiler.cppstd=gnu20 -o *:with_cbor=True -o *:with_flatbuffers=True -o *:with_msgpack=True -o *:with_toml=True -o *:with_ubjson=True -o *:with_xml=True -o *:with_yaml=True
- name: Compile
env:
CC: clang
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/windows-msvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"

jobs:
windows-msvc-conan:
runs-on: windows-latest
windows-msvc:
runs-on: windows-latest
steps:
Expand Down Expand Up @@ -47,3 +49,4 @@ jobs:
.\build\benchmarks\json\Release\reflect-cpp-json-benchmarks.exe --benchmark_filter=canada >> $env:GITHUB_STEP_SUMMARY
.\build\benchmarks\json\Release\reflect-cpp-json-benchmarks.exe --benchmark_filter=licenses >> $env:GITHUB_STEP_SUMMARY
echo '```' >> $env:GITHUB_STEP_SUMMARY
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ lib64/
parts/
sdist/
var/
vcpkg_installed/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
MANIFEST
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ if (REFLECTCPP_USE_BUNDLED_DEPENDENCIES)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/rfl/thirdparty>)
else ()
find_package(ctre CONFIG REQUIRED)
target_link_libraries(reflectcpp PUBLIC ctre::ctre)
endif ()

if (REFLECTCPP_JSON)
Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ The following table lists the serialization formats currently supported by refle

| Format | Library | Version | License | Remarks |
|--------------|------------------------------------------------------|--------------|------------| -----------------------------------------------------|
| JSON | [yyjson](https://github.com/ibireme/yyjson) | 0.8.0 | MIT | out-of-the-box support, included in this repository |
| JSON | [yyjson](https://github.com/ibireme/yyjson) | >= 0.8.0 | MIT | out-of-the-box support, included in this repository |
| BSON | [libbson](https://github.com/mongodb/mongo-c-driver) | >= 1.25.1 | Apache 2.0 | JSON-like binary format |
| CBOR | [tinycbor](https://github.com/intel/tinycbor) | >= 0.6.0 | MIT | JSON-like binary format |
| flexbuffers | [flatbuffers](https://github.com/google/flatbuffers) | >= 23.5.26 | Apache 2.0 | Schema-less version of flatbuffers, binary format |
Expand All @@ -82,7 +82,7 @@ The following table lists the serialization formats currently supported by refle

Support for more serialization formats is in development. Refer to the [issues](https://github.com/getml/reflect-cpp/issues) for details.

Please also refer to the *vcpkg.json* in this repository.
Please also refer to the *conanfile.py* or *vcpkg.json* in this repository.


## Feature Overview
Expand Down Expand Up @@ -543,6 +543,21 @@ The following compilers are supported:
- Clang 14.0 or higher
- MSVC 17.8 (19.38) or higher
### Using vcpkg
```bash
vcpkg install reflectcpp
```

or:

```bash
vcpkg add port reflectcpp
```

If the library cannot be found, please update vcpkg itself and/or update the `builtin-baseline`
tag in the *vcpkg.json* of your project.

### Using Conan

https://conan.io/center/recipes/reflect-cpp
Expand Down
147 changes: 147 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
from conan import ConanFile
from conan.tools.files import get, copy, rmdir
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps


from conan.tools.env import VirtualBuildEnv
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.errors import ConanInvalidConfiguration

import os

required_conan_version = ">=1.54"


class ReflectCppConan(ConanFile):
name = "reflectcpp"
description = "C++-20 library for fast serialization, deserialization and validation using reflection"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/getml/reflect-cpp"
topics = (
"reflection",
"serialization",
"memory",
"cbor",
"flatbuffers",
"json",
"msgpack",
"toml",
"xml",
"yaml",
)
package_type = "library"
settings = "os", "arch", "compiler", "build_type"

options = {
"shared": [True, False],
"fPIC": [True, False],
"with_cbor": [True, False],
"with_flatbuffers": [True, False],
"with_msgpack": [True, False],
"with_toml": [True, False],
"with_ubjson": [True, False],
"with_xml": [True, False],
"with_yaml": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_cbor": False,
"with_flatbuffers": False,
"with_msgpack": False,
"with_toml": False,
"with_ubjson": False,
"with_xml": False,
"with_yaml": False,
}

def config_options(self):
if self.settings.os == "Windows":
self.options.rm_safe("fPIC")

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

def requirements(self):
self.requires("ctre/3.9.0", transitive_headers=True)
self.requires("yyjson/0.10.0", transitive_headers=True)
if self.options.with_cbor:
self.requires("tinycbor/0.6.0", transitive_headers=True)
if self.options.with_flatbuffers:
self.requires("flatbuffers/24.3.25", transitive_headers=True)
if self.options.with_msgpack:
self.requires("msgpack-c/6.0.0", transitive_headers=True)
if self.options.with_toml:
self.requires("tomlplusplus/3.4.0", transitive_headers=True)
if self.options.with_ubjson:
self.requires("jsoncons/0.176.0", transitive_headers=True)
if self.options.with_xml:
self.requires("pugixml/1.14", transitive_headers=True)
if self.options.with_yaml:
self.requires("yaml-cpp/0.8.0", transitive_headers=True)

def build_requirements(self):
self.tool_requires("cmake/[>=3.23 <4]")

def validate(self):
if self.settings.get_safe("compiler.cppstd"):
check_min_cppstd(self, self._min_cppstd)

def layout(self):
cmake_layout(self, src_folder=".")

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

def generate(self):
env = VirtualBuildEnv(self)
env.generate()
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.cache_variables["REFLECTCPP_BUILD_SHARED"] = self.options.shared
tc.cache_variables["REFLECTCPP_USE_BUNDLED_DEPENDENCIES"] = False
tc.cache_variables["REFLECTCPP_USE_VCPKG"] = False
tc.cache_variables["REFLECTCPP_CBOR"] = self.options.with_cbor
tc.cache_variables["REFLECTCPP_FLEXBUFFERS"] = self.options.with_flatbuffers
tc.cache_variables["REFLECTCPP_MSGPACK"] = self.options.with_msgpack
tc.cache_variables["REFLECTCPP_TOML"] = self.options.with_toml
tc.cache_variables["REFLECTCPP_XML"] = self.options.with_xml
tc.cache_variables["REFLECTCPP_YAML"] = self.options.with_yaml
tc.generate()

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

def package(self):
copy(
self,
pattern="LICENSE",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder,
)
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.libs = ["reflectcpp"]

@property
def _min_cppstd(self):
return 20

@property
def _compilers_minimum_version(self):
return {
"Visual Studio": "17",
"msvc": "1938",
"gcc": "11",
"clang": "13",
"apple-clang": "15",
}
51 changes: 46 additions & 5 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,26 @@ The following compilers are supported:

You can include the source files into your build or compile it using cmake and vcpkg.

## Option 1: Using Conan
## Option 1: Using vcpkg

```bash
vcpkg install reflectcpp
```

or, if you are in manifest mode:

```bash
vcpkg add port reflectcpp
```

If the library cannot be found, please update vcpkg itself to make sure the newest ports are installed. You
might also want to update the `builtin-baseline` tag in the *vcpkg.json* of your project.

## Option 2: Using Conan

Simply use the following [recipe](https://conan.io/center/recipes/reflect-cpp).

## Option 2: Compilation using cmake
## Option 3: Compilation using cmake

This will compile reflect-cpp with JSON support only. You can then include reflect-cpp in your project and link to the binary.

Expand All @@ -26,14 +41,14 @@ cmake --build build -j 4 # gcc, clang
cmake --build build --config Release -j 4 # MSVC
```

## Option 3: Include source files into your own build
## Option 4: Include source files into your own build

Simply copy the contents of the folders `include` and `src` into your source repository or add it to your include path and also add `src/reflectcpp.cpp` and `src/reflectcpp_json.cpp` and `src/yyjson.c` to your source files for compilation.
If you want to link to your own version of YYJSON, then only add `src/reflectcpp.cpp` and `src/reflectcpp_json.cpp`. If you don't need JSON support, then only add `src/reflectcpp.cpp`.

If you need support for other serialization formats like flexbuffers or XML, you should also add `src/reflectcpp_<format>.cpp` and include and link the respective libraries, as listed in the section on serialization formats.

## Option 4: Compilation using cmake and vcpkg
## Option 5: Compilation using cmake and vcpkg

If you want serialization formats other than JSON, you can either install them manually or use vcpkg.

Expand Down Expand Up @@ -63,7 +78,7 @@ set(REFLECTCPP_YAML ON) # Optional
target_link_libraries(your_project PRIVATE reflectcpp) # Link against the library
```

## Troubleshooting vcpkg
### Troubleshooting vcpkg

vcpkg is a great, but very ambitious and complex project (just like C++ is a great, but very ambitious and complex language). Here are some of the you might run into and how to resolve them:

Expand All @@ -72,3 +87,29 @@ vcpkg is a great, but very ambitious and complex project (just like C++ is a gre
2. *Environment variable VCPKG_FORCE_SYSTEM_BINARIES must be set on arm, s390x, ppc64le and riscv platforms.* - This usually happens on arm platforms like the Apple Silicon chips and can be resolved by simply preceding your build with `export VCPKG_FORCE_SYSTEM_BINARIES=arm` or `export VCPKG_FORCE_SYSTEM_BINARIES=1`.

3. On some occasions you might be asked to specify a compiler. You can do so by simply adding it to the cmake command as follows: `cmake -S . -B build ... -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++` or `cmake -S . -B build ... -DCMAKE_C_COMPILER=clang-17 -DCMAKE_CXX_COMPILER=clang++-17` (or whatever supported compiler you would like to use).

## Option 6: Compilation using Conan

To install Conan (assuming you have Python and pipx installed):

```bash
pipx install conan
conan profile detect
```

For older versions of pip, you can also use `pip` instead of `pipx`.

To install the basic (JSON-only) version, cd into the `reflect-cpp`
repository and execute the following:

```bash
conan build . --build=missing -s compiler.cppstd=gnu20
```

You can call `conan inspect .` to get an overview of the supported options.

If you want to include all supported formats, do the following:

```bash
conan build . --build=missing -s compiler.cppstd=gnu20 -o *:with_cbor=True -o *:with_flatbuffers=True -o *:with_msgpack=True -o *:with_toml=True -o *:with_ubjson=True -o *:with_xml=True -o *:with_yaml=True
```
10 changes: 5 additions & 5 deletions docs/plugins/people.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
maintainers:
- login: liuzicheng1987
answers: 0
prs: 66
avatarUrl: https://avatars.githubusercontent.com/u/19538706?u=1ca794b4e5aa9bbe50277f249e701eea86b0fdd3&v=4
url: https://github.com/liuzicheng1987
- login: Urfoex
answers: 0
prs: 4
avatarUrl: https://avatars.githubusercontent.com/u/1561354?v=4
url: https://github.com/Urfoex
- login: liuzicheng1987
answers: 0
prs: 65
avatarUrl: https://avatars.githubusercontent.com/u/19538706?u=1ca794b4e5aa9bbe50277f249e701eea86b0fdd3&v=4
url: https://github.com/liuzicheng1987
experts: []
last_month_active: []
top_contributors:
Expand Down
2 changes: 1 addition & 1 deletion vcpkg
Submodule vcpkg updated 4478 files
6 changes: 3 additions & 3 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "reflectcpp",
"version-string": "0.8.0",
"builtin-baseline": "50bffcc62d7f6571eb32bc1a0b1807e77af1166c",
"version-string": "0.16.0",
"builtin-baseline": "cd124b84feb0c02a24a2d90981e8358fdee0e077",
"dependencies": [
{
"name": "avro-c",
Expand Down Expand Up @@ -57,7 +57,7 @@
},
{
"name": "yyjson",
"version>=": "0.9.0"
"version>=": "0.10.0"
},
{
"name": "benchmark",
Expand Down

0 comments on commit 8f81ce1

Please sign in to comment.