blob: c2b67b19ed33755a68f89959baf45f29bd8c63e6 [file] [log] [blame]
Ewout van Bekkume3b56032020-12-22 12:00:18 -08001# 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(
16 "//pw_build:pigweed.bzl",
17 "pw_cc_library",
18 "pw_cc_test",
19)
20
21package(default_visibility = ["//visibility:public"])
22
23licenses(["notice"]) # Apache License 2.0
24
25# TODO(pwbug/101): Need to add support for facades/backends to Bazel.
26PW_THREAD_ID_BACKEND = "//pw_thread_stl:id"
Nathaniel Brougha1113be2021-03-07 09:05:41 +080027
Ewout van Bekkume3b56032020-12-22 12:00:18 -080028PW_THREAD_SLEEP_BACKEND = "//pw_thread_stl:sleep"
Nathaniel Brougha1113be2021-03-07 09:05:41 +080029
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -080030PW_THREAD_THREAD_BACKEND = "//pw_thread_stl:thread"
Nathaniel Brougha1113be2021-03-07 09:05:41 +080031
Ewout van Bekkume3b56032020-12-22 12:00:18 -080032PW_THREAD_YIELD_BACKEND = "//pw_thread_stl:yield"
33
34pw_cc_library(
35 name = "id_facade",
36 hdrs = [
37 "public/pw_thread/id.h",
38 ],
39 includes = ["public"],
40 deps = [
41 PW_THREAD_ID_BACKEND + "_headers",
42 ],
43)
44
45pw_cc_library(
46 name = "id",
47 deps = [
48 ":id_facade",
49 PW_THREAD_ID_BACKEND + "_headers",
50 ],
51)
52
53pw_cc_library(
54 name = "id_backend",
55 deps = [
Nathaniel Brougha1113be2021-03-07 09:05:41 +080056 PW_THREAD_ID_BACKEND,
Ewout van Bekkume3b56032020-12-22 12:00:18 -080057 ],
58)
59
60pw_cc_library(
61 name = "sleep_facade",
Nathaniel Brougha1113be2021-03-07 09:05:41 +080062 srcs = [
63 "sleep.cc",
64 ],
Ewout van Bekkume3b56032020-12-22 12:00:18 -080065 hdrs = [
66 "public/pw_thread/sleep.h",
67 ],
68 includes = ["public"],
Ewout van Bekkume3b56032020-12-22 12:00:18 -080069 deps = [
70 PW_THREAD_SLEEP_BACKEND + "_headers",
71 "//pw_chrono:system_clock",
72 "//pw_preprocessor",
73 ],
74)
75
76pw_cc_library(
77 name = "sleep",
78 deps = [
79 ":sleep_facade",
80 PW_THREAD_SLEEP_BACKEND + "_headers",
81 ],
82)
83
84pw_cc_library(
85 name = "sleep_backend",
86 deps = [
Nathaniel Brougha1113be2021-03-07 09:05:41 +080087 PW_THREAD_SLEEP_BACKEND,
Ewout van Bekkume3b56032020-12-22 12:00:18 -080088 ],
89)
90
91pw_cc_library(
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -080092 name = "thread_facade",
93 hdrs = [
94 "public/pw_thread/thread.h",
Ewout van Bekkum19e753a2021-04-28 18:06:55 -070095 "public/pw_thread/detached_thread.h",
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -080096 ],
97 includes = ["public"],
98 deps = [
99 ":id_facade",
100 PW_THREAD_THREAD_BACKEND + "_headers",
101 ],
102)
103
104pw_cc_library(
105 name = "thread",
Ewout van Bekkuma082d7f2021-04-15 14:36:37 -0700106 srcs = [
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800107 "thread.cc",
108 ],
109 deps = [
110 ":thread_core",
111 ":thread_facade",
112 PW_THREAD_THREAD_BACKEND + "_headers",
Ewout van Bekkuma082d7f2021-04-15 14:36:37 -0700113 ],
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -0800114)
115
116pw_cc_library(
117 name = "thread_backend",
118 deps = [
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800119 PW_THREAD_THREAD_BACKEND,
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -0800120 ],
121)
122
123pw_cc_library(
Ewout van Bekkuma082d7f2021-04-15 14:36:37 -0700124 name = "thread_core",
125 hdrs = [
126 "public/pw_thread/thread_core.h",
127 ],
128 includes = ["public"],
129)
130
131pw_cc_library(
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800132 name = "yield_facade",
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800133 srcs = [
134 "yield.cc",
135 ],
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800136 hdrs = [
137 "public/pw_thread/yield.h",
138 ],
139 includes = ["public"],
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800140 deps = [
141 PW_THREAD_YIELD_BACKEND + "_headers",
142 "//pw_preprocessor",
143 ],
144)
145
146pw_cc_library(
147 name = "yield",
148 deps = [
149 ":yield_facade",
150 PW_THREAD_YIELD_BACKEND + "_headers",
151 ],
152)
153
154pw_cc_library(
155 name = "yield_backend",
156 deps = [
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800157 PW_THREAD_YIELD_BACKEND,
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800158 ],
159)
160
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -0800161pw_cc_library(
162 name = "test_threads_header",
163 hdrs = [
164 "public/pw_thread/test_threads.h",
165 ],
166 deps = [
167 ":thread",
168 ],
169)
170
171# To instantiate this as a pw_cc_test, depend on this pw_cc_library and the
172# pw_cc_library which implements the backend for test_threads_header. See
173# //pw_thread:thread_backend_test as an example.
174pw_cc_library(
175 name = "thread_facade_test",
176 srcs = [
177 "thread_facade_test.cc",
178 ],
179 deps = [
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -0800180 ":id",
181 ":test_threads_header",
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800182 ":thread",
Ewout van Bekkumae6c03a2021-01-19 14:53:19 -0800183 "//pw_chrono:system_clock",
184 "//pw_sync:binary_semaphore",
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -0800185 "//pw_unit_test",
186 ],
187)
188
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800189pw_cc_test(
190 name = "id_facade_test",
191 srcs = [
192 "id_facade_test.cc",
193 ],
194 deps = [
195 ":id",
196 "//pw_unit_test",
197 ],
198)
199
200pw_cc_test(
201 name = "sleep_facade_test",
202 srcs = [
203 "sleep_facade_test.cc",
204 "sleep_facade_test_c.c",
205 ],
206 deps = [
207 ":sleep",
208 "//pw_chrono:system_clock",
209 "//pw_preprocessor",
210 "//pw_unit_test",
211 ],
212)
213
214pw_cc_test(
215 name = "yield_facade_test",
216 srcs = [
217 "yield_facade_test.cc",
218 "yield_facade_test_c.c",
219 ],
220 deps = [
221 ":yield",
222 "//pw_preprocessor",
223 "//pw_unit_test",
224 ],
225)