xref: /aosp_15_r20/external/pigweed/pw_async2/BUILD.gn (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
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    "public/pw_async2/try.h",
37  ]
38  public_deps = [
39    "$dir_pw_string:to_string",
40    "$dir_pw_third_party/fuchsia:stdcompat",
41    dir_pw_polyfill,
42  ]
43}
44
45pw_test("poll_test") {
46  deps = [
47    ":poll",
48    "$dir_pw_result",
49  ]
50  sources = [ "poll_test.cc" ]
51}
52
53# NOTE: this target should only be used directly by implementors of the
54# `dispatcher` facade.
55pw_source_set("dispatcher_base") {
56  public_configs = [ ":public_include_path" ]
57  public_deps = [
58    ":poll",
59    "$dir_pw_assert",
60    "$dir_pw_chrono:system_clock",
61    "$dir_pw_sync:interrupt_spin_lock",
62    "$dir_pw_sync:lock_annotations",
63    "$dir_pw_sync:mutex",
64    "$dir_pw_toolchain:no_destructor",
65  ]
66  deps = [ "$dir_pw_assert:check" ]
67  public = [ "public/pw_async2/dispatcher_base.h" ]
68  sources = [ "dispatcher_base.cc" ]
69}
70
71pw_facade("dispatcher") {
72  backend = pw_async2_DISPATCHER_BACKEND
73  public_configs = [ ":public_include_path" ]
74  public = [ "public/pw_async2/dispatcher.h" ]
75  public_deps = [ ":dispatcher_base" ]
76}
77
78pw_test("dispatcher_test") {
79  enable_if = pw_async2_DISPATCHER_BACKEND != "" &&
80              pw_chrono_SYSTEM_CLOCK_BACKEND != "" &&
81              pw_sync_INTERRUPT_SPIN_LOCK_BACKEND != "" &&
82              pw_sync_TIMED_THREAD_NOTIFICATION_BACKEND != ""
83  deps = [
84    ":dispatcher",
85    "$dir_pw_containers:vector",
86  ]
87  sources = [ "dispatcher_test.cc" ]
88}
89
90pw_test("dispatcher_thread_test") {
91  enable_if = pw_async2_DISPATCHER_BACKEND != "" &&
92              pw_chrono_SYSTEM_CLOCK_BACKEND != "" &&
93              pw_sync_INTERRUPT_SPIN_LOCK_BACKEND != "" &&
94              pw_thread_THREAD_BACKEND == "$dir_pw_thread_stl:thread"
95  deps = [
96    ":dispatcher",
97    "$dir_pw_thread:sleep",
98    "$dir_pw_thread:thread",
99    "$dir_pw_thread_stl:thread",
100    dir_pw_function,
101  ]
102  sources = [ "dispatcher_thread_test.cc" ]
103}
104
105pw_source_set("pend_func_task") {
106  public_configs = [ ":public_include_path" ]
107  public = [ "public/pw_async2/pend_func_task.h" ]
108  public_deps = [
109    ":dispatcher",
110    dir_pw_function,
111  ]
112}
113
114pw_test("pend_func_task_test") {
115  enable_if = pw_async2_DISPATCHER_BACKEND != ""
116  deps = [
117    ":dispatcher",
118    ":pend_func_task",
119  ]
120  sources = [ "pend_func_task_test.cc" ]
121}
122
123pw_source_set("pendable_as_task") {
124  public_configs = [ ":public_include_path" ]
125  public = [ "public/pw_async2/pendable_as_task.h" ]
126  public_deps = [ ":dispatcher" ]
127}
128
129pw_test("pendable_as_task_test") {
130  enable_if = pw_async2_DISPATCHER_BACKEND != ""
131  deps = [
132    ":dispatcher",
133    ":pendable_as_task",
134  ]
135  sources = [ "pendable_as_task_test.cc" ]
136}
137
138pw_source_set("allocate_task") {
139  public_configs = [ ":public_include_path" ]
140  public = [ "public/pw_async2/allocate_task.h" ]
141  public_deps = [
142    ":dispatcher",
143    "$dir_pw_allocator:allocator",
144  ]
145}
146
147pw_test("allocate_task_test") {
148  enable_if = pw_async2_DISPATCHER_BACKEND != ""
149  deps = [
150    ":allocate_task",
151    "$dir_pw_allocator:testing",
152  ]
153  sources = [ "allocate_task_test.cc" ]
154}
155
156pw_source_set("once_sender") {
157  public_configs = [ ":public_include_path" ]
158  public = [ "public/pw_async2/once_sender.h" ]
159  public_deps = [
160    ":dispatcher",
161    "$dir_pw_function",
162  ]
163}
164
165pw_test("once_sender_test") {
166  enable_if = pw_async2_DISPATCHER_BACKEND != ""
167  deps = [
168    ":once_sender",
169    "$dir_pw_containers:vector",
170  ]
171  sources = [ "once_sender_test.cc" ]
172}
173
174if (pw_toolchain_CXX_STANDARD >= pw_toolchain_STANDARD.CXX20) {
175  pw_source_set("coro") {
176    public_configs = [ ":public_include_path" ]
177    public = [ "public/pw_async2/coro.h" ]
178    public_deps = [
179      ":dispatcher",
180      "$dir_pw_allocator:allocator",
181      dir_pw_function,
182    ]
183    deps = [ dir_pw_log ]
184    sources = [ "coro.cc" ]
185  }
186
187  pw_test("coro_test") {
188    enable_if = pw_async2_DISPATCHER_BACKEND != ""
189    deps = [
190      ":coro",
191      ":dispatcher",
192      "$dir_pw_allocator:null_allocator",
193      "$dir_pw_allocator:testing",
194    ]
195    sources = [ "coro_test.cc" ]
196  }
197
198  pw_source_set("coro_or_else_task") {
199    public_configs = [ ":public_include_path" ]
200    public = [ "public/pw_async2/coro_or_else_task.h" ]
201    public_deps = [
202      ":coro",
203      ":dispatcher",
204      "//pw_function",
205    ]
206  }
207
208  pw_test("coro_or_else_task_test") {
209    enable_if = pw_async2_DISPATCHER_BACKEND != ""
210    sources = [ "coro_or_else_task_test.cc" ]
211    deps = [
212      ":coro",
213      ":coro_or_else_task",
214      ":dispatcher",
215      "//pw_allocator:null_allocator",
216      "//pw_allocator:testing",
217    ]
218  }
219}
220
221pw_source_set("time_provider") {
222  public = [ "public/pw_async2/time_provider.h" ]
223  sources = [ "time_provider.cc" ]
224  public_configs = [ ":public_include_path" ]
225  public_deps = [
226    ":dispatcher",
227    "$dir_pw_containers:intrusive_list",
228    "$dir_pw_sync:interrupt_spin_lock",
229    "$dir_pw_toolchain:no_destructor",
230  ]
231}
232
233pw_source_set("system_time_provider") {
234  public = [ "public/pw_async2/system_time_provider.h" ]
235  public_configs = [ ":public_include_path" ]
236  public_deps = [
237    ":time_provider",
238    "$dir_pw_chrono:system_clock",
239  ]
240  sources = [ "system_time_provider.cc" ]
241  deps = [
242    "$dir_pw_chrono:system_timer",
243    "$dir_pw_toolchain:no_destructor",
244  ]
245}
246
247pw_test("system_time_provider_test") {
248  enable_if =
249      pw_async2_DISPATCHER_BACKEND != "" &&
250      pw_chrono_SYSTEM_CLOCK_BACKEND != "" &&
251      pw_sync_INTERRUPT_SPIN_LOCK_BACKEND != "" && pw_thread_YIELD_BACKEND != ""
252  sources = [ "system_time_provider_test.cc" ]
253  deps = [ ":system_time_provider" ]
254}
255
256pw_source_set("simulated_time_provider") {
257  public = [ "public/pw_async2/simulated_time_provider.h" ]
258  public_configs = [ ":public_include_path" ]
259  public_deps = [
260    ":time_provider",
261    "$dir_pw_sync:interrupt_spin_lock",
262  ]
263}
264
265pw_test("simulated_time_provider_test") {
266  enable_if =
267      pw_async2_DISPATCHER_BACKEND != "" &&
268      pw_chrono_SYSTEM_CLOCK_BACKEND != "" &&
269      pw_sync_INTERRUPT_SPIN_LOCK_BACKEND != "" && pw_thread_YIELD_BACKEND != ""
270  sources = [ "simulated_time_provider_test.cc" ]
271  deps = [
272    ":simulated_time_provider",
273    "$dir_pw_chrono:system_clock",
274  ]
275}
276
277pw_source_set("enqueue_heap_func") {
278  public = [ "public/pw_async2/enqueue_heap_func.h" ]
279  public_configs = [ ":public_include_path" ]
280  public_deps = [ ":dispatcher" ]
281}
282
283pw_test("enqueue_heap_func_test") {
284  enable_if = pw_async2_DISPATCHER_BACKEND != ""
285  sources = [ "enqueue_heap_func_test.cc" ]
286  deps = [
287    ":dispatcher",
288    ":enqueue_heap_func",
289  ]
290}
291
292pw_source_set("join") {
293  public = [ "public/pw_async2/join.h" ]
294  public_configs = [ ":public_include_path" ]
295  public_deps = [ ":dispatcher" ]
296}
297
298pw_test("join_test") {
299  enable_if = pw_async2_DISPATCHER_BACKEND != ""
300  sources = [ "join_test.cc" ]
301  deps = [
302    ":dispatcher",
303    ":join",
304  ]
305}
306
307pw_test_group("tests") {
308  tests = [
309    ":allocate_task_test",
310    ":dispatcher_test",
311    ":dispatcher_thread_test",
312    ":enqueue_heap_func_test",
313    ":join_test",
314    ":poll_test",
315    ":pend_func_task_test",
316    ":pendable_as_task_test",
317    ":once_sender_test",
318    ":simulated_time_provider_test",
319    ":system_time_provider_test",
320  ]
321  if (pw_toolchain_CXX_STANDARD >= pw_toolchain_STANDARD.CXX20) {
322    tests += [
323      ":coro_test",
324      ":coro_or_else_task_test",
325    ]
326  }
327  group_deps = [ "examples" ]
328}
329
330pw_doc_group("docs") {
331  inputs = [
332    "examples/basic.cc",
333    "examples/once_send_recv.cc",
334  ]
335  sources = [
336    "backends.rst",
337    "docs.rst",
338    "guides.rst",
339    "reference.rst",
340  ]
341}
342