blob: 4a19945c75dd1008347c5ab95cb3715ee5a8c5d0 [file]
# Copyright 2025 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@sphinxdocs//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
load(
"//pw_build:compatibility.bzl",
"incompatible_with_mcu",
"minimum_cxx_20",
)
load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
package(
default_visibility = ["//visibility:public"],
)
licenses(["notice"])
# TODO: b/481069684 - Remove deprecated alias.
alias(
name = "poll",
actual = ":pw_async2",
)
pw_cc_test(
name = "poll_test",
srcs = ["poll_test.cc"],
deps = [
":pw_async2",
"//pw_result",
],
)
pw_cc_test(
name = "await_test",
srcs = ["await_test.cc"],
deps = [
":pw_async2",
":testing",
":value_future",
"//pw_result",
],
)
cc_library(
name = "pw_async2",
srcs = [
"dispatcher.cc",
"future.cc",
"runnable_dispatcher.cc",
"task.cc",
"waker.cc",
],
hdrs = [
"public/pw_async2/await.h",
"public/pw_async2/context.h",
"public/pw_async2/dispatcher.h",
"public/pw_async2/func_task.h",
"public/pw_async2/future.h",
"public/pw_async2/future_task.h",
"public/pw_async2/internal/poll_internal.h",
"public/pw_async2/poll.h",
"public/pw_async2/runnable_dispatcher.h",
"public/pw_async2/task.h",
"public/pw_async2/try.h",
"public/pw_async2/waker.h",
],
implementation_deps = [
":yield",
"//pw_assert:check",
"//pw_thread:sleep",
],
strip_include_prefix = "public",
deps = [
":config_override",
":internal",
"//pw_allocator",
"//pw_assert:assert",
"//pw_chrono:system_clock",
"//pw_containers:intrusive_forward_list",
"//pw_containers:intrusive_list",
"//pw_containers:intrusive_queue",
"//pw_containers:optional",
"//pw_function",
"//pw_log",
"//pw_log:args",
"//pw_memory",
"//pw_polyfill",
"//pw_preprocessor",
"//pw_string:to_string",
"//pw_sync:interrupt_spin_lock",
"//pw_sync:lock_annotations",
"//pw_tokenizer",
"//third_party/fuchsia:stdcompat",
],
)
cc_library(
name = "yield",
hdrs = ["private/pw_async2_private/yield.h"],
strip_include_prefix = "private",
visibility = ["//visibility:private"],
deps = [
":internal",
"//pw_chrono:system_clock",
"//pw_thread:sleep",
],
)
# TODO: b/481069684 - Remove deprecated alias.
alias(
name = "dispatcher",
actual = ":pw_async2",
)
cc_library(
name = "internal",
hdrs = [
"public/pw_async2/internal/config.h",
"public/pw_async2/internal/lock.h",
"public/pw_async2/internal/logging.h",
],
# LINT.IfChange
defines = select({
":debug_wait_reason_disabled": ["PW_ASYNC2_DEBUG_WAIT_REASON=0"],
":debug_wait_reason_enabled": ["PW_ASYNC2_DEBUG_WAIT_REASON=1"],
}),
# LINT.ThenChange(//pw_async2/public/pw_async2/internal/config.h)
strip_include_prefix = "public",
visibility = ["//visibility:private"],
deps = [
"//pw_memory:no_destructor",
"//pw_polyfill",
"//pw_sync:interrupt_spin_lock",
],
)
cc_library(
name = "basic_dispatcher",
hdrs = ["public/pw_async2/basic_dispatcher.h"],
strip_include_prefix = "public",
deps = [
":pw_async2",
"//pw_sync:thread_notification",
],
)
cc_library(
name = "notified_dispatcher",
hdrs = ["public/pw_async2/notified_dispatcher.h"],
strip_include_prefix = "public",
deps = [
":pw_async2",
"//pw_sync:thread_notification",
],
)
label_flag(
name = "config_override",
build_setting_default = "//pw_build:default_module_config",
)
constraint_setting(
name = "debug_wait_reason",
default_constraint_value = "debug_wait_reason_enabled",
)
constraint_value(
name = "debug_wait_reason_disabled",
constraint_setting = ":debug_wait_reason",
)
constraint_value(
name = "debug_wait_reason_enabled",
constraint_setting = ":debug_wait_reason",
)
cc_library(
name = "testing",
testonly = True,
srcs = ["dispatcher_for_test.cc"],
hdrs = [
"public/pw_async2/dispatcher_for_test.h",
],
implementation_deps = ["//pw_assert:check"],
strip_include_prefix = "public",
deps = [
":dispatcher_for_test_backend",
":pw_async2",
],
)
cc_library(
name = "channel_testing_internal",
testonly = True,
hdrs = [
"public/pw_async2/internal/channel_test_util.h",
],
strip_include_prefix = "public",
visibility = ["//visibility:private"],
deps = [
":channel",
":pw_async2",
"//pw_containers:vector",
],
)
cc_library(
name = "coro_testing_internal",
testonly = True,
hdrs = [
"public/pw_async2/internal/coro_test_util.h",
],
strip_include_prefix = "public",
visibility = ["//visibility:private"],
)
cc_library(
name = "epoll_dispatcher",
srcs = ["epoll_dispatcher.cc"],
hdrs = ["public/pw_async2/epoll_dispatcher.h"],
implementation_deps = [
"//pw_assert:check",
"//pw_log",
],
strip_include_prefix = "public",
target_compatible_with = ["@platforms//os:linux"],
deps = [
":pw_async2",
"//pw_assert:assert",
"//pw_status",
],
)
cc_library(
name = "epoll_dispatcher_for_test",
hdrs = [
"epoll_dispatcher_for_test_public_overrides/pw_async2_backend/native_dispatcher_for_test.h",
],
strip_include_prefix = "epoll_dispatcher_for_test_public_overrides",
deps = [":epoll_dispatcher"],
)
label_flag(
name = "dispatcher_for_test_backend",
build_setting_default = ":dispatcher_for_test_default_backend",
)
alias(
name = "dispatcher_for_test_default_backend",
actual = select({
"@platforms//os:linux": ":epoll_dispatcher_for_test",
"//conditions:default": ":basic_dispatcher_for_test",
}),
)
cc_library(
name = "basic_dispatcher_for_test",
hdrs = [
"dispatcher_for_test_public_overrides/pw_async2_backend/native_dispatcher_for_test.h",
],
strip_include_prefix = "dispatcher_for_test_public_overrides",
deps = [":basic_dispatcher"],
)
pw_cc_test(
name = "dispatcher_test",
srcs = ["dispatcher_test.cc"],
deps = [
":pw_async2",
":testing",
":value_future",
"//pw_containers:vector",
],
)
pw_cc_test(
name = "task_test",
srcs = ["task_test.cc"],
deps = [
":pw_async2",
":testing",
"//pw_sync:binary_semaphore",
"//pw_sync:mutex",
"//pw_thread:sleep",
"//pw_thread:test_thread_context",
"//pw_thread:thread",
],
)
pw_cc_test(
name = "dispatcher_thread_test",
srcs = ["dispatcher_thread_test.cc"],
deps = [
":pw_async2",
":testing",
"//pw_sync:thread_notification",
"//pw_thread:sleep",
"//pw_thread:test_thread_context",
"//pw_thread:thread",
],
)
pw_cc_test(
name = "dispatcher_stress_test",
srcs = ["dispatcher_stress_test.cc"],
deps = [
":notified_dispatcher",
":pw_async2",
"//pw_allocator:libc_allocator",
"//pw_assert:check",
"//pw_containers:dynamic_queue",
"//pw_containers:dynamic_vector",
"//pw_log",
"//pw_sync:lock_annotations",
"//pw_sync:mutex",
"//pw_sync:thread_notification",
"//pw_thread:test_thread_context",
"//pw_thread:thread",
"//pw_thread:yield",
],
)
pw_cc_test(
name = "future_test",
srcs = ["future_test.cc"],
has_nc_test = True,
deps = [
":pw_async2",
":select",
":testing",
],
)
pw_cc_test(
name = "future_task_test",
srcs = ["future_task_test.cc"],
deps = [
":pw_async2",
":testing",
":value_future",
],
)
cc_library(
name = "future_timeout",
hdrs = [
"public/pw_async2/future_timeout.h",
],
strip_include_prefix = "public",
deps = [
":channel",
":pw_async2",
":system_time_provider",
":time_provider",
":value_future",
"//pw_assert:assert",
"//pw_chrono:system_clock",
"//pw_function",
"//pw_preprocessor",
"//pw_status",
"//third_party/fuchsia:stdcompat",
],
)
pw_cc_test(
name = "future_timeout_test",
srcs = ["future_timeout_test.cc"],
has_nc_test = True,
deps = [
":channel",
":future_timeout",
":pw_async2",
":simulated_time_provider",
":testing",
":value_future",
"//pw_chrono:system_clock",
"//pw_function",
"//pw_result",
"//pw_status",
],
)
cc_library(
name = "value_future",
srcs = ["value_future.cc"],
hdrs = [
"public/pw_async2/value_future.h",
],
strip_include_prefix = "public",
deps = [
":pw_async2",
"//pw_assert:assert",
"//pw_assert:check",
"//pw_polyfill",
"//pw_sync:interrupt_spin_lock",
],
)
pw_cc_test(
name = "value_future_test",
srcs = ["value_future_test.cc"],
deps = [
":pw_async2",
":testing",
":value_future",
],
)
pw_cc_test(
name = "value_future_thread_test",
srcs = ["value_future_thread_test.cc"],
deps = [
":callback_task",
":pw_async2",
":testing",
":value_future",
"//pw_thread:sleep",
"//pw_thread:test_thread_context",
"//pw_thread:thread",
"//pw_thread:yield",
"//pw_unit_test",
],
)
# TODO: b/481069684 - Remove deprecated alias.
alias(
name = "func_task",
actual = ":pw_async2",
)
pw_cc_test(
name = "func_task_test",
srcs = ["func_task_test.cc"],
deps = [
":pw_async2",
":testing",
"//pw_function",
],
)
cc_library(
name = "callback_task",
hdrs = [
"public/pw_async2/callback_task.h",
],
strip_include_prefix = "public",
deps = [
":pw_async2",
"//pw_function",
],
)
pw_cc_test(
name = "callback_task_test",
srcs = ["callback_task_test.cc"],
deps = [
":callback_task",
":pw_async2",
":testing",
":value_future",
"//pw_function",
],
)
pw_cc_test(
name = "allocate_task_test",
srcs = ["allocate_task_test.cc"],
deps = [
":pw_async2",
":testing",
":value_future",
"//pw_allocator:testing",
"//pw_function",
"//pw_status",
],
)
pw_cc_test(
name = "allocate_task_coro_test",
srcs = ["allocate_task_coro_test.cc"],
target_compatible_with = minimum_cxx_20(),
deps = [
":coro",
":pw_async2",
":testing",
"//pw_allocator:testing",
],
)
cc_library(
name = "box",
hdrs = [
"public/pw_async2/box.h",
],
strip_include_prefix = "public",
deps = [
":pw_async2",
"//pw_allocator",
],
)
pw_cc_test(
name = "box_test",
srcs = ["box_test.cc"],
deps = [
":box",
":channel",
":pw_async2",
":select",
":testing",
":transform",
":value_future",
"//pw_allocator:testing",
],
)
cc_library(
name = "transform",
hdrs = [
"public/pw_async2/transform.h",
],
strip_include_prefix = "public",
deps = [
":pw_async2",
],
)
pw_cc_test(
name = "transform_test",
srcs = ["transform_test.cc"],
deps = [
":channel",
":poll",
":pw_async2",
":testing",
":transform",
":value_future",
],
)
cc_library(
name = "coro",
srcs = [
"coro.cc",
"coro_task.cc",
],
hdrs = [
"public/pw_async2/coro.h",
"public/pw_async2/coro_task.h",
"public/pw_async2/fallible_coro_task.h",
],
implementation_deps = [
"//pw_assert:check",
"//pw_bytes:alignment",
"//pw_log",
],
strip_include_prefix = "public",
target_compatible_with = minimum_cxx_20(),
deps = [
":internal",
":pw_async2",
"//pw_allocator",
"//pw_assert:assert",
"//pw_containers:optional",
"//pw_function",
],
)
cc_library(
name = "notification",
hdrs = [
"public/pw_async2/notification.h",
],
strip_include_prefix = "public",
deps = [
":value_future",
],
)
pw_cc_test(
name = "notification_test",
srcs = ["notification_test.cc"],
deps = [
":notification",
":pw_async2",
":testing",
],
)
pw_cc_test(
name = "coro_test",
srcs = ["coro_test.cc"],
has_nc_test = True,
deps = [
":coro",
":coro_testing_internal",
":pw_async2",
":testing",
":value_future",
"//pw_allocator:null_allocator",
"//pw_allocator:testing",
"//pw_containers:test_helpers",
"//pw_status",
],
)
cc_library(
name = "coro_or_else_task",
hdrs = ["public/pw_async2/coro_or_else_task.h"],
strip_include_prefix = "public",
deps = [
":coro",
"//pw_status",
],
)
pw_cc_test(
name = "coro_task_test",
srcs = ["coro_task_test.cc"],
deps = [
":coro",
":coro_testing_internal",
":pw_async2",
":testing",
"//pw_allocator:testing",
"//pw_status",
],
)
pw_cc_test(
name = "fallible_coro_task_test",
srcs = ["fallible_coro_task_test.cc"],
deps = [
":coro",
":coro_testing_internal",
":pw_async2",
":testing",
":value_future",
"//pw_allocator:null_allocator",
"//pw_allocator:testing",
"//pw_containers:test_helpers",
"//pw_status",
],
)
cc_library(
name = "time_provider",
srcs = [
"time_provider.cc",
],
hdrs = [
"public/pw_async2/time_provider.h",
],
implementation_deps = ["//pw_assert:check"],
strip_include_prefix = "public",
deps = [
":pw_async2",
"//pw_chrono:virtual_clock",
"//pw_containers:intrusive_list",
"//pw_memory:no_destructor",
"//pw_sync:interrupt_spin_lock",
"//pw_sync:lock_annotations",
],
)
cc_library(
name = "system_time_provider",
srcs = [
"system_time_provider.cc",
],
hdrs = [
"public/pw_async2/system_time_provider.h",
],
implementation_deps = [
"//pw_chrono:system_timer",
"//pw_memory:no_destructor",
],
strip_include_prefix = "public",
deps = [
":time_provider",
"//pw_chrono:system_clock",
],
)
pw_cc_test(
name = "system_time_provider_test",
srcs = [
"system_time_provider_test.cc",
],
deps = [
":system_time_provider",
":testing",
],
)
cc_library(
name = "simulated_time_provider",
hdrs = [
"public/pw_async2/simulated_time_provider.h",
],
strip_include_prefix = "public",
deps = [
":time_provider",
"//pw_sync:interrupt_spin_lock",
],
)
pw_cc_test(
name = "simulated_time_provider_test",
srcs = [
"simulated_time_provider_test.cc",
],
deps = [
":simulated_time_provider",
":testing",
"//pw_chrono:system_clock",
],
)
cc_library(
name = "cancellable_task",
hdrs = [
"public/pw_async2/cancellable_task.h",
],
strip_include_prefix = "public",
deps = [
":pw_async2",
],
)
pw_cc_test(
name = "cancellable_task_test",
srcs = [
"cancellable_task_test.cc",
],
deps = [
":cancellable_task",
":pw_async2",
":testing",
"//pw_function",
],
)
cc_library(
name = "join",
hdrs = [
"public/pw_async2/join.h",
],
strip_include_prefix = "public",
deps = [
":pw_async2",
],
)
pw_cc_test(
name = "join_test",
srcs = [
"join_test.cc",
],
has_nc_test = True,
deps = [
":join",
":pw_async2",
":testing",
":value_future",
],
)
cc_library(
name = "select",
hdrs = [
"public/pw_async2/select.h",
],
strip_include_prefix = "public",
deps = [
":pw_async2",
"//pw_containers:optional_tuple",
],
)
pw_cc_test(
name = "select_test",
srcs = [
"select_test.cc",
],
deps = [
":pw_async2",
":select",
":testing",
":value_future",
"//pw_unit_test:constexpr",
],
)
cc_library(
name = "channel",
srcs = ["channel.cc"],
hdrs = ["public/pw_async2/channel.h"],
implementation_deps = ["//pw_assert:check"],
strip_include_prefix = "public",
deps = [
":callback_task",
":pw_async2",
"//pw_allocator",
"//pw_containers:deque",
"//pw_numeric:checked_arithmetic",
"//pw_result",
"//pw_sync:interrupt_spin_lock",
"//pw_sync:lock_annotations",
"//pw_sync:timed_thread_notification",
"//third_party/fuchsia:stdcompat",
],
)
pw_cc_test(
name = "channel_test",
srcs = [
"channel_test.cc",
],
deps = [
":channel",
":channel_testing_internal",
":pw_async2",
":testing",
"//pw_allocator:testing",
"//pw_containers:vector",
"//pw_function",
],
)
pw_cc_test(
name = "channel_thread_test",
srcs = [
"channel_thread_test.cc",
],
deps = [
":channel",
":channel_testing_internal",
":pw_async2",
":testing",
"//pw_containers:vector",
"//pw_function",
"//pw_thread:test_thread_context",
"//pw_thread:thread",
],
)
pw_cc_test(
name = "channel_typed_test",
srcs = ["channel_typed_test.cc"],
target_compatible_with = select({
"//pw_unit_test:backend_is_googletest": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
deps = [
":channel",
":pw_async2",
":testing",
"//pw_allocator:testing",
"//pw_containers:vector",
],
)
pw_cc_test(
name = "channel_coro_test",
srcs = [
"channel_coro_test.cc",
],
deps = [
":channel",
":coro",
":pw_async2",
":testing",
"//pw_allocator:testing",
"//pw_containers:vector",
],
)
sphinx_docs_library(
name = "docs",
srcs = [
"channels.rst",
"code_size.rst",
"coroutines.rst",
"dispatcher.rst",
"docs.rst",
"futures.rst",
"guides.rst",
"informed_poll.rst",
"public/pw_async2/coro.h",
"quickstart.rst",
"tasks.rst",
"why.rst",
"//pw_async2/codelab:docs",
"//pw_async2/examples:channel.cc",
"//pw_async2/examples:custom_future.cc",
"//pw_async2/examples:docs",
"//pw_async2/examples:task_helpers.cc",
"//pw_async2/size_report:channel_size_report",
"//pw_async2/size_report:full_size_report",
"//pw_async2/size_report:utilities_size_report",
"//pw_async2/size_report:value_future_table",
],
prefix = "pw_async2/",
target_compatible_with = incompatible_with_mcu(),
)
filegroup(
name = "doxygen",
srcs = [
"public/pw_async2/await.h",
"public/pw_async2/basic_dispatcher.h",
"public/pw_async2/box.h",
"public/pw_async2/callback_task.h",
"public/pw_async2/cancellable_task.h",
"public/pw_async2/channel.h",
"public/pw_async2/context.h",
"public/pw_async2/coro.h",
"public/pw_async2/coro_or_else_task.h",
"public/pw_async2/coro_task.h",
"public/pw_async2/dispatcher.h",
"public/pw_async2/dispatcher_for_test.h",
"public/pw_async2/epoll_dispatcher.h",
"public/pw_async2/fallible_coro_task.h",
"public/pw_async2/func_task.h",
"public/pw_async2/future.h",
"public/pw_async2/future_task.h",
"public/pw_async2/future_timeout.h",
"public/pw_async2/internal/config.h",
"public/pw_async2/join.h",
"public/pw_async2/notification.h",
"public/pw_async2/notified_dispatcher.h",
"public/pw_async2/poll.h",
"public/pw_async2/runnable_dispatcher.h",
"public/pw_async2/select.h",
"public/pw_async2/simulated_time_provider.h",
"public/pw_async2/system_time_provider.h",
"public/pw_async2/task.h",
"public/pw_async2/time_provider.h",
"public/pw_async2/transform.h",
"public/pw_async2/try.h",
"public/pw_async2/value_future.h",
"public/pw_async2/waker.h",
],
)