Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,39 @@ jobs:
./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=canada >> $GITHUB_STEP_SUMMARY
./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=licenses >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
windows-msvc-shared:
strategy:
fail-fast: false
matrix:
format: ["JSON", "AVRO", "CAPNPROTO", "CBOR", "FLEXBUFFERS", "MSGPACK", "PARQUET", "TOML", "UBJSON", "XML", "YAML"]
name: "windows-msvc-shared (${{ matrix.format }})"
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- uses: ilammy/msvc-dev-cmd@v1
- uses: lukka/run-vcpkg@v11
- name: Compile tests (JSON)
if: matrix.format == 'JSON'
run: |
cmake -S . -B build -DREFLECTCPP_BUILD_SHARED=ON -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release -j4
- name: Compile tests (Other formats)
if: matrix.format != 'JSON'
run: |
cmake -S . -B build -DREFLECTCPP_BUILD_SHARED=ON -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_JSON=OFF -DREFLECTCPP_${{ matrix.format }}=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release -j4
- name: Run tests
run: |
ctest --test-dir build --output-on-failure


32 changes: 30 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,19 @@ else()
)
endif()

if(REFLECTCPP_BUILD_SHARED AND REFLECTCPP_USE_BUNDLED_DEPENDENCIES AND _REFLECTCPP_NEEDS_JSON_IMPL)
target_compile_definitions(reflectcpp
PRIVATE
YYJSON_EXPORTS
INTERFACE
YYJSON_IMPORTS
)
endif()

if(REFLECTCPP_BUILD_SHARED)
target_compile_definitions(reflectcpp PUBLIC RFL_BUILD_SHARED)
endif()

