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