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
29 changes: 23 additions & 6 deletions .github/workflows/cpp_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,39 @@ jobs:

- uses: actions/checkout@v4

- name: Configure CMake
- name: Configure CMake for CPP23
env:
CC: gcc-14
CXX: g++-14
CXX: g++-14
working-directory: ${{github.workspace}}/
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -S ${{github.workspace}}/cpp -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
run: cmake -B ${{github.workspace}}/build23 -S ${{github.workspace}}/cpp -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCPP_VERSION=23

- name: Build
- name: Build CPP23
working-directory: ${{github.workspace}}/
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
run: cmake --build ${{github.workspace}}/build23 --config ${{env.BUILD_TYPE}}

- name: Run CTest
working-directory: ${{github.workspace}}/build/
working-directory: ${{github.workspace}}/build23/
run: ctest --rerun-failed --output-on-failure

- name: Configure CMake for CPP17
env:
CC: gcc-14
CXX: g++-14
working-directory: ${{github.workspace}}/
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build17 -S ${{github.workspace}}/cpp -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCPP_VERSION=17

- name: Build CPP17
working-directory: ${{github.workspace}}/
run: cmake --build ${{github.workspace}}/build17 --config ${{env.BUILD_TYPE}}

- name: Run CTest
working-directory: ${{github.workspace}}/build17/
run: ctest --rerun-failed --output-on-failure

