blob: 37ab8834362ed8107dceae85a5b7f5bb16b35784 [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",
95 ],
96 includes = ["public"],
97 deps = [
98 ":id_facade",
99 PW_THREAD_THREAD_BACKEND + "_headers",
100 ],
101)
102
103pw_cc_library(
104 name = "thread",
Ewout van Bekkuma082d7f2021-04-15 14:36:37 -0700105 srcs = [
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800106 "thread.cc",
107 ],
108 deps = [
109 ":thread_core",
110 ":thread_facade",
111 PW_THREAD_THREAD_BACKEND + "_headers",
Ewout van Bekkuma082d7f2021-04-15 14:36:37 -0700112 ],
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -0800113)
114
115pw_cc_library(
116 name = "thread_backend",
117 deps = [
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800118 PW_THREAD_THREAD_BACKEND,
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -0800119 ],
120)
121
122pw_cc_library(
Ewout van Bekkuma082d7f2021-04-15 14:36:37 -0700123 name = "thread_core",
124 hdrs = [
125 "public/pw_thread/thread_core.h",
126 ],
127 includes = ["public"],
128)
129
130pw_cc_library(
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800131 name = "yield_facade",
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800132 srcs = [
133 "yield.cc",
134 ],
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800135 hdrs = [
136 "public/pw_thread/yield.h",
137 ],
138 includes = ["public"],
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800139 deps = [
140 PW_THREAD_YIELD_BACKEND + "_headers",
141 "//pw_preprocessor",
142 ],
143)
144
145pw_cc_library(
146 name = "yield",
147 deps = [
148 ":yield_facade",
149 PW_THREAD_YIELD_BACKEND + "_headers",
150 ],
151)
152
153pw_cc_library(
154 name = "yield_backend",
155 deps = [
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800156 PW_THREAD_YIELD_BACKEND,
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800157 ],
158)
159
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -0800160pw_cc_library(
161 name = "test_threads_header",
162 hdrs = [
163 "public/pw_thread/test_threads.h",
164 ],
165 deps = [
166 ":thread",
167 ],
168)
169
170# To instantiate this as a pw_cc_test, depend on this pw_cc_library and the
171# pw_cc_library which implements the backend for test_threads_header. See
172# //pw_thread:thread_backend_test as an example.
173pw_cc_library(
174 name = "thread_facade_test",
175 srcs = [
176 "thread_facade_test.cc",
177 ],
178 deps = [
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -0800179 ":id",
180 ":test_threads_header",
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800181 ":thread",
Ewout van Bekkumae6c03a2021-01-19 14:53:19 -0800182 "//pw_chrono:system_clock",
183 "//pw_sync:binary_semaphore",
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -0800184 "//pw_unit_test",
185 ],
186)
187
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800188pw_cc_test(
189 name = "id_facade_test",
190 srcs = [
191 "id_facade_test.cc",
192 ],
193 deps = [
194 ":id",
195 "//pw_unit_test",
196 ],
197)
198
199pw_cc_test(
200 name = "sleep_facade_test",
201 srcs = [
202 "sleep_facade_test.cc",
203 "sleep_facade_test_c.c",
204 ],
205 deps = [
206 ":sleep",
207 "//pw_chrono:system_clock",
208 "//pw_preprocessor",
209 "//pw_unit_test",
210 ],
211)
212
213pw_cc_test(
214 name = "yield_facade_test",
215 srcs = [
216 "yield_facade_test.cc",
217 "yield_facade_test_c.c",
218 ],
219 deps = [
220 ":yield",
221 "//pw_preprocessor",
222 "//pw_unit_test",
223 ],
224)