• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pw_async2/backend.gni")
18import("$dir_pw_build/facade.gni")
19import("$dir_pw_build/target_types.gni")
20import("$dir_pw_chrono/backend.gni")
21import("$dir_pw_docgen/docs.gni")
22import("$dir_pw_sync/backend.gni")
23import("$dir_pw_thread/backend.gni")
24import("$dir_pw_toolchain/traits.gni")
25import("$dir_pw_unit_test/test.gni")
26
27config("public_include_path") {
28  include_dirs = [ "public" ]
29}
30
31pw_source_set("poll") {
32  public_configs = [ ":public_include_path" ]
33  public = [
34    "public/pw_async2/internal/poll_internal.h",
35    "public/pw_async2/poll.h",
36  ]
37  public_deps = [
38    "$dir_pw_string:to_string",
39    "$dir_pw_third_party/fuchsia:stdcompat",
40    dir_pw_polyfill,
41  ]
42}
43
44pw_test("poll_test") {
45  deps = [
46    ":poll",
47    "$dir_pw_result",
48  ]
49  sources = [ "poll_test.cc" ]
50}
51
52# NOTE: this target should only be used directly by implementors of the
53# `dispatcher` facade.
54pw_source_set("dispatcher_base") {
55  public_configs = [ ":public_include_path" ]
56  public_deps = [
57    ":poll",
58    "$dir_pw_assert",
59    "$dir_pw_chrono:system_clock",
60    "$dir_pw_sync:interrupt_spin_lock",
61    "$dir_pw_sync:lock_annotations",
62    "$dir_pw_toolchain:no_destructor",
63  ]
64  deps = [ "$dir_pw_assert:check" ]
65  public = [ "public/pw_async2/dispatcher_base.h" ]
66  sources = [ "dispatcher_base.cc" ]
67}
68
69pw_facade("dispatcher") {
70  backend = pw_async2_DISPATCHER_BACKEND
71  public_configs = [ ":public_include_path" ]
72  public = [ "public/pw_async2/dispatcher.h" ]
73  public_deps = [ ":dispatcher_base" ]
74}
75
76pw_test("dispatcher_test") {
77  enable_if = pw_async2_DISPATCHER_BACKEND != "" &&
78              pw_chrono_SYSTEM_CLOCK_BACKEND != "" &&
79              pw_sync_INTERRUPT_SPIN_LOCK_BACKEND != "" &&
80              pw_sync_TIMED_THREAD_NOTIFICATION_BACKEND != ""
81  deps = [
82    ":dispatcher",
83    "$dir_pw_containers:vector",
84  ]
85  sources = [ "dispatcher_test.cc" ]
86}
87
88pw_test("dispatcher_thread_test") {
89  enable_if = pw_async2_DISPATCHER_BACKEND != "" &&
90              pw_chrono_SYSTEM_CLOCK_BACKEND != "" &&
91              pw_sync_INTERRUPT_SPIN_LOCK_BACKEND != "" &&
92              pw_thread_THREAD_BACKEND == "$dir_pw_thread_stl:thread"
93  deps = [
94    ":dispatcher",
95    "$dir_pw_thread:sleep",
96    "$dir_pw_thread:thread",
97    dir_pw_function,
98  ]
99  sources = [ "dispatcher_thread_test.cc" ]
100}
101
102pw_source_set("pend_func_task") {
103  public_configs = [ ":public_include_path" ]
104  public = [ "public/pw_async2/pend_func_task.h" ]
105  public_deps = [ ":dispatcher" ]
106}
107
108pw_test("pend_func_task_test") {
109  enable_if = pw_async2_DISPATCHER_BACKEND != ""
110  deps = [
111    ":dispatcher",
112    ":pend_func_task",
113  ]
114  sources = [ "pend_func_task_test.cc" ]
115}
116
117pw_source_set("pendable_as_task") {
118  public_configs = [ ":public_include_path" ]
119  public = [ "public/pw_async2/pendable_as_task.h" ]
120  public_deps = [ ":dispatcher" ]
121}
122
123pw_test("pendable_as_task_test") {
124  enable_if = pw_async2_DISPATCHER_BACKEND != ""
125  deps = [
126    ":dispatcher",
127    ":pendable_as_task",
128  ]
129  sources = [ "pendable_as_task_test.cc" ]
130}
131
132pw_source_set("allocate_task") {
133  public_configs = [ ":public_include_path" ]
134  public = [ "public/pw_async2/allocate_task.h" ]
135  public_deps = [
136    ":dispatcher",
137    "$dir_pw_allocator:allocator",
138  ]
139}
140
141pw_test("allocate_task_test") {
142  enable_if = pw_async2_DISPATCHER_BACKEND != ""
143  deps = [
144    ":allocate_task",
145    "$dir_pw_allocator:testing",
146  ]
147  sources = [ "allocate_task_test.cc" ]
148}
149
150if (pw_toolchain_CXX_STANDARD >= pw_toolchain_STANDARD.CXX20) {
151  pw_source_set("coro") {
152    public_configs = [ ":public_include_path" ]
153    public = [ "public/pw_async2/coro.h" ]
154    public_deps = [
155      ":dispatcher",
156      "$dir_pw_allocator:allocator",
157    ]
158  }
159
160  pw_test("coro_test") {
161    enable_if = pw_async2_DISPATCHER_BACKEND != ""
162    deps = [
163      ":coro",
164      ":dispatcher",
165      "$dir_pw_allocator:null_allocator",
166      "$dir_pw_allocator:testing",
167    ]
168    sources = [ "coro_test.cc" ]
169  }
170}
171
172pw_test_group("tests") {
173  tests = [
174    ":allocate_task_test",
175    ":dispatcher_test",
176    ":dispatcher_thread_test",
177    ":poll_test",
178    ":pend_func_task_test",
179    ":pendable_as_task_test",
180  ]
181  if (pw_toolchain_CXX_STANDARD >= pw_toolchain_STANDARD.CXX20) {
182    tests += [ ":coro_test" ]
183  }
184  group_deps = [ "examples" ]
185}
186
187pw_doc_group("docs") {
188  inputs = [ "examples/coro.cc" ]
189  sources = [
190    "backends.rst",
191    "docs.rst",
192  ]
193}
194