Skip to content

Commit

Permalink
add msvc (#33)
Browse files Browse the repository at this point in the history
* add msvc

* fix

* typo

* exclude win + clang properly

* simplify cmake configuration

* fix

* disable ubuntu temporally

* add configure option

* fix

* another fix

* test if test is almost successful

* disable hash test

* make GitHub cache Boost build

* test

* install with config option

* copy dlls

* restore ubuntu CI

* Revert "disable hash test"

This reverts commit cb8b958.

* Revert "test if test is almost successful"

This reverts commit f334c6c.

* correct msvc version

* Revert "correct msvc version"

This reverts commit eae2cad.

* add MSVC options

* require TBB for Linux

* set global fixture

* avoid shadowing

* fix test
  • Loading branch information
yaito3014 authored Sep 26, 2024
1 parent ccf997a commit d0f0394
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 32 deletions.
70 changes: 48 additions & 22 deletions .github/workflows/run_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
os:
- name: ubuntu
version: 24.04
- name: windows
version: 2022
build_type: [Release, Debug]
cpp_version: [20, 23, 26]
boost_version: [1.86.0]
Expand All @@ -35,11 +37,26 @@ jobs:
version: 20
executable: clang++-20
cxxflags: -stdlib=libc++
- vendor: Microsoft
version: v142
executable: cl
exclude:
- compiler:
vendor: GNU
version: 13
cpp_version: 26
- os:
name: windows
compiler:
vendor: GNU
- os:
name: windows
compiler:
vendor: LLVM
- os:
name: ubuntu
compiler:
vendor: Microsoft

steps:
- uses: actions/checkout@v4
Expand All @@ -54,7 +71,7 @@ jobs:
- name: Setup GCC
if: matrix.compiler.vendor == 'GNU'
run: sudo apt update && sudo apt install -y g++-${{ matrix.compiler.version }}

- name: Install Dependencies
if: matrix.os.name == 'ubuntu'
run: sudo apt update && sudo apt install -y libtbb-dev
Expand Down Expand Up @@ -85,27 +102,23 @@ jobs:
- name: Build Boost
if: steps.cache-boost.outputs.cache-hit != 'true'
env:
cmake_options: >-
-DCMAKE_CXX_COMPILER=${{ matrix.compiler.executable }}
-DCMAKE_CXX_FLAGS=${{ matrix.compiler.cxxflags }}
-DCMAKE_CXX_STANDARD=${{ matrix.cpp_version }}
-DBUILD_SHARED_LIBS=ON
-DCMAKE_DEBUG_POSTFIX=d
working-directory: ${{ github.workspace }}/boost
run: |
cmake -Bbuild -S. \
-DCMAKE_CXX_COMPILER=${{ matrix.compiler.executable }} \
-DCMAKE_CXX_FLAGS=${{ matrix.compiler.cxxflags }} \
-DCMAKE_CXX_STANDARD=${{ matrix.cpp_version }} \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_DEBUG_POSTFIX=d \
-DCMAKE_BUILD_TYPE=Debug
cmake --build build -j
cmake --install build --prefix dist
cmake -Bbuild -S. \
-DCMAKE_CXX_COMPILER=${{ matrix.compiler.executable }} \
-DCMAKE_CXX_FLAGS=${{ matrix.compiler.cxxflags }} \
-DCMAKE_CXX_STANDARD=${{ matrix.cpp_version }} \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_BUILD_TYPE=Release
cmake --build build -j
cmake --install build --prefix dist
- name: Configure CMake
cmake -Bbuild -S. ${{ env.cmake_options }} -DCMAKE_BUILD_TYPE=Debug
cmake --build build -j --config Debug
cmake --install build --prefix dist --config Debug
cmake -Bbuild -S. ${{ env.cmake_options }} -DCMAKE_BUILD_TYPE=Release
cmake --build build -j --config Release
cmake --install build --prefix dist --config Release
- name: Configure
run: >
cmake -B ${{ github.workspace }}/build
-DCMAKE_CXX_COMPILER=${{ matrix.compiler.executable }}
Expand All @@ -114,9 +127,22 @@ jobs:
-DCMAKE_PREFIX_PATH=${{ github.workspace }}/boost/dist
-S ${{ github.workspace }}
- name: Build
- name: Build (Ubuntu)
if: matrix.os.name == 'ubuntu'
run: cmake --build ${{ github.workspace }}/build --verbose --config ${{ matrix.build_type }} --target yk_util_test

- name: Test
- name: Build (Windows)
if: matrix.os.name == 'windows'
run: cmake --build ${{ github.workspace }}/build/test --verbose --config ${{ matrix.build_type }} --target yk_util_test

- name: Test (Ubuntu)
if: matrix.os.name == 'ubuntu'
working-directory: ${{ github.workspace }}/build/test
run: ./yk_util_test --report_level=short

- name: Test (Windows)
if: matrix.os.name == 'windows'
working-directory: ${{ github.workspace }}/build/test/${{ matrix.build_type }}
run: |
copy ${{ github.workspace }}/boost/dist/bin/*.dll .
./yk_util_test --report_level=short
19 changes: 15 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@ if(BUILD_TESTING)
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra>
)
target_compile_definitions(
yk_util_test PRIVATE $<$<CXX_COMPILER_ID:Clang>:YK_BUILD_UNIT_TEST_FRAMEWORK=1>
yk_util_test
PRIVATE $<$<CXX_COMPILER_ID:Clang>:YK_BUILD_UNIT_TEST_FRAMEWORK=1>
PRIVATE $<$<CXX_COMPILER_ID:MSVC>:NOMINMAX>
PRIVATE $<$<CXX_COMPILER_ID:MSVC>:WIN32_LEAN_AND_MEAN>
PRIVATE $<$<CXX_COMPILER_ID:MSVC>:_UNICODE>
PRIVATE $<$<CXX_COMPILER_ID:MSVC>:UNICODE>
)
target_compile_options(
yk_util_test
PRIVATE ${YK_COMMON_FLAG}
PRIVATE $<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -pedantic-errors>
PRIVATE $<$<CXX_COMPILER_ID:Clang>:-Wall -Wextra -pedantic-errors>
PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/W4 /permissive- /Zc:__cplusplus /Zc:preprocessor /sdl /utf-8>
)
target_compile_options(yk_util_test PRIVATE ${YK_COMMON_FLAG})
target_link_options(yk_util_test PRIVATE ${YK_COMMON_FLAG})

find_package(TBB)
if(${TBB_FOUND})
if(NOT MSVC)
find_package(TBB REQUIRED)
target_link_libraries(yk_util_test PRIVATE TBB::tbb)
endif()

Expand Down
27 changes: 21 additions & 6 deletions test/test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "yk/allocator/default_init_allocator.hpp"
#include "yk/allocator/default_init_allocator.hpp"
#include "yk/bitmask_enum.hpp"
#include "yk/hash/adapt.hpp"
#include "yk/hash/hash_combine.hpp"
Expand Down Expand Up @@ -27,9 +27,14 @@
#include <boost/test/unit_test.hpp>
#endif

#include <boost/predef/os.h>
#include <boost/container_hash/hash.hpp>
#include <boost/range/iterator_range.hpp>

#if BOOST_OS_WINDOWS
#include "Windows.h"
#endif // BOOST_OS_WINDOWS

#include <algorithm>
#include <atomic>
#include <exception>
Expand All @@ -53,6 +58,16 @@

namespace utf = boost::unit_test;

struct GlobalFixture {
void setup() {
#if BOOST_OS_WINDOWS
SetConsoleOutputCP(65001);
#endif // BOOST_OS_WINDOWS
}
};

BOOST_TEST_GLOBAL_FIXTURE(GlobalFixture);

namespace hash_test {

template <class T, class... Ts>
Expand Down Expand Up @@ -454,12 +469,12 @@ BOOST_AUTO_TEST_CASE(Hash) {
BOOST_TEST(hash_value(s) == yk::hash_value_for(42)); // call hash_value by ADL

{
hash_test::MultiS s{31415, 9265, 3589};
hash_test::MultiS ms{31415, 9265, 3589};
std::size_t seed = 0;
boost::hash_combine(seed, s.a);
boost::hash_combine(seed, s.b);
boost::hash_combine(seed, s.c);
BOOST_TEST(hash_value(s) == seed);
boost::hash_combine(seed, boost::hash<int>{}(ms.a));
boost::hash_combine(seed, boost::hash<int>{}(ms.b));
boost::hash_combine(seed, boost::hash<int>{}(ms.c));
BOOST_TEST(hash_value(ms) == seed);
}
}

Expand Down

0 comments on commit d0f0394

Please sign in to comment.