if(REFLECTCPP_USE_STD_EXPECTED)
target_compile_definitions(reflectcpp PUBLIC REFLECTCPP_USE_STD_EXPECTED)
endif()
Expand Down Expand Up @@ -232,7 +245,20 @@ if (REFLECTCPP_AVRO)
if (REFLECTCPP_USE_VCPKG)
target_include_directories(reflectcpp SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include")
if (MSVC)
target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/avro${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(_AVRO_STATIC_LIB "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/avro${CMAKE_STATIC_LIBRARY_SUFFIX}")
if(REFLECTCPP_BUILD_SHARED)
message(STATUS "With whole archive ${_AVRO_STATIC_LIB}")
target_link_libraries(reflectcpp
PUBLIC
$<LINK_LIBRARY:WHOLE_ARCHIVE,${_AVRO_STATIC_LIB}>
"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/snappy${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/lzma${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/jansson${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/zlib${CMAKE_STATIC_LIBRARY_SUFFIX}"
)
else()
target_link_libraries(reflectcpp PUBLIC "${_AVRO_STATIC_LIB}")
endif()
else ()
target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libavro${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif ()
Expand Down Expand Up @@ -370,9 +396,11 @@ target_sources(reflectcpp PRIVATE ${REFLECT_CPP_SOURCES})
target_precompile_headers(reflectcpp PRIVATE [["rfl.hpp"]] <iostream> <string> <functional>)

if (REFLECTCPP_BUILD_TESTS)
add_library(reflectcpp_tests_crt INTERFACE)
target_link_libraries(reflectcpp_tests_crt INTERFACE reflectcpp GTest::gtest_main)

enable_testing()
find_package(GTest CONFIG REQUIRED)
set(REFLECT_CPP_GTEST_LIB reflectcpp GTest::gtest_main)
add_subdirectory(tests)
endif ()

Expand Down
3 changes: 2 additions & 1 deletion include/rfl/Generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
#include "Object.hpp"
#include "Result.hpp"
#include "Variant.hpp"
#include "common.hpp"

namespace rfl {

class Generic {
class RFL_API Generic {
public:
constexpr static std::nullopt_t Null = std::nullopt;

Expand Down
3 changes: 2 additions & 1 deletion include/rfl/avro/SchemaImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

//#include "../Box.hpp"
//#include "../Result.hpp"
#include "../common.hpp"

namespace rfl::avro {

class SchemaImpl {
class RFL_API SchemaImpl {
public:
SchemaImpl(const std::string& _json_str);

Expand Down
3 changes: 2 additions & 1 deletion include/rfl/avro/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
#include "../Vectorstring.hpp"
#include "../always_false.hpp"
#include "../internal/is_literal.hpp"
#include "../common.hpp"

namespace rfl::avro {

class Writer {
class RFL_API Writer {
public:
struct AVROOutputArray {
avro_value_t val_;
Expand Down
3 changes: 2 additions & 1 deletion include/rfl/avro/schema/Type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
#include "../../Ref.hpp"
#include "../../Rename.hpp"
#include "../../Variant.hpp"
#include "../../common.hpp"

namespace rfl::avro::schema {

struct Type {
struct RFL_API Type {
struct Null {
Literal<"null"> type{};
};
Expand Down
3 changes: 2 additions & 1 deletion include/rfl/avro/to_schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
#include "Schema.hpp"
#include "Writer.hpp"
//#include "schema/Type.hpp"
#include "../common.hpp"

namespace rfl::avro {

std::string to_json_representation(
RFL_API std::string to_json_representation(
const parsing::schema::Definition& internal_schema);

/// Returns the Avro schema for a class.
Expand Down
3 changes: 2 additions & 1 deletion include/rfl/bson/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
#include "../Vectorstring.hpp"
#include "../always_false.hpp"
#include "../internal/ptr_cast.hpp"
#include "../common.hpp"

namespace rfl {
namespace bson {

/// Please refer to https://mongoc.org/libbson/current/api.html
class Writer {
class RFL_API Writer {
struct BSONType {
bson_t val_;
};
Expand Down
3 changes: 2 additions & 1 deletion include/rfl/capnproto/Reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
#include "../always_false.hpp"
#include "../internal/is_literal.hpp"
#include "../internal/ptr_cast.hpp"
#include "../common.hpp"

namespace rfl::capnproto {

class Reader {
class RFL_API Reader {
public:
struct CapNProtoInputArray {
capnp::DynamicList::Reader val_;
Expand Down
3 changes: 2 additions & 1 deletion include/rfl/capnproto/SchemaImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

//#include "../Box.hpp"
//#include "../Result.hpp"
#include "../common.hpp"

namespace rfl::capnproto {

class SchemaImpl {
class RFL_API SchemaImpl {
public:
SchemaImpl(const std::string& _str);

Expand Down
3 changes: 2 additions & 1 deletion include/rfl/capnproto/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
#include "../always_false.hpp"
#include "../internal/is_literal.hpp"
//#include "../internal/ptr_cast.hpp"
#include "../common.hpp"

namespace rfl::capnproto {

class Writer {
class RFL_API Writer {
public:
struct CapnProtoOutputArray {
capnp::DynamicList::Builder val_;
Expand Down
3 changes: 2 additions & 1 deletion include/rfl/capnproto/schema/Type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
#include "../../Ref.hpp"
//#include "../../Rename.hpp"
#include "../../Variant.hpp"
#include "../../common.hpp"

namespace rfl::capnproto::schema {

struct Type {
struct RFL_API Type {
struct Void {};

struct Bool {};
Expand Down
3 changes: 2 additions & 1 deletion include/rfl/capnproto/to_schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
#include "Writer.hpp"
#include "Reader.hpp"
//#include "schema/Type.hpp"
#include "../common.hpp"

namespace rfl::capnproto {

std::string to_string_representation(
RFL_API std::string to_string_representation(
const parsing::schema::Definition& internal_schema);

/// This ensures that the schema is only generated once.
Expand Down
3 changes: 2 additions & 1 deletion include/rfl/cbor/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
//#include "../Result.hpp"
#include "../Vectorstring.hpp"
#include "../always_false.hpp"
#include "../common.hpp"

namespace rfl::cbor {

class Writer {
class RFL_API Writer {
using Encoder = jsoncons::cbor::cbor_bytes_encoder;

public:
Expand Down
19 changes: 19 additions & 0 deletions include/rfl/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef RFL_COMMON_HPP_
#define RFL_COMMON_HPP_


#ifdef RFL_BUILD_SHARED
#ifdef _WIN32
#ifdef reflectcpp_EXPORTS
#define RFL_API __declspec(dllexport)
#else
#define RFL_API __declspec(dllimport)
#endif
#else
#define RFL_API __attribute__((visibility("default")))
#endif
#else
#define RFL_API
#endif

#endif

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's a common convention to end files with a newline character. Some tools might issue a warning if it's missing.

Suggested change
#endif
#endif

3 changes: 2 additions & 1 deletion include/rfl/flexbuf/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
//#include "../Result.hpp"
#include "../Vectorstring.hpp"
#include "../always_false.hpp"
#include "../common.hpp"

namespace rfl {
namespace flexbuf {

struct Writer {
struct RFL_API Writer {
struct OutputArray {
size_t start_;
};
Expand Down
3 changes: 2 additions & 1 deletion include/rfl/generic/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

#include "../Generic.hpp"
#include "../always_false.hpp"
#include "../common.hpp"

namespace rfl::generic {

struct Writer {
struct RFL_API Writer {
struct OutputArray {
Generic::Array* val_;
};
Expand Down
12 changes: 7 additions & 5 deletions include/rfl/internal/strings/strings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@
#include <string>
#include <vector>

#include "../../common.hpp"

namespace rfl::internal::strings {

/// Joins a series of strings.
std::string join(const std::string& _delimiter,
RFL_API std::string join(const std::string& _delimiter,
const std::vector<std::string>& _strings);

/// Replace all occurences of _from with _to.
std::string replace_all(const std::string& _str, const std::string& _from,
RFL_API std::string replace_all(const std::string& _str, const std::string& _from,
const std::string& _to);

/// Splits _str along _delimiter.
std::vector<std::string> split(const std::string& _str,
RFL_API std::vector<std::string> split(const std::string& _str,
const std::string& _delimiter);

/// Transforms the string to camel case.
std::string to_camel_case(const std::string& _str);
RFL_API std::string to_camel_case(const std::string& _str);

/// Transforms the string to pascal case.
std::string to_pascal_case(const std::string& _str);
RFL_API std::string to_pascal_case(const std::string& _str);

} // namespace rfl::internal::strings

Expand Down
3 changes: 2 additions & 1 deletion include/rfl/json/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@

//#include "../Result.hpp"
#include "../always_false.hpp"
#include "../common.hpp"

namespace rfl {
namespace json {

class Writer {
class RFL_API Writer {
public:
struct YYJSONOutputArray {
YYJSONOutputArray(yyjson_mut_val* _val) : val_(_val) {}
Expand Down
3 changes: 2 additions & 1 deletion include/rfl/json/to_schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "schema/JSONSchema.hpp"
// #include "schema/Type.hpp"
// #include "write.hpp"
#include "../common.hpp"

namespace rfl::json {

Expand All @@ -31,7 +32,7 @@ struct TypeHelper<rfl::Variant<Ts...>> {
using JSONSchemaType = rfl::Variant<schema::JSONSchema<Ts>...>;
};

std::string to_schema_internal_schema(
RFL_API std::string to_schema_internal_schema(
const parsing::schema::Definition& internal_schema, const yyjson_write_flag,
const bool _no_required, const std::string& comment = "");

Expand Down
3 changes: 2 additions & 1 deletion include/rfl/msgpack/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
//#include "../Result.hpp"
#include "../Vectorstring.hpp"
#include "../always_false.hpp"
#include "../common.hpp"

namespace rfl::msgpack {

class Writer {
class RFL_API Writer {
public:
struct MsgpackOutputArray {};

Expand Down
3 changes: 2 additions & 1 deletion include/rfl/parsing/schema/Type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
#include "../../Ref.hpp"
#include "../../Variant.hpp"
#include "ValidationType.hpp"
#include "../../common.hpp"

namespace rfl::parsing::schema {

struct Type {
struct RFL_API Type {
struct Boolean {};

struct Bytestring {};
Expand Down
Loading
Loading