Skip to content

Commit f407f0c

Browse files
committed
Make strong_ptr transitive dependency
1 parent 630eb04 commit f407f0c

File tree

7 files changed

+185
-5
lines changed

7 files changed

+185
-5
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ cmake_minimum_required(VERSION 3.28)
1717
# Generate compile commands for anyone using our libraries.
1818
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1919
set(CMAKE_COLOR_DIAGNOSTICS ON)
20+
set(CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_DEPENDENCIES
21+
"1942b4fa-b2c5-4546-9385-83f254070067")
2022

2123
project(async_context LANGUAGES CXX)
2224

@@ -48,10 +50,10 @@ install(
4850

4951
install(
5052
EXPORT async_context_targets
51-
FILE "libasync_context-config.cmake"
52-
NAMESPACE libasync_context::
53+
FILE "async_context-config.cmake"
5354
DESTINATION "lib/cmake"
5455
CXX_MODULES_DIRECTORY "cxx-modules"
56+
EXPORT_PACKAGE_DEPENDENCIES
5557
)
5658

5759
# ==============================================================================

conanfile.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class async_context_conan(ConanFile):
3333
description = ("Implementation of C++20 coroutines targeting embedded system by eliminating the usage of the global heap and providing a 'context' which contains a coroutine stack frame and other useful utilities for scheduling.")
3434
topics = ("async", "coroutines", "stack", "scheduling", "scheduler")
3535
settings = "compiler", "build_type", "os", "arch"
36-
exports_sources = "modules/*", "tests/*", "CMakeLists.txt", "LICENSE"
36+
exports_sources = "modules/*", "tests/*", "CMakeLists.txt", "*.cmake.in", "LICENSE"
3737
package_type = "static-library"
3838
shared = False
3939

@@ -89,7 +89,8 @@ def build_requirements(self):
8989
self.test_requires("boost-ext-ut/2.3.1")
9090

9191
def requirements(self):
92-
self.requires("strong_ptr/0.0.0")
92+
self.requires("strong_ptr/0.0.0", transitive_libs=True,
93+
transitive_headers=True)
9394

9495
def layout(self):
9596
cmake_layout(self)

modules/async_context.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ public:
599599

600600
constexpr void resume() const
601601
{
602-
auto active = handle().promise().context().active_handle();
602+
auto active = handle().promise().get_context().active_handle();
603603
active.resume();
604604
}
605605

test_package/.clangd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CompileFlags:
2+
CompilationDatabase: .
3+
BuiltinHeaders: QueryDriver

test_package/CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2024 - 2025 Khalil Estell and the libhal contributors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
cmake_minimum_required(VERSION 4.0)
16+
17+
# Generate compile commands for anyone using our libraries.
18+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
19+
set(CMAKE_COLOR_DIAGNOSTICS ON)
20+
21+
project(test_package LANGUAGES CXX)
22+
23+
# Require Ninja or Visual Studio for modules
24+
if(NOT CMAKE_GENERATOR MATCHES "Ninja|Visual Studio")
25+
message(FATAL_ERROR "C++20 modules require Ninja or Visual Studio generator")
26+
endif()
27+
28+
find_package(async_context REQUIRED CONFIG)
29+
30+
add_executable(${PROJECT_NAME})
31+
target_sources(${PROJECT_NAME} PUBLIC
32+
FILE_SET CXX_MODULES
33+
TYPE CXX_MODULES
34+
PRIVATE main.cpp
35+
)
36+
target_include_directories(${PROJECT_NAME} PUBLIC .)
37+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_23)
38+
target_link_libraries(${PROJECT_NAME} PRIVATE async_context)
39+
40+
# Always run this custom target by making it depend on ALL
41+
add_custom_target(copy_compile_commands ALL
42+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
43+
${CMAKE_BINARY_DIR}/compile_commands.json
44+
${CMAKE_SOURCE_DIR}/compile_commands.json
45+
DEPENDS ${CMAKE_BINARY_DIR}/compile_commands.json)

test_package/conanfile.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/python
2+
#
3+
# Copyright 2024 - 2025 Khalil Estell and the libhal contributors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from conan import ConanFile
18+
from conan.tools.build import cross_building
19+
from conan.tools.cmake import CMake, cmake_layout, CMakeToolchain, CMakeDeps
20+
from pathlib import Path
21+
22+
23+
class TestPackageConan(ConanFile):
24+
settings = "os", "arch", "compiler", "build_type"
25+
generators = "VirtualRunEnv"
26+
27+
def build_requirements(self):
28+
self.tool_requires("cmake-modules-toolchain/1.0.2")
29+
30+
def requirements(self):
31+
self.requires(self.tested_reference_str)
32+
33+
def layout(self):
34+
cmake_layout(self)
35+
36+
def generate(self):
37+
tc = CMakeToolchain(self)
38+
tc.generate()
39+
40+
deps = CMakeDeps(self)
41+
deps.generate()
42+
43+
def build(self):
44+
cmake = CMake(self)
45+
cmake.configure()
46+
cmake.build()
47+
48+
def test(self):
49+
if not cross_building(self):
50+
bin_path = Path(self.cpp.build.bindirs[0]) / "test_package"
51+
self.run(bin_path.absolute(), env="conanrun")

test_package/main.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright 2024 - 2025 Khalil Estell and the libhal contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <cassert>
16+
17+
#include <array>
18+
#include <chrono>
19+
#include <coroutine>
20+
#include <memory_resource>
21+
#include <span>
22+
#include <variant>
23+
24+
import async_context;
25+
26+
struct my_scheduler : public async::scheduler
27+
{
28+
int sleep_count = 0;
29+
30+
private:
31+
void do_schedule(
32+
[[maybe_unused]] async::context& p_context,
33+
[[maybe_unused]] async::blocked_by p_block_state,
34+
[[maybe_unused]] std::variant<async::sleep_duration, async::context*>
35+
p_block_info) override
36+
{
37+
if (std::holds_alternative<async::sleep_duration>(p_block_info)) {
38+
sleep_count++;
39+
}
40+
}
41+
};
42+
43+
async::future<void> coro_double_delay(async::context&)
44+
{
45+
using namespace std::chrono_literals;
46+
co_await 100ns;
47+
co_await 100ns;
48+
co_return;
49+
}
50+
int main()
51+
{
52+
auto scheduler =
53+
mem::make_strong_ptr<my_scheduler>(std::pmr::new_delete_resource());
54+
auto buffer = mem::make_strong_ptr<std::array<async::u8, 1024>>(
55+
std::pmr::new_delete_resource());
56+
auto buffer_span = mem::make_strong_ptr<std::span<async::u8>>(
57+
std::pmr::new_delete_resource(), *buffer);
58+
async::context my_context(scheduler, buffer_span);
59+
60+
auto future_delay = coro_double_delay(my_context);
61+
62+
assert(not future_delay.done());
63+
64+
future_delay.resume();
65+
66+
assert(scheduler->sleep_count == 1);
67+
68+
future_delay.resume();
69+
70+
assert(scheduler->sleep_count == 2);
71+
assert(not scheduler->done());
72+
73+
future_delay.resume();
74+
75+
assert(scheduler->done());
76+
77+
return 0;
78+
}

0 commit comments

Comments
 (0)