Skip to content

Commit 2236217

Browse files
committed
Add the execution.cppm module again
1 parent 407b112 commit 2236217

File tree

9 files changed

+531
-5
lines changed

9 files changed

+531
-5
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ set(TARGET_PREFIX ${TARGET_NAMESPACE}.${TARGET_NAME})
3434
set(TARGET_LIBRARY ${PROJECT_NAME})
3535
set(TARGET_ALIAS ${TARGET_NAMESPACE}::${TARGET_NAME})
3636
set(TARGET_PACKAGE_NAME ${PROJECT_NAME}-config)
37-
set(TARGETS_EXPORT_NAME ${PROJECT_NAME}-targets)
37+
set(TARGETS_EXPORT_NAME ${PROJECT_NAME}-config-targets)
3838

3939
#========================== post project settings ==============================
4040
# Tell CMake that we explicitly want `import std`.

Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ endif
3131
LDFLAGS ?=
3232
SAN_FLAGS ?=
3333
CXX_FLAGS ?= -g
34+
# TODO: SANITIZER := release
3435
SANITIZER ?= default
3536
SOURCEDIR = $(CURDIR)
3637
BUILDROOT = build
3738
export hostSystemName:=$(shell uname -s)
38-
BUILD = $(BUILDROOT)/$(hostSystemName)/$(SANITIZER)
39+
# TODO BUILD := $(BUILDROOT)/$(SANITIZER)
40+
BUILD ?= $(BUILDROOT)/$(hostSystemName)/$(SANITIZER)
3941
EXAMPLE = beman.execution.examples.stop_token
4042

4143
################################################
@@ -92,6 +94,9 @@ ifeq ($(SANITIZER),lsan)
9294
LDFLAGS = $(SAN_FLAGS)
9395
endif
9496

97+
# TODO: beman.execution.examples.modules
98+
# FIXME: beman.execution.execution-module.test beman.execution.stop-token-module.test
99+
95100
default: test
96101

97102
all: $(SANITIZERS)
@@ -115,7 +120,7 @@ build:
115120
-D CMAKE_CXX_COMPILER=$(CXX) # XXX -D CMAKE_CXX_FLAGS="$(CXX_FLAGS) $(SAN_FLAGS)"
116121
cmake --build $(BUILD)
117122

118-
# NOTE: without install! CK
123+
# NOTE: without install, see CMAKE_SKIP_INSTALL_RULES! CK
119124
test: build
120125
ctest --test-dir $(BUILD) --rerun-failed --output-on-failure
121126

@@ -126,12 +131,12 @@ CMakeUserPresets.json:: cmake/CMakeUserPresets.json
126131
ln -s $< $@
127132

128133
release: CMakeUserPresets.json
129-
cmake --preset $@ --fresh --log-level=TRACE
134+
cmake --preset $@ --log-level=TRACE # XXX --fresh
130135
ln -fs $(BUILDROOT)/$@/compile_commands.json .
131136
cmake --workflow --preset $@
132137

133138
debug: CMakeUserPresets.json
134-
cmake --preset $@ --fresh --log-level=TRACE
139+
cmake --preset $@ --log-level=TRACE # XXX --fresh
135140
ln -fs $(BUILDROOT)build/$@/compile_commands.json .
136141
cmake --workflow --preset $@
137142

examples/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ list(
2121
doc-just_stopped
2222
)
2323

24+
if(BEMAN_USE_MODULES)
25+
list(APPEND EXAMPLES modules) # modules.cpp
26+
endif()
27+
2428
foreach(EXAMPLE ${EXAMPLES})
2529
set(EXAMPLE_TARGET ${TARGET_PREFIX}.examples.${EXAMPLE})
2630
add_executable(${EXAMPLE_TARGET})