convert_to_draft:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
build17
build23
dist
bin
53 changes: 48 additions & 5 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"tasks": [
{
"label": "CMakePrepare",
"label": "CMakePrepare CPP23",
"type": "shell",
"command": "cmake",
"args": [
"-B",
"${workspaceFolder}/build",
"${workspaceFolder}/build23",
"-S",
"${workspaceFolder}/cpp",
"-DCMAKE_BUILD_TYPE=Debug"
"-DCMAKE_BUILD_TYPE=Debug",
"-DCPP_VERSION=23"
],
"group": {
"kind": "build",
Expand All @@ -19,12 +20,54 @@
"detail": "Generated task by Debugger."
},
{
"label": "CMakeBuild",
"label": "CMakeBuild CPP23",
"type": "shell",
"command": "cmake",
"args": [
"--build",
"${workspaceFolder}/build"
"${workspaceFolder}/build23"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": ["$gcc"],
"detail": "Generated task by Debugger.",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": true
}
},
{
"label": "CMakePrepare CPP17",
"type": "shell",
"command": "cmake",
"args": [
"-B",
"${workspaceFolder}/build17",
"-S",
"${workspaceFolder}/cpp",
"-DCMAKE_BUILD_TYPE=Debug",
"-DCPP_VERSION=17"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": ["$gcc"],
"detail": "Generated task by Debugger."
},
{
"label": "CMakeBuild CPP17",
"type": "shell",
"command": "cmake",
"args": [
"--build",
"${workspaceFolder}/build17"
],
"group": {
"kind": "build",
Expand Down
7 changes: 6 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ include(CTest)

# option(BUILD_MODULE_L5 "Build the L5 module" ON)

set(CMAKE_CXX_STANDARD 23)
set(CPP_VERSION "23" CACHE STRING "C++ standard version to use (17 or 23)")
set_property(CACHE CPP_VERSION PROPERTY STRINGS "17" "23")
if(NOT CPP_VERSION STREQUAL "17" AND NOT CPP_VERSION STREQUAL "23")
message(FATAL_ERROR "CPP_VERSION must be 17 or 23 (got '${CPP_VERSION}')")
endif()
set(CMAKE_CXX_STANDARD ${CPP_VERSION})
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED True)
Expand Down
41 changes: 28 additions & 13 deletions cpp/modules/l4/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.22)

add_library(module_l4 STATIC)
add_executable(module_l4_tests
test/test_dummy.cpp)

target_sources(module_l4
PRIVATE
src/Channel.cpp
src/impl/ChannelUnixTcp.cpp
src/ChannelRx.cpp
src/ChannelTx.cpp
src/impl/ClientsRepoImpl.cpp
src/impl/ChannelUnixPipeImpl.cpp
src/impl/ChannelUnixFile.cpp
)

Expand All @@ -16,31 +17,45 @@ target_include_directories(module_l4 PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

add_executable(module_l4_tests
test/test_ChannelUnixTcp.cpp
test/test_ChannelUnixPipeImpl.cpp
)

if (USE_STD_MEMORY)
target_compile_definitions(module_l4 PRIVATE USE_STD_MEMORY)
target_compile_definitions(module_l4_tests PRIVATE USE_STD_MEMORY)
endif()

if(CMAKE_CXX_STANDARD GREATER_EQUAL 23)
target_sources(module_l4 PRIVATE src/cxx_23/ChannelTx.cpp)
message("Build for C++23")
target_sources(module_l4 PRIVATE
src/impl/ChannelUnixTcp.cpp
src/impl/ChannelUnixUdp.cpp
src/impl/ChannelUnixPipeImpl.cpp
src/impl/ChannelUnixSocket.cpp
)


target_sources(module_l4_tests PRIVATE
test/test_ChannelUnixTcp.cpp

Copilot AI Feb 23, 2026

Copy link

Choose a reason for hiding this comment

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

The new UDP implementation (ChannelUnixUdp.cpp) is built for C++23 but there are no corresponding tests for it. The test suite includes test_ChannelUnixTcp.cpp and test_ChannelUnixPipeImpl.cpp but no test_ChannelUnixUdp.cpp. This new implementation should have test coverage similar to the other channel implementations.

Suggested change
test/test_ChannelUnixTcp.cpp
test/test_ChannelUnixTcp.cpp
test/test_ChannelUnixUdp.cpp

Copilot uses AI. Check for mistakes.
test/test_ChannelUnixPipeImpl.cpp
)

# This helps CMake provide better error messages if the compiler doesn't fully
# support the C++23 standard.
target_compile_features(module_l4_tests PRIVATE cxx_std_23)

elseif(CMAKE_CXX_STANDARD GREATER_EQUAL 17)
target_sources(module_l4 PRIVATE src/cxx_17/ChannelTx.cpp)

message("Build for C++17")
# target_sources(module_l4 PRIVATE src/cxx_17/ChannelTx.cpp)

Comment on lines +48 to +49

Copilot AI Feb 23, 2026

Copy link

Choose a reason for hiding this comment

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

The C++17 build path is incomplete and commented out. When CMAKE_CXX_STANDARD is 17, only the base sources (ChannelRx.cpp, ChannelTx.cpp, ClientsRepoImpl.cpp, ChannelUnixFile.cpp) are built, but the socket implementations (ChannelUnixSocket.cpp, ChannelUnixTcp.cpp, ChannelUnixUdp.cpp, ChannelUnixPipeImpl.cpp) are only built for C++23. This means the library will be incomplete when built with C++17. Either complete the C++17 support or document that C++23 is required for full functionality.

Suggested change
# target_sources(module_l4 PRIVATE src/cxx_17/ChannelTx.cpp)
target_sources(module_l4 PRIVATE
src/impl/ChannelUnixTcp.cpp
src/impl/ChannelUnixUdp.cpp
src/impl/ChannelUnixPipeImpl.cpp
src/impl/ChannelUnixSocket.cpp
)
target_sources(module_l4_tests PRIVATE
test/test_ChannelUnixTcp.cpp
test/test_ChannelUnixPipeImpl.cpp
)
# This helps CMake provide better error messages if the compiler doesn't fully
# support the C++17 standard.
target_compile_features(module_l4_tests PRIVATE cxx_std_17)

Copilot uses AI. Check for mistakes.
else()

message(FATAL_ERROR "module_l4 requires C++17 or higher. Please set CMAKE_CXX_STANDARD to 17 or above.")

endif()

target_include_directories(module_l4_tests PRIVATE ./include/)
target_link_libraries(module_l4_tests PUBLIC Catch2::Catch2WithMain module_l4)

# This helps CMake provide better error messages if the compiler doesn't fully
# support the C++23 standard.
target_compile_features(module_l4_tests PRIVATE cxx_std_23)

catch_discover_tests(module_l4_tests
PROPERTIES
TIMEOUT 10)
18 changes: 0 additions & 18 deletions cpp/modules/l4/include/Channel.h

This file was deleted.

31 changes: 31 additions & 0 deletions cpp/modules/l4/include/ChannelRx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "data.h"
#include "SerializerL4.h"

namespace styxlib
{
class ChannelRx
{
protected:
DeserializerL4Ptr deserializer;

public:
ChannelRx();
ErrorCode setDeserializer(DeserializerL4Ptr deserializer);
virtual ~ChannelRx() = default;
};

/**
* Reads the first X bytes of buffer and interprets them as a packet size.
* @param headerSize The size of the packet header (1, 2, or 4 bytes).
* @param buffer The buffer to read from.
* @param bufferSize The number of valid bytes available in the buffer.
* @return The decoded packet payload size, or an ErrorCode if the buffer
* is too small to hold the header.
*/
SizeResult getPacketSize(
const PacketHeaderSize &headerSize,
const uint8_t *buffer,
Size bufferSize);
}
22 changes: 14 additions & 8 deletions cpp/modules/l4/include/ChannelTx.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ namespace styxlib
virtual ~ChannelTx() = default;
virtual SizeResult sendBuffer(ClientId clientId, const StyxBuffer buffer, Size size) = 0;
};

/**
* Sets the packet size in the provided buffer according to the specified header size.
* @param headerSize The size of the packet header (1, 2, or 4 bytes).
* @param buffer The buffer where the packet size will be set.
* @param bufferSize The size of the buffer.
* @param packetSize The size of the packet to set.
* @return The number of bytes used for the header, or an ErrorCode if an error occurs.
*/
SizeResult setPacketSize(
const PacketHeaderSize &headerSize,
uint8_t *buffer,
Size bufferSize,
Size packetSize);
}

#if __cplusplus >= 202302L
#include "cxx_23/ChannelTx.h"
#elif __cplusplus >= 201703L
#include "cxx_17/ChannelTx.h"
#else
// Handle older standards (C++14, C++11, etc.)
#error "This library requires at least C++17."
#endif
1 change: 0 additions & 1 deletion cpp/modules/l4/include/SerializerL4.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#include "data.h"
#include "Channel.h"

namespace styxlib
{
Expand Down
18 changes: 0 additions & 18 deletions cpp/modules/l4/include/cxx_17/ChannelTx.h

This file was deleted.

7 changes: 7 additions & 0 deletions cpp/modules/l4/include/cxx_17/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@ namespace styxlib
bool has_value() const { return _error == ErrorCode::Success; }
};

class Unexpected: public ExpectedSizeResult
{
public:
Unexpected(ErrorCode error) : ExpectedSizeResult(error) {}
};

using SizeResult = ExpectedSizeResult;

}
18 changes: 0 additions & 18 deletions cpp/modules/l4/include/cxx_23/ChannelTx.h

This file was deleted.

1 change: 1 addition & 0 deletions cpp/modules/l4/include/cxx_23/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
namespace styxlib
{
using SizeResult = std::expected<Size, ErrorCode>;
using Unexpected = std::unexpected<ErrorCode>;
}
3 changes: 2 additions & 1 deletion cpp/modules/l4/include/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ namespace styxlib
UnknownClient,
BufferTooSmall,
InvalidHeaderSize,
NullptrArgument
NullptrArgument,
SendFailed
};

enum class PacketHeaderSize : uint8_t
Expand Down
2 changes: 1 addition & 1 deletion cpp/modules/l4/include/impl/ChannelUnixFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cstdint>

#include "data.h"
#include "Channel.h"
#include "ChannelRx.h"
#include "ChannelTx.h"

namespace styxlib
Expand Down
Loading
Loading