diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index 6ec6ccbc..e36545b7 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -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 diff --git a/.github/workflows/macos-clang.yaml b/.github/workflows/macos-clang.yaml index 60b82af3..e12e7028 100644 --- a/.github/workflows/macos-clang.yaml +++ b/.github/workflows/macos-clang.yaml @@ -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 diff --git a/.github/workflows/windows-msvc.yaml b/.github/workflows/windows-msvc.yaml index 73cdb4e5..66f901fe 100644 --- a/.github/workflows/windows-msvc.yaml +++ b/.github/workflows/windows-msvc.yaml @@ -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: @@ -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 + diff --git a/.gitignore b/.gitignore index d96f2b9a..801e1bf5 100644 --- a/.gitignore +++ b/.gitignore @@ -81,9 +81,10 @@ lib64/ parts/ sdist/ var/ +vcpkg_installed/ wheels/ share/python-wheels/ *.egg-info/ .installed.cfg *.egg -MANIFEST \ No newline at end of file +MANIFEST diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e16468e..6018ce35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,7 +75,6 @@ if (REFLECTCPP_USE_BUNDLED_DEPENDENCIES) $) else () find_package(ctre CONFIG REQUIRED) - target_link_libraries(reflectcpp PUBLIC ctre::ctre) endif () if (REFLECTCPP_JSON) diff --git a/README.md b/README.md index 176bc388..1d350ba4 100644 --- a/README.md +++ b/README.md @@ -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 | @@ -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 @@ -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 diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 00000000..8b3272e8 --- /dev/null +++ b/conanfile.py @@ -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", + } diff --git a/docs/install.md b/docs/install.md index d63143fc..88f4cec1 100644 --- a/docs/install.md +++ b/docs/install.md @@ -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. @@ -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_.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. @@ -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: @@ -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 +``` diff --git a/docs/plugins/people.yml b/docs/plugins/people.yml index 319e3110..4ea5a32d 100644 --- a/docs/plugins/people.yml +++ b/docs/plugins/people.yml @@ -1,14 +1,14 @@ maintainers: -- 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 +- login: Urfoex + answers: 0 + prs: 4 + avatarUrl: https://avatars.githubusercontent.com/u/1561354?v=4 + url: https://github.com/Urfoex experts: [] last_month_active: [] top_contributors: diff --git a/vcpkg b/vcpkg index f7423ee1..cd124b84 160000 --- a/vcpkg +++ b/vcpkg @@ -1 +1 @@ -Subproject commit f7423ee180c4b7f40d43402c2feb3859161ef625 +Subproject commit cd124b84feb0c02a24a2d90981e8358fdee0e077 diff --git a/vcpkg.json b/vcpkg.json index 7b19a54a..2911e623 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,7 +1,7 @@ { "name": "reflectcpp", - "version-string": "0.8.0", - "builtin-baseline": "50bffcc62d7f6571eb32bc1a0b1807e77af1166c", + "version-string": "0.16.0", + "builtin-baseline": "cd124b84feb0c02a24a2d90981e8358fdee0e077", "dependencies": [ { "name": "ctre", @@ -53,7 +53,7 @@ }, { "name": "yyjson", - "version>=": "0.9.0" + "version>=": "0.10.0" }, { "name": "benchmark",