xref: /aosp_15_r20/external/pigweed/pw_thread_freertos/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("@bazel_skylib//rules:run_binary.bzl", "run_binary")
16load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
17
18package(default_visibility = ["//visibility:public"])
19
20licenses(["notice"])
21
22cc_library(
23    name = "id",
24    hdrs = [
25        "id_public_overrides/pw_thread_backend/id_inline.h",
26        "id_public_overrides/pw_thread_backend/id_native.h",
27        "public/pw_thread_freertos/id_inline.h",
28        "public/pw_thread_freertos/id_native.h",
29    ],
30    includes = [
31        "id_public_overrides",
32        "public",
33    ],
34    target_compatible_with = [
35        "//pw_build/constraints/rtos:freertos",
36    ],
37    deps = [
38        "//pw_interrupt:context",
39        "//pw_thread:id.facade",
40        "@freertos",
41    ],
42)
43
44cc_library(
45    name = "sleep",
46    srcs = [
47        "sleep.cc",
48    ],
49    hdrs = [
50        "public/pw_thread_freertos/sleep_inline.h",
51        "sleep_public_overrides/pw_thread_backend/sleep_inline.h",
52    ],
53    includes = [
54        "public",
55        "sleep_public_overrides",
56    ],
57    target_compatible_with = [
58        "//pw_build/constraints/rtos:freertos",
59    ],
60    deps = [
61        "//pw_assert",
62        "//pw_chrono:system_clock",
63        "//pw_thread:sleep.facade",
64        "//pw_thread:thread",
65        "@freertos",
66    ],
67)
68
69cc_library(
70    name = "thread",
71    srcs = [
72        "thread.cc",
73    ],
74    hdrs = [
75        "public/pw_thread_freertos/config.h",
76        "public/pw_thread_freertos/context.h",
77        "public/pw_thread_freertos/options.h",
78        "public/pw_thread_freertos/thread_inline.h",
79        "public/pw_thread_freertos/thread_native.h",
80        "thread_public_overrides/pw_thread_backend/thread_inline.h",
81        "thread_public_overrides/pw_thread_backend/thread_native.h",
82    ],
83    includes = [
84        "public",
85        "thread_public_overrides",
86    ],
87    target_compatible_with = [
88        "//pw_build/constraints/rtos:freertos",
89    ],
90    deps = [
91        ":config_override",
92        ":id",
93        "//pw_assert",
94        "//pw_function",
95        "//pw_string",
96        "//pw_sync:binary_semaphore",
97        "//pw_thread:thread.facade",
98    ],
99)
100
101label_flag(
102    name = "config_override",
103    build_setting_default = "//pw_build:default_module_config",
104)
105
106cc_library(
107    name = "dynamic_test_threads",
108    srcs = [
109        "dynamic_test_threads.cc",
110    ],
111    target_compatible_with = [
112        "//pw_build/constraints/rtos:freertos",
113    ],
114    deps = [
115        "//pw_chrono:system_clock",
116        "//pw_thread:non_portable_test_thread_options",
117        "//pw_thread:sleep",
118        "//pw_thread:thread.facade",
119    ],
120    alwayslink = 1,
121)
122
123pw_cc_test(
124    name = "dynamic_thread_backend_test",
125    # TODO: https://pwbug.dev/271465588 - This test fails on-device.
126    tags = ["do_not_run_test"],
127    deps = [
128        ":dynamic_test_threads",
129        "//pw_thread:thread_facade_test",
130    ],
131)
132
133cc_library(
134    name = "static_test_threads",
135    srcs = [
136        "static_test_threads.cc",
137    ],
138    target_compatible_with = [
139        "//pw_build/constraints/rtos:freertos",
140    ],
141    deps = [
142        "//pw_chrono:system_clock",
143        "//pw_thread:non_portable_test_thread_options",
144        "//pw_thread:sleep",
145        "//pw_thread:thread.facade",
146    ],
147    alwayslink = 1,
148)
149
150pw_cc_test(
151    name = "static_thread_backend_test",
152    deps = [
153        ":static_test_threads",
154        "//pw_thread:thread_facade_test",
155    ],
156)
157
158cc_library(
159    name = "yield",
160    hdrs = [
161        "public/pw_thread_freertos/yield_inline.h",
162        "yield_public_overrides/pw_thread_backend/yield_inline.h",
163    ],
164    includes = [
165        "public",
166        "yield_public_overrides",
167    ],
168    deps = [
169        "//pw_thread:thread",
170        "//pw_thread:yield.facade",
171        "@freertos",
172    ],
173)
174
175cc_library(
176    name = "thread_iteration",
177    srcs = [
178        "pw_thread_freertos_private/thread_iteration.h",
179        "thread_iteration.cc",
180    ],
181    target_compatible_with = [
182        "//pw_build/constraints/rtos:freertos",
183    ],
184    deps = [
185        ":freertos_tasktcb",
186        "//pw_function",
187        "//pw_span",
188        "//pw_status",
189        "//pw_thread:thread_info",
190        "//pw_thread:thread_iteration.facade",
191        "//pw_thread_freertos:util",
192    ],
193)
194
195pw_cc_test(
196    name = "thread_iteration_test",
197    srcs = [
198        "pw_thread_freertos_private/thread_iteration.h",
199        "thread_iteration_test.cc",
200    ],
201    # TODO: https://pwbug.dev/271465588 - This test fails on-device.
202    tags = ["do_not_run_test"],
203    deps = [
204        ":freertos_tasktcb",
205        ":static_test_threads",
206        ":thread_iteration",
207        "//pw_bytes",
208        "//pw_span",
209        "//pw_string:builder",
210        "//pw_string:util",
211        "//pw_sync:thread_notification",
212        "//pw_thread:non_portable_test_thread_options",
213        "//pw_thread:thread",
214        "//pw_thread:thread_info",
215        "//pw_thread:thread_iteration",
216    ],
217)
218
219cc_library(
220    name = "util",
221    srcs = [
222        "util.cc",
223    ],
224    hdrs = [
225        "public/pw_thread_freertos/util.h",
226    ],
227    strip_include_prefix = "public",
228    target_compatible_with = [
229        "//pw_build/constraints/rtos:freertos",
230    ],
231    deps = [
232        "//pw_function",
233        "//pw_log",
234        "//pw_span",
235        "//pw_status",
236        "@freertos",
237    ],
238)
239
240cc_library(
241    name = "snapshot",
242    srcs = [
243        "snapshot.cc",
244    ],
245    hdrs = [
246        "public/pw_thread_freertos/snapshot.h",
247    ],
248    # TODO: b/269204725 - Put this in the toolchain configuration instead.  I
249    # would like to say `copts = ["-Wno-c++20-designator"]`, but arm-gcc tells
250    # me that's an "unrecognized command line option"; I think it may be a
251    # clang-only flag.
252    copts = ["-Wno-pedantic"],
253    target_compatible_with = [
254        "//pw_build/constraints/rtos:freertos",
255    ],
256    deps = [
257        ":freertos_tasktcb",
258        ":util",
259        "//pw_function",
260        "//pw_log",
261        "//pw_protobuf",
262        "//pw_status",
263        "//pw_thread:snapshot",
264        "//pw_thread:thread_pwpb",
265    ],
266)
267
268cc_library(
269    name = "freertos_tasktcb",
270    hdrs = [
271        "public/pw_thread_freertos/freertos_tsktcb.h",
272        ":generate_freertos_tsktcb",
273    ],
274    includes = [
275        "public",
276        "thread_public_overrides",
277    ],
278)
279
280run_binary(
281    name = "generate_freertos_tsktcb",
282    srcs = [
283        "@freertos//:tasks.c",
284    ],
285    outs = [":thread_public_overrides/pw_thread_freertos_backend/freertos_tsktcb.h"],
286    args = [
287        "--freertos-tasks-c=$(location @freertos//:tasks.c)",
288        "--output=$(location :thread_public_overrides/pw_thread_freertos_backend/freertos_tsktcb.h)",
289    ],
290    tool = "//pw_thread_freertos/py:generate_freertos_tsktcb",
291)
292
293cc_library(
294    name = "test_thread_context",
295    hdrs = [
296        "public/pw_thread_freertos/test_thread_context_native.h",
297        "test_thread_context_public_overrides/pw_thread_backend/test_thread_context_native.h",
298    ],
299    includes = [
300        "public",
301        "test_thread_context_public_overrides",
302    ],
303    target_compatible_with = [
304        "//pw_build/constraints/rtos:freertos",
305    ],
306    deps = [
307        ":thread",
308        "//pw_thread:test_thread_context.facade",
309    ],
310)
311