Skip to content

Commit e9b3ad7

Browse files
authored
Add GitHub Action for verification
* fix benchmark generation code for gcc * add CI Github action * fix failing clang tests build
1 parent 7a3e0ff commit e9b3ad7

File tree

3 files changed

+87
-13
lines changed

3 files changed

+87
-13
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: CMake on multiple platforms
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ${{ matrix.os }}
12+
13+
strategy:
14+
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
15+
fail-fast: false
16+
17+
# Set up a matrix to run the following 3 configurations:
18+
matrix:
19+
os: [ubuntu-latest, windows-latest]
20+
build_type: [Release]
21+
c_compiler: [gcc, clang, cl]
22+
include:
23+
- os: windows-latest
24+
c_compiler: cl
25+
cpp_compiler: cl
26+
- os: ubuntu-latest
27+
c_compiler: gcc
28+
cpp_compiler: g++
29+
- os: ubuntu-latest
30+
c_compiler: clang
31+
cpp_compiler: clang++
32+
exclude:
33+
- os: windows-latest
34+
c_compiler: gcc
35+
- os: windows-latest
36+
c_compiler: clang
37+
- os: ubuntu-latest
38+
c_compiler: cl
39+
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- name: Set reusable strings
44+
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
45+
id: strings
46+
shell: bash
47+
run: |
48+
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
49+
50+
- name: Configure CMake
51+
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
52+
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
53+
# Building with `SORTING_NETWORK_CPP_BUILD_BENCHMARK=ON` to ensure that the benchmarks can be built
54+
run: >
55+
cmake -B ${{ steps.strings.outputs.build-output-dir }}
56+
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
57+
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
58+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
59+
-DSORTING_NETWORK_CPP_BUILD_TESTS=ON
60+
-DSORTING_NETWORK_CPP_BUILD_BENCHMARK=ON
61+
-S ${{ github.workspace }}
62+
63+
- name: Build
64+
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --parallel
65+
66+
- name: Test
67+
working-directory: ${{ steps.strings.outputs.build-output-dir }}
68+
run: ctest --build-config ${{ matrix.build_type }}

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ if(SORTING_NETWORK_CPP_BUILD_TESTS)
4848
CPMAddPackage("gh:brunocodutra/metal#v2.1.4")
4949
CPMAddPackage("gh:google/googletest#release-1.12.0")
5050

51+
include(GoogleTest)
52+
53+
enable_testing()
54+
5155
set(SN_TESTS_EXECUTABLE_NAME ${PROJECT_NAME}_tests)
5256

5357
add_executable(${SN_TESTS_EXECUTABLE_NAME}
@@ -60,4 +64,5 @@ if(SORTING_NETWORK_CPP_BUILD_TESTS)
6064
"test/test_size_optimized_sort.cpp"
6165
)
6266
target_link_libraries(${SN_TESTS_EXECUTABLE_NAME} GTest::gtest GTest::gmock GTest::gtest_main Metal project_options sorting_network_cpp)
67+
gtest_discover_tests(${SN_TESTS_EXECUTABLE_NAME})
6368
endif()

src/util.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
#include <algorithm>
1718
#include <array>
1819
#include <chrono>
1920
#include <cstddef>
@@ -101,9 +102,9 @@ namespace quxflux
101102
}
102103

103104
template<typename T>
104-
constexpr std::string_view to_string()
105+
std::string_view to_string()
105106
{
106-
static std::unordered_map<std::type_index, std::string_view> name_map{
107+
const std::unordered_map<std::type_index, std::string_view> name_map{
107108
std::pair{std::type_index(typeid(int16_t)), "int16_t"}, //
108109
std::pair{std::type_index(typeid(int32_t)), "int32_t"}, //
109110
std::pair{std::type_index(typeid(int64_t)), "int64_t"}, //
@@ -121,11 +122,11 @@ namespace quxflux
121122
}
122123

123124
template<quxflux::sorting_net::type NWT>
124-
constexpr std::string_view to_string()
125+
std::string_view to_string()
125126
{
126127
using SN = quxflux::sorting_net::type;
127128

128-
static std::unordered_map<quxflux::sorting_net::type, std::string_view> name_map{
129+
const std::unordered_map<quxflux::sorting_net::type, std::string_view> name_map{
129130
std::pair{SN::bubble_sort, "SN::bubble_sort"}, //
130131
std::pair{SN::insertion_sort, "SN::insertion_sort"}, //
131132
std::pair{SN::batcher_odd_even_merge_sort, "SN::batcher_odd_even_merge_sort"}, //
@@ -237,16 +238,16 @@ namespace quxflux
237238

238239
#define IMPL_BENCHMARK(T) \
239240
template<> \
240-
void detail::benchmark_impl<##T>::operator()(std::set<benchmark_result>& benchmark_results) const \
241+
void detail::benchmark_impl<T>::operator()(std::set<benchmark_result>& benchmark_results) const \
241242
{ \
242-
benchmark_all_with_size_and_type<1, ##T>(benchmark_results); \
243-
benchmark_all_with_size_and_type<2, ##T>(benchmark_results); \
244-
benchmark_all_with_size_and_type<4, ##T>(benchmark_results); \
245-
benchmark_all_with_size_and_type<8, ##T>(benchmark_results); \
246-
benchmark_all_with_size_and_type<16, ##T>(benchmark_results); \
247-
benchmark_all_with_size_and_type<32, ##T>(benchmark_results); \
248-
benchmark_all_with_size_and_type<64, ##T>(benchmark_results); \
249-
benchmark_all_with_size_and_type<128, ##T>(benchmark_results); \
243+
benchmark_all_with_size_and_type<1, T>(benchmark_results); \
244+
benchmark_all_with_size_and_type<2, T>(benchmark_results); \
245+
benchmark_all_with_size_and_type<4, T>(benchmark_results); \
246+
benchmark_all_with_size_and_type<8, T>(benchmark_results); \
247+
benchmark_all_with_size_and_type<16, T>(benchmark_results); \
248+
benchmark_all_with_size_and_type<32, T>(benchmark_results); \
249+
benchmark_all_with_size_and_type<64, T>(benchmark_results); \
250+
benchmark_all_with_size_and_type<128, T>(benchmark_results); \
250251
\
251252
std::clog << '\n'; \
252253
} \

0 commit comments

Comments
 (0)