Skip to content

Commit

Permalink
(conan-io#22490) Add rotor v0.28, v0.29
Browse files Browse the repository at this point in the history
* Add rotor v0.28

* Feedback: remove exports_sources

* Update receipe

* Try to use boost 1.84

* refine cppstd validation

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Fix test_package/conanfile.py

* Add v0.29

* Add v0.29

* Add test_v1_package

---------

Signed-off-by: Uilian Ries <uilianries@gmail.com>
Co-authored-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
basiliscos and uilianries authored Mar 1, 2024
1 parent 4b480c6 commit f48eeb7
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 44 deletions.
6 changes: 6 additions & 0 deletions recipes/rotor/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ sources:
"0.25":
url: "https://github.com/basiliscos/cpp-rotor/archive/refs/tags/v0.25.tar.gz"
sha256: "b1de95937adb8d7a9beb93bc4956d8e28ff64a6c0a898e7ce12b22a224bb8f6f"
"0.28":
url: "https://github.com/basiliscos/cpp-rotor/archive/refs/tags/v0.28.tar.gz"
sha256: "9fc7d1721379adca228ca45d0240b5a0060c993de984f0288c9e4b9cf667b971"
"0.29":
url: "https://github.com/basiliscos/cpp-rotor/archive/refs/tags/v0.29.tar.gz"
sha256: "e17e25f2d6402389e8fde07a158ca952b815666f0a2b5e07748dfc062834c522"
67 changes: 35 additions & 32 deletions recipes/rotor/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,65 @@
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, rmdir, copy
from conan.tools.cmake import CMakeToolchain, CMake, CMakeDeps, cmake_layout

required_conan_version = ">=1.52.0"
required_conan_version = ">=1.54.0"

class RotorConan(ConanFile):
name = "rotor"
description = "Event loop friendly C++ actor micro-framework, supervisable"
license = "MIT"
homepage = "https://github.com/basiliscos/cpp-rotor"
url = "https://github.com/conan-io/conan-center-index"
description = (
"Event loop friendly C++ actor micro-framework, supervisable"
)
topics = ("concurrency", "actor-framework", "actors", "actor-model", "erlang", "supervising", "supervisor")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"fPIC": [True, False],
"shared": [True, False],
"enable_asio": [True, False],
"enable_thread": [True, False],
"multithreading": [True, False], # enables multithreading support
"enable_ev": [True, False],
}
default_options = {
"fPIC": True,
"shared": False,
"enable_asio": False,
"enable_thread": False,
"multithreading": True,
"enable_ev": False,
}

@property
def _min_cppstd(self):
return 17

@property
def _compilers_minimum_version(self):
return {
"Visual Studio": "16",
"msvc": "192",
"gcc": "8",
"clang": "7",
"apple-clang": "12",
}

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if Version(self.version) < "0.26":
del self.options.enable_ev

def configure(self):
if self.options.shared:
try:
del self.options.fPIC
except Exception:
pass
self.options.rm_safe("fPIC")

def requirements(self):
self.requires("boost/1.81.0")
self.requires("boost/1.84.0", transitive_headers=True)
if self.options.get_safe("enable_ev", False):
self.requires("libev/4.33")

def layout(self):
cmake_layout(self, src_folder="src")
Expand All @@ -60,31 +75,18 @@ def generate(self):
tc.variables["BUILD_THREAD"] = self.options.enable_thread
tc.variables["BUILD_THREAD_UNSAFE"] = not self.options.multithreading
tc.variables["BUILD_TESTING"] = False
if Version(self.version) >= "0.26":
tc.variables["BUILD_EV"] = self.options.enable_ev
tc.generate()
tc = CMakeDeps(self)
tc.generate()

