xref: /aosp_15_r20/external/pigweed/pw_thread/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2020 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_build/facade.gni")
18import("$dir_pw_build/module_config.gni")
19import("$dir_pw_build/target_types.gni")
20import("$dir_pw_docgen/docs.gni")
21import("$dir_pw_protobuf_compiler/proto.gni")
22import("$dir_pw_unit_test/test.gni")
23import("backend.gni")
24
25declare_args() {
26  # The build target that overrides the default configuration options for this
27  # module. This should point to a source set that provides defines through a
28  # public config (which may -include a file or add defines directly).
29  pw_thread_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
30}
31
32config("public_include_path") {
33  include_dirs = [ "public" ]
34  visibility = [ ":*" ]
35}
36
37pw_source_set("config") {
38  public_deps = [ pw_thread_CONFIG ]
39  public = [ "public/pw_thread/config.h" ]
40  public_configs = [ ":public_include_path" ]
41  visibility = [ ":*" ]
42}
43
44pw_facade("id") {
45  backend = pw_thread_ID_BACKEND
46  public_configs = [ ":public_include_path" ]
47  public = [ "public/pw_thread/id.h" ]
48}
49
50pw_facade("sleep") {
51  backend = pw_thread_SLEEP_BACKEND
52  public_configs = [ ":public_include_path" ]
53  public = [ "public/pw_thread/sleep.h" ]
54  public_deps = [
55    "$dir_pw_chrono:system_clock",
56    "$dir_pw_preprocessor",
57  ]
58  sources = [ "sleep.cc" ]
59}
60
61pw_facade("thread") {
62  backend = pw_thread_THREAD_BACKEND
63  public_configs = [ ":public_include_path" ]
64  public = [
65    "public/pw_thread/detached_thread.h",
66    "public/pw_thread/thread.h",
67  ]
68  public_deps = [
69    ":id",
70    ":options",
71    ":thread_core",
72    dir_pw_function,
73  ]
74  sources = [ "thread.cc" ]
75}
76
77pw_source_set("options") {
78  public_configs = [ ":public_include_path" ]
79  public = [ "public/pw_thread/options.h" ]
80}
81
82pw_facade("test_thread_context") {
83  backend = pw_thread_TEST_THREAD_CONTEXT_BACKEND
84  public_configs = [ ":public_include_path" ]
85  public = [ "public/pw_thread/test_thread_context.h" ]
86}
87
88pw_source_set("thread_core") {
89  public_configs = [ ":public_include_path" ]
90  public = [ "public/pw_thread/thread_core.h" ]
91}
92
93pw_facade("thread_iteration") {
94  backend = pw_thread_THREAD_ITERATION_BACKEND
95  public_configs = [ ":public_include_path" ]
96  public = [ "public/pw_thread/thread_iteration.h" ]
97  public_deps = [
98    ":thread_info",
99    "$dir_pw_function",
100    "$dir_pw_status",
101  ]
102}
103
104pw_facade("yield") {
105  backend = pw_thread_YIELD_BACKEND
106  public_configs = [ ":public_include_path" ]
107  public = [ "public/pw_thread/yield.h" ]
108  public_deps = [ "$dir_pw_preprocessor" ]
109  sources = [ "yield.cc" ]
110}
111
112pw_source_set("snapshot") {
113  public_configs = [ ":public_include_path" ]
114  public_deps = [
115    "$dir_pw_thread:protos.pwpb",
116    dir_pw_bytes,
117    dir_pw_function,
118    dir_pw_protobuf,
119    dir_pw_status,
120  ]
121  public = [ "public/pw_thread/snapshot.h" ]
122  sources = [ "snapshot.cc" ]
123  deps = [
124    ":config",
125    dir_pw_log,
126  ]
127}
128
129pw_source_set("thread_info") {
130  public_configs = [ ":public_include_path" ]
131  public_deps = [ dir_pw_span ]
132  public = [ "public/pw_thread/thread_info.h" ]
133  deps = [ ":config" ]
134}
135
136pw_source_set("thread_snapshot_service") {
137  public_configs = [ ":public_include_path" ]
138  public = [ "public/pw_thread/thread_snapshot_service.h" ]
139  public_deps = [
140    ":protos.pwpb",
141    ":protos.raw_rpc",
142    ":thread_info",
143    "$dir_pw_rpc/raw:server_api",
144    "$dir_pw_status:pw_status",
145  ]
146  sources = [
147    "pw_thread_private/thread_snapshot_service.h",
148    "thread_snapshot_service.cc",
149  ]
150  deps = [
151    ":config",
152    ":thread_iteration",
153    "$dir_pw_log",
154    "$dir_pw_protobuf",
155    "$dir_pw_rpc/raw:server_api",
156    "$dir_pw_span",
157    "$dir_pw_status:pw_status",
158  ]
159}
160
161pw_test_group("tests") {
162  tests = [
163    ":id_facade_test",
164    ":sleep_facade_test",
165    ":thread_info_test",
166    ":yield_facade_test",
167    ":test_thread_context_facade_test",
168    ":thread_snapshot_service_test",
169    ":options_test",
170  ]
171}
172
173pw_test("test_thread_context_facade_test") {
174  # TODO: b/317922402 - On Windows, this test can easily hang indefinitely.
175  # Disable on Windows until we can test with the native Windows SDK libraries
176  # for threading.
177  enable_if = pw_thread_TEST_THREAD_CONTEXT_BACKEND != "" && current_os != "win"
178  sources = [ "test_thread_context_facade_test.cc" ]
179  deps = [
180    ":test_thread_context",
181    ":thread",
182    "$dir_pw_sync:binary_semaphore",
183  ]
184}
185
186pw_test("id_facade_test") {
187  enable_if = pw_thread_ID_BACKEND != ""
188  sources = [ "id_facade_test.cc" ]
189  deps = [ ":thread" ]
190}
191
192pw_test("thread_snapshot_service_test") {
193  enable_if = pw_thread_THREAD_ITERATION_BACKEND != ""
194  sources = [
195    "pw_thread_private/thread_snapshot_service.h",
196    "thread_snapshot_service_test.cc",
197  ]
198  deps = [
199    ":protos.pwpb",
200    ":thread_iteration",
201    "$dir_pw_protobuf",
202    "$dir_pw_span",
203    "$dir_pw_sync:thread_notification",
204    "$dir_pw_thread:thread_info",
205    "$dir_pw_thread:thread_snapshot_service",
206  ]
207}
208
209pw_test("sleep_facade_test") {
210  enable_if = pw_thread_SLEEP_BACKEND != "" && pw_thread_ID_BACKEND != ""
211  sources = [
212    "sleep_facade_test.cc",
213    "sleep_facade_test_c.c",
214  ]
215  deps = [
216    ":sleep",
217    ":thread",
218    "$dir_pw_chrono:system_clock",
219  ]
220}
221
222pw_source_set("non_portable_test_thread_options") {
223  public_configs = [ ":public_include_path" ]
224  public = [ "public/pw_thread/non_portable_test_thread_options.h" ]
225  public_deps = [ ":thread" ]
226}
227
228# To instantiate this facade test based on a selected backend to provide
229# test_threads you can create a pw_test target which depends on this
230# pw_source_set and a pw_source_set which provides the implementation of
231# test_threads. See "$dir_pw_thread_stl:thread_backend_test" as an example.
232pw_source_set("thread_facade_test") {
233  testonly = pw_unit_test_TESTONLY
234  sources = [ "thread_facade_test.cc" ]
235  deps = [
236    ":non_portable_test_thread_options",
237    ":sleep",
238    ":thread",
239    "$dir_pw_sync:binary_semaphore",
240    dir_pw_unit_test,
241  ]
242}
243
244pw_test("options_test") {
245  sources = [ "options_test.cc" ]
246  deps = [ ":options" ]
247  negative_compilation_tests = true
248}
249
250pw_test("thread_info_test") {
251  sources = [ "thread_info_test.cc" ]
252  deps = [
253    ":thread_info",
254    dir_pw_span,
255  ]
256}
257
258pw_test("yield_facade_test") {
259  enable_if = pw_thread_YIELD_BACKEND != "" && pw_thread_ID_BACKEND != ""
260  sources = [
261    "yield_facade_test.cc",
262    "yield_facade_test_c.c",
263  ]
264  deps = [
265    ":thread",
266    ":yield",
267  ]
268}
269
270pw_proto_library("protos") {
271  sources = [
272    "pw_thread_protos/thread.proto",
273    "pw_thread_protos/thread_snapshot_service.proto",
274  ]
275  deps = [ "$dir_pw_tokenizer:proto" ]
276}
277
278pw_doc_group("docs") {
279  inputs =
280      [ "$dir_pw_thread_stl/public/pw_thread_stl/test_thread_context_native.h" ]
281  sources = [
282    "backends.rst",
283    "docs.rst",
284  ]
285}
286