xref: /aosp_15_r20/external/pigweed/pw_thread_stl/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/error.gni")
18import("$dir_pw_build/target_types.gni")
19import("$dir_pw_chrono/backend.gni")
20import("$dir_pw_docgen/docs.gni")
21import("$dir_pw_thread/backend.gni")
22import("$dir_pw_unit_test/test.gni")
23
24config("public_include_path") {
25  include_dirs = [ "public" ]
26  visibility = [ ":*" ]
27}
28
29config("id_public_overrides") {
30  include_dirs = [ "id_public_overrides" ]
31  visibility = [ ":*" ]
32}
33
34# This target provides the backend for pw::Thread::id & pw::this_thread::get_id.
35pw_source_set("id") {
36  public_configs = [
37    ":public_include_path",
38    ":id_public_overrides",
39  ]
40  public = [
41    "id_public_overrides/pw_thread_backend/id_inline.h",
42    "id_public_overrides/pw_thread_backend/id_native.h",
43    "public/pw_thread_stl/id_inline.h",
44    "public/pw_thread_stl/id_native.h",
45  ]
46  deps = [ "$dir_pw_thread:id.facade" ]
47}
48
49config("thread_public_overrides") {
50  include_dirs = [ "thread_public_overrides" ]
51  visibility = [ ":*" ]
52}
53
54# This target provides the backend for pw::Thread with joining capability.
55pw_source_set("thread") {
56  public_configs = [
57    ":public_include_path",
58    ":thread_public_overrides",
59  ]
60  public = [
61    "public/pw_thread_stl/options.h",
62    "public/pw_thread_stl/thread_inline.h",
63    "public/pw_thread_stl/thread_native.h",
64    "thread_public_overrides/pw_thread_backend/thread_inline.h",
65    "thread_public_overrides/pw_thread_backend/thread_native.h",
66  ]
67  allow_circular_includes_from = [ "$dir_pw_thread:thread.facade" ]
68  deps = [ "$dir_pw_thread:thread.facade" ]
69}
70
71pw_build_assert("check_system_clock_backend") {
72  condition =
73      pw_thread_SLEEP_BACKEND != "$dir_pw_thread_stl:sleep" ||
74      pw_chrono_SYSTEM_CLOCK_BACKEND == "" ||
75      pw_chrono_SYSTEM_CLOCK_BACKEND == "$dir_pw_chrono_stl:system_clock"
76  message = "The STL pw::this_thread::sleep_{for,until} backend only works " +
77            "with the STL pw::chrono::SystemClock backend " +
78            "(pw_chrono_SYSTEM_CLOCK_BACKEND = " +
79            "\"$dir_pw_chrono_stl:system_clock\")"
80}
81
82config("sleep_public_overrides") {
83  include_dirs = [ "sleep_public_overrides" ]
84  visibility = [ ":*" ]
85}
86
87# This target provides the backend for pw::this_thread::sleep_{for,until}.
88pw_source_set("sleep") {
89  public_configs = [
90    ":public_include_path",
91    ":sleep_public_overrides",
92  ]
93  public = [
94    "public/pw_thread_stl/sleep_inline.h",
95    "sleep_public_overrides/pw_thread_backend/sleep_inline.h",
96  ]
97  deps = [
98    ":check_system_clock_backend",
99    "$dir_pw_chrono:system_clock",
100    "$dir_pw_thread:sleep.facade",
101  ]
102}
103
104config("yield_public_overrides") {
105  include_dirs = [ "yield_public_overrides" ]
106  visibility = [ ":*" ]
107}
108
109# This target provides the backend for pw::this_thread::yield.
110pw_source_set("yield") {
111  public_configs = [
112    ":public_include_path",
113    ":yield_public_overrides",
114  ]
115  public = [
116    "public/pw_thread_stl/yield_inline.h",
117    "yield_public_overrides/pw_thread_backend/yield_inline.h",
118  ]
119  deps = [ "$dir_pw_thread:yield.facade" ]
120}
121
122# This target provides a stub backend for pw::this_thread::thread_iteration.
123# Iterating over child threads isn't supported by STL, so this only exists
124# for portability reasons.
125pw_source_set("thread_iteration") {
126  deps = [
127    "$dir_pw_thread:thread_iteration.facade",
128    dir_pw_status,
129  ]
130  sources = [ "thread_iteration.cc" ]
131}
132
133pw_test_group("tests") {
134  tests = [ ":thread_backend_test" ]
135}
136
137config("test_thread_context_public_overrides") {
138  include_dirs = [ "test_thread_context_public_overrides" ]
139  visibility = [ ":*" ]
140}
141
142pw_source_set("test_thread_context") {
143  public_deps = [ ":thread" ]
144  public_configs = [
145    ":public_include_path",
146    ":test_thread_context_public_overrides",
147  ]
148  public = [
149    "public/pw_thread_stl/test_thread_context_native.h",
150    "test_thread_context_public_overrides/pw_thread_backend/test_thread_context_native.h",
151  ]
152  deps = [ "$dir_pw_thread:test_thread_context.facade" ]
153}
154
155pw_source_set("non_portable_test_thread_options") {
156  public_deps = [ "$dir_pw_thread:non_portable_test_thread_options" ]
157  sources = [ "test_threads.cc" ]
158  deps = [ "$dir_pw_thread:thread" ]
159}
160
161pw_test("thread_backend_test") {
162  # TODO: b/317922402 - On Windows, this test can hang indefinitely. Disable on
163  # Windows until we can test with the native Windows SDK libraries for
164  # threading.
165  enable_if = pw_thread_THREAD_BACKEND == "$dir_pw_thread_stl:thread" &&
166              pw_thread_SLEEP_BACKEND != "" && current_os != "win"
167  deps = [
168    ":non_portable_test_thread_options",
169    "$dir_pw_thread:thread_facade_test",
170  ]
171}
172
173pw_doc_group("docs") {
174  sources = [ "docs.rst" ]
175}
176