def validate(self):
minimal_cpp_standard = "17"
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, minimal_cpp_standard)
minimal_version = {
"gcc": "7",
"clang": "6",
"apple-clang": "10",
"Visual Studio": "15"
}
compiler = str(self.settings.compiler)
if compiler not in minimal_version:
self.output.warn(
f"{self.ref} recipe lacks information about the {compiler} compiler standard version support")
self.output.warn(
f"{self.ref} requires a compiler that supports at least C++{minimal_cpp_standard}")
return

compiler_version = Version(self.settings.compiler.version)
if compiler_version < minimal_version[compiler]:
raise ConanInvalidConfiguration(f"{self.ref} requires a compiler that supports at least C++{minimal_cpp_standard}")
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support.")

if self.options.shared and Version(self.version) < "0.23":
raise ConanInvalidConfiguration("shared option is available from v0.23")
Expand Down Expand Up @@ -121,5 +123,6 @@ def package_info(self):
self.cpp_info.components["thread"].libs = ["rotor_thread"]
self.cpp_info.components["thread"].requires = ["core"]

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.names["cmake_find_package"] = "rotor"
if self.options.get_safe("enable_ev", False):
self.cpp_info.components["ev"].libs = ["rotor_ev"]
self.cpp_info.components["ev"].requires = ["core", "libev::libev"]
8 changes: 2 additions & 6 deletions recipes/rotor/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.15)
project(test_package CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
find_package("rotor" REQUIRED)
find_package("rotor" COMPONENTS asio thread REQUIRED)

add_executable(${PROJECT_NAME} test_package.cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
target_link_libraries(${PROJECT_NAME} rotor::core)


20 changes: 14 additions & 6 deletions recipes/rotor/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/rotor/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package CXX)

find_package("rotor" COMPONENTS asio thread REQUIRED)

add_executable(${PROJECT_NAME} test_package.cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
target_link_libraries(${PROJECT_NAME} rotor::core)
26 changes: 26 additions & 0 deletions recipes/rotor/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
58 changes: 58 additions & 0 deletions recipes/rotor/all/test_v1_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <rotor/supervisor.h>
#include <iostream>


namespace {
namespace to {
struct on_timer_trigger {};
} // namespace to
} // namespace

namespace rotor {
template <>
inline auto rotor::actor_base_t::access<to::on_timer_trigger, request_id_t, bool>(request_id_t request_id,
bool cancelled) noexcept {
on_timer_trigger(request_id, cancelled);
}
} // namespace rotor

struct dummy_supervisor_t : public rotor::supervisor_t {
using rotor::supervisor_t::supervisor_t;
using timers_map_t = std::unordered_map<rotor::request_id_t, rotor::timer_handler_base_t *>;

timers_map_t timers_map;

void do_start_timer(const rotor::pt::time_duration &, rotor::timer_handler_base_t &handler) noexcept override {
timers_map.emplace(handler.request_id, &handler);
}

void do_cancel_timer(rotor::request_id_t timer_id) noexcept override {
auto it = timers_map.find(timer_id);
auto &actor_ptr = it->second->owner;
actor_ptr->access<to::on_timer_trigger, rotor::request_id_t, bool>(timer_id, true);
timers_map.erase(it);
}

void start() noexcept override {}
void shutdown() noexcept override {}
void enqueue(rotor::message_ptr_t) noexcept override {}
};

struct hello_actor : public rotor::actor_base_t {
using rotor::actor_base_t::actor_base_t;
void on_start() noexcept override {
rotor::actor_base_t::on_start();
std::cout << "hello world\n";
supervisor->do_shutdown();
}
};

int main() {
rotor::system_context_t ctx{};
auto timeout = boost::posix_time::milliseconds{500}; /* does not matter */
auto sup = ctx.create_supervisor<dummy_supervisor_t>().timeout(timeout).finish();
sup->create_actor<hello_actor>().timeout(timeout).finish();
sup->do_process();
return 0;
}

4 changes: 4 additions & 0 deletions recipes/rotor/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ versions:
folder: all
"0.25":
folder: all
"0.28":
folder: all
"0.29":
folder: all

0 comments on commit f48eeb7

Please sign in to comment.