Skip to content

Commit 067d041

Browse files
committed
fix Conan recipe: add system_context option and correct package_type/package_id
- Add system_context option (default False) to reflect that stdexec is header-only by default; opt in to build the compiled system_context library - Set package_type dynamically in configure(): header-library or static-library - package_id() clears settings only when system_context=False (header-only) - Pass STDEXEC_BUILD_SYSTEM_CONTEXT to CMake based on the option - Declare system_context as a Conan component so CMakeDeps generates the STDEXEC::system_context target for consumers - test_package: conditionally link and test system_context when available
1 parent 814da48 commit 067d041

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

conanfile.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ class StdexecPackage(ConanFile):
1414
license = "Apache 2.0"
1515

1616
settings = "os", "arch", "compiler", "build_type"
17+
options = {
18+
"system_context": [True, False],
19+
}
20+
default_options = {
21+
"system_context": False,
22+
}
1723
exports_sources = (
1824
"include/*",
1925
"src/*",
@@ -24,6 +30,12 @@ class StdexecPackage(ConanFile):
2430
)
2531
generators = "CMakeToolchain"
2632

33+
def configure(self):
34+
if self.options.system_context:
35+
self.package_type = "static-library"
36+
else:
37+
self.package_type = "header-library"
38+
2739
def validate(self):
2840
check_min_cppstd(self, "20")
2941

@@ -37,18 +49,21 @@ def layout(self):
3749

3850
def build(self):
3951
tests = "OFF" if self.conf.get("tools.build:skip_test", default=False) else "ON"
52+
system_context = "ON" if self.options.system_context else "OFF"
4053

4154
cmake = CMake(self)
4255
cmake.configure(variables={
4356
"STDEXEC_BUILD_TESTS": tests,
4457
"STDEXEC_BUILD_EXAMPLES": tests,
58+
"STDEXEC_BUILD_SYSTEM_CONTEXT": system_context,
4559
})
4660
cmake.build()
4761
cmake.test()
4862

4963
def package_id(self):
50-
# Clear settings because this package is header-only.
51-
self.info.clear()
64+
if not self.info.options.system_context:
65+
# Clear settings because this package is header-only.
66+
self.info.clear()
5267

5368
def package(self):
5469
cmake = CMake(self)
@@ -58,4 +73,8 @@ def package_info(self):
5873
self.cpp_info.set_property("cmake_file_name", "P2300")
5974
self.cpp_info.set_property("cmake_target_name", "P2300::P2300")
6075
self.cpp_info.set_property("cmake_target_aliases", ["STDEXEC::stdexec"])
61-
self.cpp_info.libs = ["system_context"]
76+
if self.options.system_context:
77+
self.cpp_info.components["system_context"].libs = ["system_context"]
78+
self.cpp_info.components["system_context"].set_property(
79+
"cmake_target_name", "STDEXEC::system_context"
80+
)

test_package/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ enable_testing()
55
find_package(P2300 REQUIRED)
66

77
add_executable(test_stdexec test.cpp)
8-
target_link_libraries(test_stdexec STDEXEC::stdexec)
8+
target_link_libraries(test_stdexec STDEXEC::stdexec $<TARGET_NAME_IF_EXISTS:STDEXEC::system_context>)
9+
if(TARGET STDEXEC::system_context)
10+
target_compile_definitions(test_stdexec PRIVATE STDEXEC_TEST_SYSTEM_CONTEXT)
11+
endif()
912
add_test(test_stdexec test_stdexec)

test_package/test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
#ifdef STDEXEC_TEST_SYSTEM_CONTEXT
12
#include <exec/system_context.hpp>
3+
#else
4+
#include <exec/static_thread_pool.hpp>
5+
#endif
26
#include <stdexec/execution.hpp>
37

48
#include <cstdlib>
59

610
int main()
711
{
12+
#ifdef STDEXEC_TEST_SYSTEM_CONTEXT
813
auto x = stdexec::starts_on(exec::get_parallel_scheduler(), stdexec::just(42));
14+
#else
15+
exec::static_thread_pool pool{1};
16+
auto x = stdexec::starts_on(pool.get_scheduler(), stdexec::just(42));
17+
#endif
918
auto [a] = stdexec::sync_wait(std::move(x)).value();
1019
return a == 42 ? EXIT_SUCCESS : EXIT_FAILURE;
1120
}

0 commit comments

Comments
 (0)