examples/modules.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// examples/modules.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifdef BEMAN_HAS_IMPORT_STD
5+
import std;
6+
#else
7+
8+
#include <version>
9+
#include <iostream>
10+
#include <string>
11+
12+
#endif
13+
14+
#if __cpp_modules < 201907L
15+
#include <beman/execution/execution.hpp>
16+
#else
17+
import beman_execution;
18+
#endif
19+
20+
namespace ex = beman::execution;
21+
22+
int main() {
23+
auto [result] = ex::sync_wait(ex::when_all(ex::just(std::string("hello, ")), ex::just(std::string("world"))) |
24+
ex::then([](const auto& s1, const auto& s2) { return s1 + s2; }))
25+
.value_or(std::tuple(std::string("oops")));
26+
std::cout << "result='" << result << "'\n";
27+
}

src/beman/execution/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ target_sources(
192192
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/write_env.hpp
193193
)
194194

195+
if(BEMAN_USE_MODULES)
196+
target_sources(
197+
${TARGET_NAME}
198+
PUBLIC
199+
FILE_SET CXX_MODULES
200+
BASE_DIRS ${PROJECT_SOURCE_DIR}/src/beman/execution
201+
FILES ${PROJECT_SOURCE_DIR}/src/beman/execution/execution.cppm
202+
)
203+
endif()
204+
195205
get_property(
196206
DETAIL_HEADER_FILES
197207
TARGET ${TARGET_NAME}
@@ -211,11 +221,17 @@ install(
211221
ARCHIVE DESTINATION lib/$<CONFIG>
212222
FILE_SET ${TARGET_NAME}_public_headers
213223
FILE_SET ${TARGET_NAME}_detail_headers
224+
FILE_SET CXX_MODULES DESTINATION ${INSTALL_CONFIGDIR}/module
225+
# There's currently no convention for this location
226+
CXX_MODULES_BMI
227+
DESTINATION ${INSTALL_CONFIGDIR}/bmi-${CMAKE_CXX_COMPILER_ID}_$<CONFIG>
214228
)
215229

216230
install(
217231
EXPORT ${TARGETS_EXPORT_NAME}1
218232
FILE ${TARGETS_EXPORT_NAME}.cmake
219233
DESTINATION "${INSTALL_CONFIGDIR}"
220234
NAMESPACE ${TARGET_NAMESPACE}::
235+
CXX_MODULES_DIRECTORY
236+
.
221237
)

src/beman/execution/execution.cppm

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
// src/beman/execution/execution.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
// ----------------------------------------------------------------------------
4+
5+
module;
6+
#include <execution>
7+
#include <stop_token>
8+
#include <beman/execution/execution.hpp>
9+
#include <beman/execution/stop_token.hpp>
10+
11+
export module beman_execution;
12+
13+
namespace beman::execution {
14+
export int version(0);
15+
// [stoptoken.concepts], stop token concepts
16+
export using ::beman::execution::stoppable_token;
17+
export using ::beman::execution::unstoppable_token;
18+
19+
// [stoptoken], class stop_token
20+
export using ::beman::execution::stop_token;
21+
22+
// [stopsource], class stop_source
23+
export using ::beman::execution::stop_source;
24+
25+
// no-shared-stop-state indicator
26+
//-dk:TODO export using ::beman::execution::no_stop_state_t;
27+
28+
// [stopcallback], class template stop_callback
29+
export using ::beman::execution::stop_callback;
30+
31+
// [stoptoken.never], class never_stop_token
32+
export using ::beman::execution::never_stop_token;
33+
34+
// [stoptoken.inplace], class inplace_stop_token
35+
export using ::beman::execution::inplace_stop_token;
36+
37+
// [stopsource.inplace], class inplace_stop_source
38+
export using ::beman::execution::inplace_stop_source;
39+
40+
// [stopcallback.inplace], class template inplace_stop_callback
41+
export using ::beman::execution::inplace_stop_callback;
42+
export using ::beman::execution::stop_callback_for_t;
43+
44+
#if 0
45+
//-dk:TODO enable the execution policies
46+
export using ::std::is_execution_policy;
47+
export using ::std::is_execution_policy_v;
48+
49+
export using ::std::execution::sequenced_policy;
50+
export using ::std::execution::parallel_policy;
51+
export using ::std::execution::parallel_unsequenced_policy;
52+
export using ::std::execution::unsequenced_policy;
53+
54+
export using ::std::execution::seq;
55+
export using ::std::execution::par;
56+
export using ::std::execution::par_unseq;
57+
export using ::std::execution::unseq;
58+
#endif
59+
60+
// [exec.queries], queries
61+
export using ::beman::execution::forwarding_query_t;
62+
export using ::beman::execution::get_allocator_t;
63+
export using ::beman::execution::get_stop_token_t;
64+
65+
export using ::beman::execution::forwarding_query;
66+
export using ::beman::execution::get_allocator;
67+
export using ::beman::execution::get_stop_token;
68+
69+
export using ::beman::execution::stop_token_of_t;
70+
71+
export using ::beman::execution::get_domain_t;
72+
export using ::beman::execution::get_scheduler_t;
73+
export using ::beman::execution::get_delegation_scheduler_t;
74+
//-dk:TODO export using ::beman::execution::get_forward_progress_guarantee_t;
75+
export using ::beman::execution::get_completion_scheduler_t;
76+
77+
export using ::beman::execution::get_domain;
78+
export using ::beman::execution::get_scheduler;
79+
export using ::beman::execution::get_delegation_scheduler;
80+
//-dk:TODO export using ::beman::execution::forward_progress_guarantee;
81+
//-dk:TODO export using ::beman::execution::get_forward_progress_guarantee;
82+
export using ::beman::execution::get_completion_scheduler;
83+
84+
export using ::beman::execution::empty_env;
85+
export using ::beman::execution::get_env_t;
86+
export using ::beman::execution::get_env;
87+
88+
export using ::beman::execution::env_of_t;
89+
90+
// [exec.domain.default], execution_domains
91+
export using ::beman::execution::default_domain;
92+
93+
// [exec.sched], schedulers
94+
export using ::beman::execution::scheduler_t;
95+
export using ::beman::execution::scheduler;
96+
97+
// [exec.recv], receivers
98+
export using ::beman::execution::receiver_t;
99+
export using ::beman::execution::receiver;
100+
export using ::beman::execution::receiver_of;
101+
102+
export using ::beman::execution::set_value_t;
103+
export using ::beman::execution::set_error_t;
104+
export using ::beman::execution::set_stopped_t;
105+
106+
export using ::beman::execution::set_value;
107+
export using ::beman::execution::set_error;
108+
export using ::beman::execution::set_stopped;
109+
110+
// [exec.opstate], operation states
111+
export using ::beman::execution::operation_state_t;
112+
export using ::beman::execution::operation_state;
113+
export using ::beman::execution::start_t;
114+
export using ::beman::execution::start;
115+
116+
// [exec.snd], senders
117+
export using ::beman::execution::sender_t;
118+
export using ::beman::execution::sender;
119+
export using ::beman::execution::sender_in;
120+
//-dk:TODO export using ::beman::execution::sender_to;
121+
122+
// [exec.getcomplsigs], completion signatures
123+
export using ::beman::execution::get_completion_signatures_t;
124+
export using ::beman::execution::get_completion_signatures;
125+
export using ::beman::execution::completion_signatures_of_t;
126+
export using ::beman::execution::value_types_of_t;
127+
export using ::beman::execution::error_types_of_t;
128+
export using ::beman::execution::sends_stopped;
129+
export using ::beman::execution::tag_of_t;
130+
131+
// [exec.snd.transform], sender transformations
132+
export using ::beman::execution::transform_sender;
133+
134+
// [exec.snd.transform.env], environment transformations
135+
//-dk:TODO export using ::beman::execution::transform_env;
136+
137+
// [exec.snd.apply], sender algorithm application
138+
export using ::beman::execution::apply_sender;
139+
140+
// [exec.connect], the connect sender algorithm
141+
export using ::beman::execution::connect_t;
142+
export using ::beman::execution::connect;
143+
export using ::beman::execution::connect_result_t;
144+
145+
// [exec.factories], sender factories
146+
export using ::beman::execution::just_t;
147+
export using ::beman::execution::just_error_t;
148+
export using ::beman::execution::just_stopped_t;
149+
export using ::beman::execution::schedule_t;
150+
151+
export using ::beman::execution::just;
152+
export using ::beman::execution::just_error;
153+
export using ::beman::execution::just_stopped;
154+
export using ::beman::execution::schedule;
155+
export using ::beman::execution::read_env;
156+
157+
export using ::beman::execution::schedule_result_t;
158+
159+
// [exec.adapt], sender adaptors
160+
export using ::beman::execution::sender_adaptor_closure;
161+
162+
export using ::beman::execution::starts_on_t;
163+
export using ::beman::execution::continues_on_t;
164+
//-dk:TODO export using ::beman::execution::on_t;
165+
export using ::beman::execution::schedule_from_t;
166+
export using ::beman::execution::then_t;
167+
export using ::beman::execution::upon_error_t;
168+
export using ::beman::execution::upon_stopped_t;
169+
export using ::beman::execution::let_value_t;
170+
export using ::beman::execution::let_error_t;
171+
export using ::beman::execution::let_stopped_t;
172+
//-dk:TODO export using ::beman::execution::bulk_t;
173+
//-dk:TODO export using ::beman::execution::split_t;
174+
export using ::beman::execution::when_all_t;
175+
export using ::beman::execution::when_all_with_variant_t;
176+
export using ::beman::execution::into_variant_t;
177+
//-dk:TODO export using ::beman::execution::stopped_as_optional_t;
178+
//-dk:TODO export using ::beman::execution::stopped_as_error_t;
179+
180+
export using ::beman::execution::starts_on;
181+
export using ::beman::execution::continues_on;
182+
//-dk:TODO export using ::beman::execution::on;
183+
export using ::beman::execution::schedule_from;
184+
export using ::beman::execution::then;
185+
export using ::beman::execution::upon_error;
186+
export using ::beman::execution::upon_stopped;
187+
export using ::beman::execution::let_value;
188+
export using ::beman::execution::let_error;
189+
export using ::beman::execution::let_stopped;
190+
//-dk:TODO export using ::beman::execution::bulk;
191+
//-dk:TODO export using ::beman::execution::split;
192+
export using ::beman::execution::when_all;
193+
export using ::beman::execution::when_all_with_variant;
194+
export using ::beman::execution::into_variant;
195+
//-dk:TODO export using ::beman::execution::stopped_as_optional;
196+
//-dk:TODO export using ::beman::execution::stopped_as_error;
197+
198+
// [exec.util.cmplsig]
199+
export using ::beman::execution::completion_signatures;
200+
201+
// [exec.util.cmplsig.trans]
202+
//-dk:TODO export using ::beman::execution::transform_completion_signatures;
203+
//-dk:TODO export using ::beman::execution::transform_completion_signatures_of;
204+
205+
// [exec.run.loop], run_loop
206+
export using ::beman::execution::run_loop;
207+
208+
// [exec.consumers], consumers
209+
export using ::beman::execution::sync_wait_t;
210+
//-dk:TODO export using ::beman::execution::sync_wait_with_variant_t;
211+
212+
export using ::beman::execution::sync_wait;
213+
//-dk:TODO export using ::beman::execution::sync_wait_with_variant;
214+
215+
// [exec.as.awaitable]
216+
//-dk:TODO export using ::beman::execution::as_awaitable_t;
217+
//-dk:TODO export using ::beman::execution::as_awaitable;
218+
219+
// [exec.with.awaitable.senders]
220+
//-dk:TODO export using ::beman::execution::with_awaitable_senders;
221+
222+
} // namespace beman::execution

tests/beman/execution/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
99
endif()
1010

1111
list(APPEND todo exec-associate.test)
12+
13+
if(BEMAN_USE_MODULES)
14+
list(
15+
APPEND execution_tests
16+
execution-module.test # execution-module.test.cpp
17+
stop-token-module.test # stop-token-module.test.cpp
18+
)
19+
endif()
20+
1221
list(
1322
APPEND execution_tests
1423
issue-174.test

0 commit comments

Comments
 (0)