From 6f6ab3fb07b89beaa0f018464536a1cab67b3498 Mon Sep 17 00:00:00 2001 From: BestITUserEUW Date: Tue, 14 Oct 2025 20:55:31 +0200 Subject: [PATCH 1/2] added explicit exports for shared builds ci updates --- .github/workflows/linux.yaml | 4 ++++ .github/workflows/windows.yaml | 16 +++++++++------ CMakeLists.txt | 1 + include/oryx/chron/chrono_types.hpp | 11 ---------- include/oryx/chron/clock.hpp | 10 ++++----- include/oryx/chron/common.hpp | 25 +++++++++++++++++++++++ include/oryx/chron/details/any_of.hpp | 2 -- include/oryx/chron/details/null_mutex.hpp | 15 -------------- include/oryx/chron/null_mutex.hpp | 15 ++++++++++++++ include/oryx/chron/parser.hpp | 12 ++++++----- include/oryx/chron/preprocessor.hpp | 6 +++--- include/oryx/chron/randomization.hpp | 5 ++++- include/oryx/chron/schedule.hpp | 9 ++++---- include/oryx/chron/scheduler.hpp | 16 +++++++-------- include/oryx/chron/task.hpp | 14 +++---------- include/oryx/chron/traits.hpp | 2 +- include/oryx/chron/version.hpp | 4 +++- src/clock.cpp | 1 - src/schedule.cpp | 2 +- src/task.cpp | 3 ++- 20 files changed, 97 insertions(+), 76 deletions(-) delete mode 100644 include/oryx/chron/chrono_types.hpp create mode 100644 include/oryx/chron/common.hpp delete mode 100644 include/oryx/chron/details/null_mutex.hpp create mode 100644 include/oryx/chron/null_mutex.hpp diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index 77c7451..16e0009 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -66,8 +66,12 @@ jobs: include: - name: "ASan" extra-flags: "-DORYX_CHRON_SANITIZE_ADDRESS=ON" + - name: "TSan" + extra-flags: "-DORYX_CHRON_SANITIZE_THREAD=ON" # Not doing much right now - name: "Optimized Build" extra-flags: "-DCMAKE_CXX_FLAGS=-O3" + - name: "Shared Build" + extra-flags: "-DORYX_CHRON_BUILD_SHARED_LIBS=ON" name: "${{ github.job }} ${{ matrix.name }}" runs-on: ubuntu-latest diff --git a/.github/workflows/windows.yaml b/.github/workflows/windows.yaml index e5f253f..589c8e1 100644 --- a/.github/workflows/windows.yaml +++ b/.github/workflows/windows.yaml @@ -2,29 +2,33 @@ name: windows on: [push, pull_request] -env: - VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" - jobs: windows-msvc: runs-on: windows-latest + strategy: + matrix: + shared: [OFF, ON] + name: "Windows MSVC ${{ matrix.shared == 'ON' && 'shared' || 'static' }}" steps: - name: Checkout uses: actions/checkout@v4 with: submodules: recursive fetch-depth: 0 + - name: Export GitHub Actions cache environment variables uses: actions/github-script@v7 with: script: | core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + - uses: ilammy/msvc-dev-cmd@v1 + - name: Compile run: | - cmake -B build -DORYX_CHRON_BUILD_TESTS=ON -DCMAKE_CXX_STANDARD=20 -DCMAKE_BUILD_TYPE=Release + cmake -B build -DORYX_CHRON_BUILD_TESTS=ON -DORYX_CHRON_BUILD_SHARED_LIBS=${{ matrix.shared }} -DCMAKE_CXX_STANDARD=20 -DCMAKE_BUILD_TYPE=Release cmake --build build + - name: Run tests - run: | - .\build\Debug\chron-cpp_tests --success + run: .\build\Debug\chron-cpp_tests diff --git a/CMakeLists.txt b/CMakeLists.txt index 904e917..ef5d54d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ endif() if (ORYX_CHRON_BUILD_SHARED_LIBS) add_library(${PROJECT_NAME} SHARED) + target_compile_definitions(${PROJECT_NAME} PUBLIC ORYX_CHRON_BUILD_SHARED_LIBS) set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION}) else() add_library(${PROJECT_NAME} STATIC) diff --git a/include/oryx/chron/chrono_types.hpp b/include/oryx/chron/chrono_types.hpp deleted file mode 100644 index 4f2acb8..0000000 --- a/include/oryx/chron/chrono_types.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include - -namespace oryx::chron { - -using Clock = std::chrono::system_clock; -using TimePoint = std::chrono::time_point; -using Duration = Clock::duration; - -} // namespace oryx::chron \ No newline at end of file diff --git a/include/oryx/chron/clock.hpp b/include/oryx/chron/clock.hpp index 0320c1b..3ee24ef 100644 --- a/include/oryx/chron/clock.hpp +++ b/include/oryx/chron/clock.hpp @@ -4,18 +4,18 @@ #include #include -#include -#include +#include "common.hpp" +#include "traits.hpp" namespace oryx::chron { -class UTCClock { +class ORYX_CHRON_API UTCClock { public: auto Now() const -> TimePoint { return Clock::now(); } auto UtcOffset(TimePoint) const -> std::chrono::seconds { return std::chrono::seconds(0); } }; -class LocalClock { +class ORYX_CHRON_API LocalClock { public: auto Now() const -> TimePoint { auto now = Clock::now(); @@ -25,7 +25,7 @@ class LocalClock { auto UtcOffset(TimePoint now) const -> std::chrono::seconds; }; -class TzClock { +class ORYX_CHRON_API TzClock { public: auto Now() const -> TimePoint { auto now = Clock::now(); diff --git a/include/oryx/chron/common.hpp b/include/oryx/chron/common.hpp new file mode 100644 index 0000000..c57d970 --- /dev/null +++ b/include/oryx/chron/common.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include + +#ifdef ORYX_CHRON_BUILD_SHARED_LIBS + #ifdef _WIN32 + #ifdef chron_cpp_EXPORTS + #define ORYX_CHRON_API __declspec(dllexport) + #else + #define ORYX_CHRON_API __declspec(dllimport) + #endif + #else + #define ORYX_CHRON_API __attribute__((visibility("default"))) + #endif +#else + #define ORYX_CHRON_API +#endif + +namespace oryx::chron { + +using Clock = std::chrono::system_clock; +using TimePoint = std::chrono::time_point; +using Duration = Clock::duration; + +} // namespace oryx::chron \ No newline at end of file diff --git a/include/oryx/chron/details/any_of.hpp b/include/oryx/chron/details/any_of.hpp index 65faebc..e6ad1e8 100644 --- a/include/oryx/chron/details/any_of.hpp +++ b/include/oryx/chron/details/any_of.hpp @@ -3,8 +3,6 @@ #include #include -#include - namespace oryx::chron::details { namespace traits { diff --git a/include/oryx/chron/details/null_mutex.hpp b/include/oryx/chron/details/null_mutex.hpp deleted file mode 100644 index 835fc67..0000000 --- a/include/oryx/chron/details/null_mutex.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include - -namespace oryx::chron::details { - -class NullMutex { -public: - void lock() {} - void unlock() {} -}; - -static_assert(traits::BasicLockable); - -} // namespace oryx::chron::details \ No newline at end of file diff --git a/include/oryx/chron/null_mutex.hpp b/include/oryx/chron/null_mutex.hpp new file mode 100644 index 0000000..b2704f9 --- /dev/null +++ b/include/oryx/chron/null_mutex.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "traits.hpp" + +namespace oryx::chron { + +class NullMutex { +public: + void lock() noexcept {} + void unlock() noexcept {} +}; + +static_assert(traits::BasicLockable); + +} // namespace oryx::chron \ No newline at end of file diff --git a/include/oryx/chron/parser.hpp b/include/oryx/chron/parser.hpp index 10c6eda..e4a307f 100644 --- a/include/oryx/chron/parser.hpp +++ b/include/oryx/chron/parser.hpp @@ -1,21 +1,23 @@ #pragma once -#include #include +#include +#include +#include #include -#include - +#include "common.hpp" #include "chron_data.hpp" #include "traits.hpp" +#include "null_mutex.hpp" namespace oryx::chron { -struct ExpressionParser { +struct ORYX_CHRON_API ExpressionParser { auto operator()(std::string_view cron_expression) const -> std::optional; }; -template +template class CachedExpressionParser : ExpressionParser { public: using Pair = std::pair; diff --git a/include/oryx/chron/preprocessor.hpp b/include/oryx/chron/preprocessor.hpp index 3fcf277..3e1d202 100644 --- a/include/oryx/chron/preprocessor.hpp +++ b/include/oryx/chron/preprocessor.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include "traits.hpp" namespace oryx::chron { @@ -22,11 +22,11 @@ struct Processors { } }; -struct DollarExpressionProcessor { +struct ORYX_CHRON_API DollarExpressionProcessor { static auto Process(std::string data) noexcept -> std::string; }; -struct WeekMonthDayLiteralProcessor { +struct ORYX_CHRON_API WeekMonthDayLiteralProcessor { static auto Process(std::string data) noexcept -> std::string; }; diff --git a/include/oryx/chron/randomization.hpp b/include/oryx/chron/randomization.hpp index 02ab58e..c62a611 100644 --- a/include/oryx/chron/randomization.hpp +++ b/include/oryx/chron/randomization.hpp @@ -4,8 +4,11 @@ #include #include +#include "common.hpp" + namespace oryx::chron { -class Randomization { + +class ORYX_CHRON_API Randomization { public: Randomization(); diff --git a/include/oryx/chron/schedule.hpp b/include/oryx/chron/schedule.hpp index 72afaa6..c1a10c0 100644 --- a/include/oryx/chron/schedule.hpp +++ b/include/oryx/chron/schedule.hpp @@ -2,12 +2,13 @@ #include -#include -#include -#include +#include "common.hpp" +#include "chron_data.hpp" +#include "date_time.hpp" namespace oryx::chron { -class Schedule { + +class ORYX_CHRON_API Schedule { public: explicit Schedule(ChronData data) : data_(std::move(data)) {} diff --git a/include/oryx/chron/scheduler.hpp b/include/oryx/chron/scheduler.hpp index f862c0e..5dba9c0 100644 --- a/include/oryx/chron/scheduler.hpp +++ b/include/oryx/chron/scheduler.hpp @@ -8,16 +8,16 @@ #include #include -#include -#include -#include -#include -#include +#include "common.hpp" +#include "traits.hpp" +#include "clock.hpp" +#include "parser.hpp" +#include "task.hpp" namespace oryx::chron { template class Scheduler { public: @@ -67,7 +67,7 @@ class Scheduler { void RemoveSchedule(std::string_view name) { std::lock_guard lock{tasks_mtx_}; - std::erase_if(tasks_, [name](const Task& t) { return t == name; }); + std::erase_if(tasks_, [name](const Task& t) { return t.GetName() == name; }); } void RecalculateSchedules() { @@ -170,7 +170,7 @@ class Scheduler { }; template -using CScheduler = Scheduler>; +using CScheduler = Scheduler>; template using MTScheduler = Scheduler; diff --git a/include/oryx/chron/task.hpp b/include/oryx/chron/task.hpp index 4cc88be..d15d4d9 100644 --- a/include/oryx/chron/task.hpp +++ b/include/oryx/chron/task.hpp @@ -3,8 +3,8 @@ #include #include -#include -#include +#include "common.hpp" +#include "schedule.hpp" namespace oryx::chron { @@ -15,7 +15,7 @@ struct TaskInfo { using TaskFn = std::function; -class Task { +class ORYX_CHRON_API Task { public: Task(std::string name, Schedule schedule, TaskFn task); @@ -41,12 +41,4 @@ class Task { bool valid_; }; -inline auto operator==(std::string_view lhs, const Task &rhs) -> bool { return lhs == rhs.GetName(); } - -inline auto operator==(const Task &lhs, std::string_view rhs) -> bool { return lhs.GetName() == rhs; } - -inline auto operator!=(std::string_view lhs, const Task &rhs) -> bool { return !(lhs == rhs); } - -inline auto operator!=(const Task &lhs, std::string_view rhs) -> bool { return !(lhs == rhs); } - } // namespace oryx::chron diff --git a/include/oryx/chron/traits.hpp b/include/oryx/chron/traits.hpp index 1d1784c..c0d05a1 100644 --- a/include/oryx/chron/traits.hpp +++ b/include/oryx/chron/traits.hpp @@ -6,7 +6,7 @@ #include #include -#include "chrono_types.hpp" +#include "common.hpp" #include "chron_data.hpp" namespace oryx::chron::traits { diff --git a/include/oryx/chron/version.hpp b/include/oryx/chron/version.hpp index 8929fcd..9242e69 100644 --- a/include/oryx/chron/version.hpp +++ b/include/oryx/chron/version.hpp @@ -2,12 +2,14 @@ #include +#include "common.hpp" + namespace oryx::chron { inline constexpr int kVersionMajor = 0; inline constexpr int KVersionMinor = 3; inline constexpr int kVersionPatch = 0; -auto MakeStringVersion() -> std::string; +ORYX_CHRON_API auto MakeStringVersion() -> std::string; } // namespace oryx::chron \ No newline at end of file diff --git a/src/clock.cpp b/src/clock.cpp index 493a39b..20f32b4 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -1,4 +1,3 @@ - #include #ifdef WIN32 diff --git a/src/schedule.cpp b/src/schedule.cpp index da10926..cf0ead4 100644 --- a/src/schedule.cpp +++ b/src/schedule.cpp @@ -1,8 +1,8 @@ #include #include +#include #include -#include using namespace std::chrono; diff --git a/src/task.cpp b/src/task.cpp index 62ea097..9a695af 100644 --- a/src/task.cpp +++ b/src/task.cpp @@ -1,7 +1,8 @@ #include #include -#include "oryx/chron/chrono_types.hpp" + +#include using namespace std::chrono; From bedc1e5adcf96a315ccd619f3d3a631c43e74392 Mon Sep 17 00:00:00 2001 From: BestITUserEUW Date: Tue, 14 Oct 2025 21:17:29 +0200 Subject: [PATCH 2/2] silence C4251 when building shared in msvc --- CMakeLists.txt | 2 ++ src/clock.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef5d54d..a96849f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,8 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_options(${PROJECT_NAME} PRIVATE /W4 + PUBLIC + $<$:/wd4251> ) else() target_compile_options(${PROJECT_NAME} diff --git a/src/clock.cpp b/src/clock.cpp index 20f32b4..f925107 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -39,7 +39,7 @@ auto TzClock::TrySetTimezone(std::string_view name) -> bool { try { new_zone = locate_zone(name); - } catch (std::runtime_error &err) { + } catch (std::runtime_error &) { return false; }