Skip to content

Commit

Permalink
Merge pull request #75 from OleksandrKvl/OleksandrKvl/add-build-ci-wo…
Browse files Browse the repository at this point in the history
…rkflow
  • Loading branch information
OleksandrKvl authored Oct 25, 2024
2 parents 1fa84fd + 6c862cb commit 3954688
Show file tree
Hide file tree
Showing 21 changed files with 178 additions and 45 deletions.
11 changes: 11 additions & 0 deletions .github/conan_config/profiles/default
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% set compiler, compiler_version = os.getenv("CC").split('-') %}

[settings]
arch=x86_64
build_type=Debug
compiler={{ compiler }}
compiler.libcxx={{ os.getenv("LIBCXX") }}
compiler.version={{ compiler_version }}
os=Linux

tools.build:compiler_executables={'c': '{{ os.getenv("CC") }}', 'cpp': '{{ os.getenv("CXX") }}'}
83 changes: 83 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Build and test

on:
pull_request:
branches:
- main

jobs:
build-linux:
runs-on: ubuntu-24.04

strategy:
matrix:
compiler: [gcc-9, gcc-14, clang-9, clang-19]
include:
- compiler: gcc-9
cxx: g++-9
libcxx: libstdc++11
install: |
sudo apt install -y gcc-9 g++-9
- compiler: gcc-14
cxx: g++-14
libcxx: libstdc++11
- compiler: clang-9
cxx: clang++-9
libcxx: libc++
install: |
sudo apt-add-repository 'deb http://archive.ubuntu.com/ubuntu focal main universe'
sudo apt install -y clang-9 libc++-9-dev libc++abi-9-dev
- compiler: clang-19
cxx: clang++-19
libcxx: libc++
install: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-add-repository 'deb http://apt.llvm.org/noble/ llvm-toolchain-noble-19 main'
sudo apt install -y clang-19 libc++-19-dev libc++abi-19-dev
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt update
${{ matrix.install }}
- name: Build
env:
CC: ${{ matrix.compiler }}
CXX: ${{ matrix.cxx }}
LIBCXX: ${{ matrix.libcxx }}
run: |
python -m venv venv
source ./venv/bin/activate
pip install conan
source ~/.profile
conan config install --type dir ./.github/conan_config
conan install . -of=build --build=missing
cmake -B build -DSBEPP_BUILD_TESTS=ON -DSBEPP_SEPARATE_TESTS=OFF --preset conan-debug
cmake --build build --preset conan-debug --parallel $(nproc)
- name: Run tests
run: ctest --test-dir build --output-on-failure --parallel --build-config Debug

build-windows:
runs-on: windows-2022

steps:
- uses: actions/checkout@v4

- name: Build
run: |
python -m venv venv
.\venv\Scripts\activate
pip install conan
conan profile detect
conan profile show
conan install . -of=build --build=missing -s build_type=Debug
cmake -B build -DSBEPP_BUILD_TESTS=ON -DSBEPP_SEPARATE_TESTS=OFF --preset conan-default
$threads = (Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors
cmake --build build --preset conan-debug --parallel $threads
- name: Run tests
run: ctest --test-dir build --output-on-failure --parallel --build-config Debug
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# 1.4.2

- add build and test GitHub action
- fix wrong usage of `template` keyword when calling dependent template function
without template arguments (e.g. `obj.template f()`) in Visit API
- generate explicitly defaulted constructor for empty group entry classes
- make `SBEPP_BUILD_TESTS` CMake option independent of `SBEPP_DEV_MODE`
- add `SBEPP_SEPARATE_TESTS` CMake option
- fix minor errors in tests detected by CI

---

# 1.4.1

- fixed `sbepp::size_bytes_checked` example
Expand Down
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.11)

project(sbepp
VERSION 1.4.1
VERSION 1.4.2
LANGUAGES CXX
)

Expand All @@ -21,7 +21,14 @@ option(SBEPP_DEV_MODE "Developer mode" OFF)

