xref: /aosp_15_r20/external/pigweed/pw_async2/BUILD.bazel (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2023 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://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, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
16load(
17    "//pw_build:compatibility.bzl",
18    "incompatible_with_mcu",
19    "minimum_cxx_20",
20)
21load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
22
23package(default_visibility = ["//visibility:public"])
24
25licenses(["notice"])
26
27cc_library(
28    name = "poll",
29    hdrs = [
30        "public/pw_async2/internal/poll_internal.h",
31        "public/pw_async2/poll.h",
32        "public/pw_async2/try.h",
33    ],
34    strip_include_prefix = "public",
35    deps = [
36        "//pw_polyfill",
37        "//pw_string:to_string",
38        "//third_party/fuchsia:stdcompat",
39    ],
40)
41
42pw_cc_test(
43    name = "poll_test",
44    srcs = ["poll_test.cc"],
45    deps = [
46        ":poll",
47        "//pw_result",
48    ],
49)
50
51# NOTE: this target should only be used directly by implementors of the
52# `dispatcher` facade.
53cc_library(
54    name = "dispatcher_base",
55    srcs = [
56        "dispatcher_base.cc",
57    ],
58    hdrs = [
59        "public/pw_async2/dispatcher_base.h",
60    ],
61    strip_include_prefix = "public",
62    deps = [
63        ":poll",
64        "//pw_assert",
65        "//pw_chrono:system_clock",
66        "//pw_containers:vector",
67        "//pw_sync:interrupt_spin_lock",
68        "//pw_sync:lock_annotations",
69        "//pw_sync:mutex",
70        "//pw_toolchain:no_destructor",
71    ],
72)
73
74cc_library(
75    name = "dispatcher",
76    hdrs = [
77        "public/pw_async2/dispatcher.h",
78    ],
79    strip_include_prefix = "public",
80    deps = [
81        ":dispatcher_backend",
82        ":dispatcher_base",
83    ],
84)
85
86label_flag(
87    name = "dispatcher_backend",
88    build_setting_default = ":dispatcher_backend_multiplexer",
89)
90
91cc_library(
92    name = "dispatcher_backend_multiplexer",
93    visibility = ["//targets:__pkg__"],
94    deps = select({
95        "@platforms//os:linux": ["//pw_async2_epoll:dispatcher"],
96        "//conditions:default": ["//pw_async2_basic:dispatcher"],
97    }),
98)
99
100pw_cc_test(
101    name = "dispatcher_test",
102    srcs = ["dispatcher_test.cc"],
103    deps = [":dispatcher"],
104)
105
106pw_cc_test(
107    name = "dispatcher_thread_test",
108    srcs = ["dispatcher_thread_test.cc"],
109    # TODO: b/343776738 - update to run on all compatible devices
110    target_compatible_with = incompatible_with_mcu(),
111    deps = [
112        ":dispatcher",
113        "//pw_function",
114        "//pw_thread:sleep",
115        "//pw_thread:thread",
116    ],
117)
118
119cc_library(
120    name = "pend_func_task",
121    hdrs = [
122        "public/pw_async2/pend_func_task.h",
123    ],
124    strip_include_prefix = "public",
125    deps = [
126        ":dispatcher",
127        "//pw_function",
128    ],
129)
130
131pw_cc_test(
132    name = "pend_func_task_test",
133    srcs = ["pend_func_task_test.cc"],
134    deps = [":pend_func_task"],
135)
136
137cc_library(
138    name = "pendable_as_task",
139    hdrs = [
140        "public/pw_async2/pendable_as_task.h",
141    ],
142    strip_include_prefix = "public",
143    deps = [
144        ":dispatcher",
145    ],
146)
147
148pw_cc_test(
149    name = "pendable_as_task_test",
150    srcs = ["pendable_as_task_test.cc"],
151    deps = [":pendable_as_task"],
152)
153
154cc_library(
155    name = "allocate_task",
156    hdrs = [
157        "public/pw_async2/allocate_task.h",
158    ],
159    strip_include_prefix = "public",
160    deps = [
161        ":dispatcher",
162        "//pw_allocator:allocator",
163    ],
164)
165
166pw_cc_test(
167    name = "allocate_task_test",
168    srcs = ["allocate_task_test.cc"],
169    deps = [
170        ":allocate_task",
171        "//pw_allocator:testing",
172    ],
173)
174
175cc_library(
176    name = "once_sender",
177    hdrs = [
178        "public/pw_async2/once_sender.h",
179    ],
180    strip_include_prefix = "public",
181    deps = [
182        ":dispatcher",
183        "//pw_function",
184    ],
185)
186
187pw_cc_test(
188    name = "once_sender_test",
189    srcs = [
190        "once_sender_test.cc",
191    ],
192    deps = [
193        ":once_sender",
194        "//pw_containers:vector",
195    ],
196)
197
198cc_library(
199    name = "coro",
200    srcs = [
201        "coro.cc",
202    ],
203    hdrs = [
204        "public/pw_async2/coro.h",
205    ],
206    implementation_deps = [
207        "//pw_log",
208    ],
209    strip_include_prefix = "public",
210    target_compatible_with = minimum_cxx_20(),
211    deps = [
212        ":dispatcher",
213        "//pw_allocator:allocator",
214        "//pw_function",
215    ],
216)
217
218pw_cc_test(
219    name = "coro_test",
220    srcs = ["coro_test.cc"],
221    deps = [
222        ":coro",
223        ":dispatcher",
224        "//pw_allocator:null_allocator",
225        "//pw_allocator:testing",
226    ],
227)
228
229cc_library(
230    name = "coro_or_else_task",
231    hdrs = [
232        "public/pw_async2/coro_or_else_task.h",
233    ],
234    strip_include_prefix = "public",
235    deps = [
236        ":coro",
237        ":dispatcher",
238        "//pw_function",
239    ],
240)
241
242pw_cc_test(
243    name = "coro_or_else_task_test",
244    srcs = ["coro_or_else_task_test.cc"],
245    deps = [
246        ":coro",
247        ":coro_or_else_task",
248        ":dispatcher",
249        "//pw_allocator:null_allocator",
250        "//pw_allocator:testing",
251    ],
252)
253
254cc_library(
255    name = "time_provider",
256    srcs = [
257        "time_provider.cc",
258    ],
259    hdrs = [
260        "public/pw_async2/time_provider.h",
261    ],
262    strip_include_prefix = "public",
263    deps = [
264        ":dispatcher",
265        "//pw_chrono:virtual_clock",
266        "//pw_containers:intrusive_list",
267        "//pw_sync:interrupt_spin_lock",
268        "//pw_toolchain:no_destructor",
269    ],
270)
271
272cc_library(
273    name = "system_time_provider",
274    srcs = [
275        "system_time_provider.cc",
276    ],
277    hdrs = [
278        "public/pw_async2/system_time_provider.h",
279    ],
280    implementation_deps = [
281        "//pw_chrono:system_timer",
282        "//pw_toolchain:no_destructor",
283    ],
284    strip_include_prefix = "public",
285    deps = [
286        ":time_provider",
287        "//pw_chrono:system_clock",
288    ],
289)
290
291pw_cc_test(
292    name = "system_time_provider_test",
293    srcs = [
294        "system_time_provider_test.cc",
295    ],
296    deps = [
297        ":system_time_provider",
298        "//pw_unit_test",
299    ],
300)
301
302cc_library(
303    name = "simulated_time_provider",
304    hdrs = [
305        "public/pw_async2/simulated_time_provider.h",
306    ],
307    strip_include_prefix = "public",
308    deps = [
309        ":time_provider",
310        "//pw_sync:interrupt_spin_lock",
311    ],
312)
313
314pw_cc_test(
315    name = "simulated_time_provider_test",
316    srcs = [
317        "simulated_time_provider_test.cc",
318    ],
319    deps = [
320        ":simulated_time_provider",
321        "//pw_chrono:system_clock",
322        "//pw_unit_test",
323    ],
324)
325
326cc_library(
327    name = "enqueue_heap_func",
328    hdrs = [
329        "public/pw_async2/enqueue_heap_func.h",
330    ],
331    strip_include_prefix = "public",
332    deps = [
333        ":dispatcher",
334    ],
335)
336
337pw_cc_test(
338    name = "enqueue_heap_func_test",
339    srcs = [
340        "enqueue_heap_func_test.cc",
341    ],
342    deps = [
343        ":dispatcher",
344        ":enqueue_heap_func",
345        "//pw_unit_test",
346    ],
347)
348
349cc_library(
350    name = "join",
351    hdrs = [
352        "public/pw_async2/join.h",
353    ],
354    strip_include_prefix = "public",
355    deps = [
356        ":dispatcher",
357    ],
358)
359
360pw_cc_test(
361    name = "join_test",
362    srcs = [
363        "join_test.cc",
364    ],
365    deps = [
366        ":dispatcher",
367        ":join",
368    ],
369)
370
371sphinx_docs_library(
372    name = "docs",
373    srcs = [
374        "backends.rst",
375        "docs.rst",
376    ],
377    prefix = "pw_async2/",
378    target_compatible_with = incompatible_with_mcu(),
379    deps = [
380        "//pw_async2/examples:docs",
381    ],
382)
383
384filegroup(
385    name = "doxygen",
386    srcs = [
387        "public/pw_async2/allocate_task.h",
388        "public/pw_async2/coro.h",
389        "public/pw_async2/coro_or_else_task.h",
390        "public/pw_async2/dispatcher.h",
391        "public/pw_async2/dispatcher_base.h",
392        "public/pw_async2/enqueue_heap_func.h",
393        "public/pw_async2/join.h",
394        "public/pw_async2/once_sender.h",
395        "public/pw_async2/pend_func_task.h",
396        "public/pw_async2/pendable_as_task.h",
397        "public/pw_async2/poll.h",
398        "public/pw_async2/simulated_time_provider.h",
399        "public/pw_async2/system_time_provider.h",
400        "public/pw_async2/time_provider.h",
401    ],
402)
403