Skip to content

Commit

Permalink
Made sure that Github Actions also work for MSVC (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzicheng1987 committed Apr 21, 2024
1 parent 8a858d2 commit bf1c9be
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 33 deletions.
40 changes: 22 additions & 18 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,25 @@ jobs:
./build/tests/xml/reflect-cpp-xml-tests
./build/tests/yaml/reflect-cpp-yaml-tests
# The latest MSVC version on GitHub Actions has a bug, and it's difficult to switch to another version.
# Re-enable this when the bug is fixed.

# windows-msvc:
# runs-on: windows-latest
# steps:
# - uses: actions/checkout@v3
# with:
# submodules: true
# - uses: ilammy/msvc-dev-cmd@v1
# - uses: lukka/run-vcpkg@v11
# - name: Run test
# run: |
# cmake -S . -B build -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_FLEXBUFFERS=ON
# cmake --build build -j 4
# .\build\tests\flexbuffers\Release\reflect-cpp-flexbuffers-tests.exe
# .\build\tests\json\Release\reflect-cpp-json-tests.exe
windows-msvc:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- uses: ilammy/msvc-dev-cmd@v1
- uses: lukka/run-vcpkg@v11
- name: Run test
run: |
cmake -S . -B build -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_BSON=ON -DREFLECTCPP_CBOR=ON -DREFLECTCPP_FLEXBUFFERS=ON -DREFLECTCPP_MSGPACK=ON -DREFLECTCPP_XML=ON -DREFLECTCPP_TOML=ON -DREFLECTCPP_YAML=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release -j4
.\build\tests\json\Release\reflect-cpp-json-tests.exe
.\build\tests\bson\Release\reflect-cpp-bson-tests.exe
.\build\tests\cbor\Release\reflect-cpp-cbor-tests.exe
.\build\tests\flexbuffers\Release\reflect-cpp-flexbuffers-tests.exe
.\build\tests\msgpack\Release\reflect-cpp-msgpack-tests.exe
.\build\tests\toml\Release\reflect-cpp-toml-tests.exe
.\build\tests\xml\Release\reflect-cpp-xml-tests.exe
.\build\tests\yaml\Release\reflect-cpp-yaml-tests.exe
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ if (REFLECTCPP_FLEXBUFFERS)
endif ()

if (REFLECTCPP_MSGPACK)
message(${VCPKG_INSTALLED_DIR})
find_package(msgpack-c CONFIG REQUIRED)
if (MSVC)
target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/msgpack-c${CMAKE_STATIC_LIBRARY_SUFFIX}")
Expand All @@ -66,9 +65,11 @@ if (REFLECTCPP_MSGPACK)
endif ()

if (REFLECTCPP_TOML)
find_package(PkgConfig REQUIRED)
pkg_check_modules(tomlplusplus REQUIRED IMPORTED_TARGET tomlplusplus)
target_link_libraries(reflectcpp INTERFACE PkgConfig::tomlplusplus)
if (MSVC)
target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/tomlplusplus${CMAKE_STATIC_LIBRARY_SUFFIX}")
else ()
target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libtomlplusplus${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif ()
endif()

if (REFLECTCPP_XML)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,9 @@ To run the tests, do the following:
./build/tests/flexbuffers/reflect-cpp-flexbuffers-tests
./build/tests/msgpack/reflect-cpp-msgpack-tests
./build/tests/json/reflect-cpp-json-tests
./build/tests/xml/reflect-cpp-toml-tests
./build/tests/toml/reflect-cpp-toml-tests
./build/tests/xml/reflect-cpp-xml-tests
./build/tests/xml/reflect-cpp-yaml-tests
./build/tests/yaml/reflect-cpp-yaml-tests
```

## How to contribute
Expand Down
4 changes: 2 additions & 2 deletions include/rfl/internal/get_field_names.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ consteval auto get_field_name_str_view() {
#endif
#if defined(__clang__)
const auto split = func_name.substr(0, func_name.size() - 2);
return split.substr(split.find_last_of(":.") + 1);
return split.substr(split.find_last_of(":.") + 1);
#elif defined(__GNUC__)
const auto split = func_name.substr(0, func_name.size() - 2);
return split.substr(split.find_last_of(":") + 1);
#elif defined(_MSC_VER)
const auto split = func_name.substr(0, func_name.size() - 7);
return split.substr(split.find("value->") + 7);
return split.substr(split.rfind("->") + 2);
#else
static_assert(false,
"You are using an unsupported compiler. Please use GCC, Clang "
Expand Down
14 changes: 7 additions & 7 deletions tests/json/test_inheritance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <iostream>
#include <rfl.hpp>
#include <source_location>
#include <tuple>

namespace test_inheritance {

Expand All @@ -14,13 +15,12 @@ void test() {

struct T : S {};

const auto name = get<0>(rfl::fields<T>()).name();
if (name == "x") {
std::cout << "OK" << std::endl << std::endl;
} else {
std::cout << "FAIL\n"
<< "Expected member name 'x', got '" << name << "'" << std::endl;
}
constexpr auto name =
std::tuple_element_t<0, typename rfl::named_tuple_t<T>::Fields>::name();

static_assert(name == "x");

std::cout << "OK" << std::endl << std::endl;
}

} // namespace test_inheritance
1 change: 1 addition & 0 deletions tests/toml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ file(GLOB_RECURSE SOURCES "*.cpp")

add_executable(reflect-cpp-toml-tests ${SOURCES})

target_include_directories(reflect-cpp-toml-tests SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include")
target_link_libraries(reflect-cpp-toml-tests PRIVATE reflectcpp)

0 comments on commit bf1c9be

Please sign in to comment.