cmake_dependent_option(SBEPP_BUILD_TESTS
"Build sbepp tests" OFF
"SBEPP_DEV_MODE;BUILD_TESTING;CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR"
"BUILD_TESTING;CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR"
OFF
)

# used primarily to speed up CI by running all unit tests as a single binary
cmake_dependent_option(SBEPP_SEPARATE_TESTS
"Treat each unit test separately in CTest" ON
"SBEPP_BUILD_TESTS"
OFF
)

Expand Down
5 changes: 3 additions & 2 deletions doc/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ Available CMake options (`name = default_value`):
- `SBEPP_BUILD_BENCHMARK = OFF`, requires `SBEPP_DEV_MODE=ON`, controls whether
benchmarks should be built. If
`ON`, requires [benchmark](https://github.com/google/benchmark)
- `SBEPP_BUILD_TESTS = OFF`, requires `SBEPP_DEV_MODE=ON`, controls whether
tests should be built. If `ON`,
- `SBEPP_BUILD_TESTS = OFF`, controls whether tests should be built. If `ON`,
requires [googletest](https://github.com/google/googletest) and
[fmt](https://github.com/fmtlib/fmt)
- `SBEPP_SEPARATE_TESTS = ON`, requires `SBEPP_BUILD_TESTS=ON`, controls whether
each unit test is treated separately in CTest
- `SBEPP_BUILD_DOCS = OFF`, controls whether documentation should be built. If
`ON` requires [Doxygen](https://doxygen.nl/)

Expand Down
4 changes: 2 additions & 2 deletions sbepp/src/sbepp/sbepp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2498,7 +2498,7 @@ class flat_group_base : public byte_range<Byte>
{
for(const auto entry : this->cursor_range(c))
{
if(v.template on_entry(entry, c))
if(v.on_entry(entry, c))
{
return true;
}
Expand Down Expand Up @@ -2720,7 +2720,7 @@ class nested_group_base : public byte_range<Byte>
{
for(const auto entry : this->cursor_range(c))
{
if(v.template on_entry(entry, c))
if(v.on_entry(entry, c))
{
return true;
}
Expand Down
17 changes: 10 additions & 7 deletions sbeppc/src/sbepp/sbeppc/messages_compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,16 @@ R"(
{
// for empty group entries we generate a special cursor constructor to
// advance cursor to `block_length` because there are no other fields
// to do this
// to do this. Default constructor is declared explicitly because old
// compilers don't support inheriting it from the base class.
if(members.fields.empty() && members.groups.empty()
&& members.data.empty())
{
return fmt::format(
// clang-format off
R"(
{class_name}() = default;
template<typename Byte2,
typename = ::sbepp::detail::enable_if_convertible_t<Byte2, Byte>>
SBEPP_CPP14_CONSTEXPR {class_name}(
Expand Down Expand Up @@ -445,7 +448,7 @@ class {name} : public {base_class}
constexpr bool operator()(
::sbepp::detail::visit_tag, Visitor& v, Cursor& c) const
{{
return v.template on_entry(*this, c);
return v.on_entry(*this, c);
}}
{visit_children_impl}
Expand Down Expand Up @@ -611,7 +614,7 @@ class {name} : public ::sbepp::detail::{base_class}<
constexpr bool operator()(
::sbepp::detail::visit_tag, Visitor& v, Cursor& c) const
{{
return v.template on_group(*this, c, "{public_name}");
return v.on_group(*this, c, "{public_name}");
}}
}};
)",
Expand Down Expand Up @@ -1700,23 +1703,23 @@ R"(
}

res.push_back(fmt::format(
"v.template on_field(this->{name}(c), {tag}{{}})",
"v.on_field(this->{name}(c), {tag}{{}})",
fmt::arg("name", f.name),
fmt::arg("tag", f.tag)));
}

for(const auto& g : members.groups)
{
res.push_back(fmt::format(
"v.template on_group(this->{name}(c), c, {tag}{{}})",
"v.on_group(this->{name}(c), c, {tag}{{}})",
fmt::arg("name", g.name),
fmt::arg("tag", g.tag)));
}

for(const auto& d : members.data)
{
res.push_back(fmt::format(
"v.template on_data(this->{name}(c), {tag}{{}})",
"v.on_data(this->{name}(c), {tag}{{}})",
fmt::arg("name", d.name),
fmt::arg("tag", d.tag)));
}
Expand Down Expand Up @@ -1796,7 +1799,7 @@ class {name} : public ::sbepp::detail::message_base<
SBEPP_CPP14_CONSTEXPR void operator()(
::sbepp::detail::visit_tag, Visitor& v, Cursor& c)
{{
v.template on_message(*this, c, {tag}{{}});
v.on_message(*this, c, {tag}{{}});
}}
{visit_children_impl}
Expand Down
4 changes: 2 additions & 2 deletions sbeppc/src/sbepp/sbeppc/types_compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ class {name} : public ::sbepp::detail::bitset_base<{type}>
if(!std::get<0>(visit_info).empty())
{
res.push_back(fmt::format(
"v.template {visitor}(this->{name}(), {tag}{{}})",
"v.{visitor}(this->{name}(), {tag}{{}})",
fmt::arg("visitor", std::get<0>(visit_info)),
fmt::arg("name", std::get<1>(visit_info)),
fmt::arg("tag", std::get<2>(visit_info))));
Expand Down Expand Up @@ -775,7 +775,7 @@ class {name} : public ::sbepp::detail::composite_base<Byte>
constexpr bool operator()(
::sbepp::detail::visit_tag, Visitor& v, Cursor&) const
{{
return v.template on_composite(*this, {tag}{{}});
return v.on_composite(*this, {tag}{{}});
}}
{visit_children_impl}
Expand Down
6 changes: 5 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ function(add_test_binary name_suffix cpp_version)

sbepp_set_strict_compiler_options(${test_name})

gtest_discover_tests(${test_name} TEST_PREFIX "${test_name}.")
if(SBEPP_SEPARATE_TESTS)
gtest_discover_tests(${test_name} TEST_PREFIX "${test_name}.")
else()
add_test(NAME "${test_name}" COMMAND "${test_name}")
endif()
endfunction()

foreach(version IN LISTS cpp_versions)
Expand Down
2 changes: 2 additions & 0 deletions test/src/sbepp/test/assert_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <sbepp/sbepp.hpp>

#include <exception>

namespace sbepp
{
void assertion_failed(
Expand Down
6 changes: 3 additions & 3 deletions test/src/sbepp/test/composite.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ TEST_F(CompositeTest, DefaultConstructedToNullptr)

TEST_F(CompositeTest, CanBeConstructedFromBeginEndPointers)
{
composite_t c{std::begin(buf), std::end(buf)};
composite_t c{buf.data(), buf.data() + buf.size()};

ASSERT_EQ(sbepp::addressof(c), buf.data());
STATIC_ASSERT_V(std::is_nothrow_constructible<
composite_t,
decltype(std::begin(buf)),
decltype(std::end(buf))>);
decltype(buf.data()),
decltype(buf.data())>);
}

TEST_F(CompositeTest, CanBeConstructedFromPointerAndSize)
Expand Down
8 changes: 5 additions & 3 deletions test/src/sbepp/test/dynamic_array_ref.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ TEST_F(DynamicArrayRefTest, DefaultConstructedToNullptr)

TEST_F(DynamicArrayRefTest, CanBeConstructedFromBeginEndPointers)
{
array_t a{buf.data(), buf.data() + buf.size()};

ASSERT_EQ(sbepp::addressof(a), buf.data());
STATIC_ASSERT_V(std::is_nothrow_constructible<
array_t,
decltype(std::begin(buf)),
decltype(std::end(buf))>);
decltype(buf.data()),
decltype(buf.data())>);
}

TEST_F(DynamicArrayRefTest, CanBeConstructedFromPointerAndSize)
Expand Down Expand Up @@ -1006,7 +1008,7 @@ TEST_F(DynamicArrayRefTest, Assign2NotAvailableForConstByteTypes)

TEST_F(DynamicArrayRefDeathTest, Assign2TerminatesIfNotEnoughMemory)
{
ASSERT_DEATH({ a.assign(std::begin(buf), std::end(buf)); }, ".*");
ASSERT_DEATH({ a.assign(buf.data(), buf.data() + buf.size()); }, ".*");
}

TEST_F(DynamicArrayRefDeathTest, Assign2TerminatesIfHoldsNullptr)
Expand Down
8 changes: 4 additions & 4 deletions test/src/sbepp/test/entry.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ TEST_F(EntryTest, DefaultConstructedToNullptr)

TEST_F(EntryTest, CanBeConstructedFromBeginEndPointersAndBlockLength)
{
entry_t e{std::begin(buf), std::end(buf), g_block_length};
entry_t e{buf.data(), buf.data() + buf.size(), g_block_length};

ASSERT_EQ(sbepp::addressof(e), buf.data());
ASSERT_EQ(e(sbepp::detail::get_block_length_tag{}), g_block_length);
STATIC_ASSERT_V(std::is_nothrow_constructible<
entry_t,
decltype(std::begin(buf)),
decltype(std::end(buf)),
decltype(buf.data()),
decltype(buf.data()),
decltype(g_block_length)>);
}

Expand Down Expand Up @@ -130,7 +130,7 @@ constexpr auto constexpr_test()
{
std::array<byte_type, 100> buf{};
entry_t e1;
e1 = entry_t{std::begin(buf), std::end(buf), 0};
e1 = entry_t{buf.data(), buf.data() + buf.size(), 0};
e1 = entry_t{buf.data(), buf.size(), 0};
auto e2 = e1;
entry_t e3{std::move(e2)};
Expand Down
6 changes: 4 additions & 2 deletions test/src/sbepp/test/flat_group.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ TEST_F(FlatGroupTest, DefaultConstructedToNullptr)

TEST_F(FlatGroupTest, CanBeConstructedFromBeginEndPointers)
{
group_t g{buf.data(), buf.data() + buf.size()};

ASSERT_EQ(sbepp::addressof(g), buf.data());
STATIC_ASSERT_V(std::is_nothrow_constructible<
group_t,
decltype(std::begin(buf)),
decltype(std::end(buf))>);
decltype(buf.data()),
decltype(buf.data())>);
}

TEST_F(FlatGroupTest, CanBeConstructedFromPointerAndSize)
Expand Down
2 changes: 1 addition & 1 deletion test/src/sbepp/test/forward_iterator.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ STATIC_ASSERT_V(std::is_trivially_move_constructible<iterator_t>);
STATIC_ASSERT_V(std::is_trivially_move_assignable<iterator_t>);
STATIC_ASSERT_V(std::is_trivially_destructible<iterator_t>);

#if __cpp_concepts >= 201907L
#if __cpp_lib_concepts >= 202002L
STATIC_ASSERT(std::forward_iterator<iterator_t>);
#endif

Expand Down
2 changes: 1 addition & 1 deletion test/src/sbepp/test/input_iterator.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ STATIC_ASSERT_V(std::is_trivially_move_constructible<iterator_t>);
STATIC_ASSERT_V(std::is_trivially_move_assignable<iterator_t>);
STATIC_ASSERT_V(std::is_trivially_destructible<iterator_t>);

#if __cpp_concepts >= 201907L
#if __cpp_lib_concepts >= 202002L
STATIC_ASSERT(std::input_iterator<iterator_t>);
#endif

Expand Down
Loading

0 comments on commit 3954688

Please sign in to comment.