xref: /aosp_15_r20/external/pigweed/pw_thread_stl/BUILD.bazel (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
15load("//pw_build:compatibility.bzl", "incompatible_with_mcu")
16load(
17    "//pw_build:selects.bzl",
18    "TARGET_COMPATIBLE_WITH_HOST_SELECT",
19)
20load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
21
22package(default_visibility = ["//visibility:public"])
23
24licenses(["notice"])
25
26cc_library(
27    name = "id",
28    hdrs = [
29        "id_public_overrides/pw_thread_backend/id_inline.h",
30        "id_public_overrides/pw_thread_backend/id_native.h",
31        "public/pw_thread_stl/id_inline.h",
32        "public/pw_thread_stl/id_native.h",
33    ],
34    includes = [
35        "id_public_overrides",
36        "public",
37    ],
38    target_compatible_with = incompatible_with_mcu(),
39    deps = [
40        "//pw_thread:id.facade",
41    ],
42)
43
44cc_library(
45    name = "sleep",
46    hdrs = [
47        "public/pw_thread_stl/sleep_inline.h",
48        "sleep_public_overrides/pw_thread_backend/sleep_inline.h",
49    ],
50    includes = [
51        "public",
52        "sleep_public_overrides",
53    ],
54    target_compatible_with = incompatible_with_mcu(),
55    deps = [
56        "//pw_chrono:system_clock",
57        "//pw_thread:sleep.facade",
58    ],
59)
60
61cc_library(
62    name = "thread",
63    hdrs = [
64        "public/pw_thread_stl/options.h",
65        "public/pw_thread_stl/thread_inline.h",
66        "public/pw_thread_stl/thread_native.h",
67        "thread_public_overrides/pw_thread_backend/thread_inline.h",
68        "thread_public_overrides/pw_thread_backend/thread_native.h",
69    ],
70    includes = [
71        "public",
72        "thread_public_overrides",
73    ],
74    target_compatible_with = incompatible_with_mcu(),
75    deps = [
76        "//pw_thread:thread.facade",
77    ],
78)
79
80# This target provides a stub backend for pw::this_thread::thread_iteration.
81# Iterating over child threads isn't supported by STL, so this only exists
82# for portability reasons.
83cc_library(
84    name = "thread_iteration",
85    srcs = ["thread_iteration.cc"],
86    deps = [
87        "//pw_status",
88        "//pw_thread:thread_iteration.facade",
89    ],
90)
91
92cc_library(
93    name = "non_portable_test_thread_options",
94    srcs = [
95        "test_threads.cc",
96    ],
97    target_compatible_with = incompatible_with_mcu(),
98    deps = [
99        "//pw_thread:non_portable_test_thread_options",
100        "//pw_thread:thread.facade",
101    ],
102)
103
104pw_cc_test(
105    name = "thread_backend_test",
106    # TODO: b/317922402 - On Windows, this test can easily hang indefinitely.
107    # Disable on Windows until we can test with the native Windows SDK libraries
108    # for threading.
109    target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT | {
110        "@platforms//os:windows": ["@platforms//:incompatible"],
111    }),
112    deps = [
113        ":non_portable_test_thread_options",
114        "//pw_thread:thread_facade_test",
115    ],
116)
117
118cc_library(
119    name = "yield",
120    hdrs = [
121        "public/pw_thread_stl/yield_inline.h",
122        "yield_public_overrides/pw_thread_backend/yield_inline.h",
123    ],
124    includes = [
125        "public",
126        "yield_public_overrides",
127    ],
128    target_compatible_with = incompatible_with_mcu(),
129    deps = [
130        "//pw_thread:yield.facade",
131    ],
132)
133
134cc_library(
135    name = "test_thread_context",
136    hdrs = [
137        "public/pw_thread_stl/test_thread_context_native.h",
138        "test_thread_context_public_overrides/pw_thread_backend/test_thread_context_native.h",
139    ],
140    includes = [
141        "public",
142        "test_thread_context_public_overrides",
143    ],
144    target_compatible_with = incompatible_with_mcu(),
145    deps = [
146        ":thread",
147        "//pw_thread:test_thread_context.facade",
148    ],
149)
150