• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2023 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("@rules_cc//cc:cc_library.bzl", "cc_library")
16load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
17load("//pw_build:compatibility.bzl", "incompatible_with_mcu")
18load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
19
20package(
21    default_visibility = ["//visibility:public"],
22    features = ["-layering_check"],
23)
24
25licenses(["notice"])
26
27cc_library(
28    name = "chunk",
29    srcs = ["chunk.cc"],
30    hdrs = ["public/pw_multibuf/chunk.h"],
31    implementation_deps = ["//pw_assert:check"],
32    strip_include_prefix = "public",
33    deps = [
34        "//pw_assert:assert",
35        "//pw_bytes",
36        "//pw_preprocessor",
37        "//pw_span",
38        "//pw_sync:mutex",
39    ],
40)
41
42cc_library(
43    name = "header_chunk_region_tracker",
44    hdrs = ["public/pw_multibuf/header_chunk_region_tracker.h"],
45    strip_include_prefix = "public",
46    deps = [
47        ":chunk",
48        "//pw_allocator:allocator",
49        "//pw_bytes",
50    ],
51)
52
53cc_library(
54    name = "single_chunk_region_tracker",
55    hdrs = ["public/pw_multibuf/single_chunk_region_tracker.h"],
56    strip_include_prefix = "public",
57    deps = [
58        ":chunk",
59        "//pw_assert:assert",
60        "//pw_bytes",
61    ],
62)
63
64pw_cc_test(
65    name = "chunk_test",
66    srcs = ["chunk_test.cc"],
67    deps = [
68        ":chunk",
69        ":header_chunk_region_tracker",
70        "//pw_allocator:testing",
71    ],
72)
73
74pw_cc_test(
75    name = "header_chunk_region_tracker_test",
76    srcs = ["header_chunk_region_tracker_test.cc"],
77    deps = [
78        ":chunk",
79        ":header_chunk_region_tracker",
80        "//pw_allocator:testing",
81        "//pw_status",
82    ],
83)
84
85pw_cc_test(
86    name = "single_chunk_region_tracker_test",
87    srcs = ["single_chunk_region_tracker_test.cc"],
88    # TODO: b/260624583 - Fix this for rp2040
89    target_compatible_with = select({
90        "//pw_build/constraints/chipset:rp2040": ["@platforms//:incompatible"],
91        "//conditions:default": [],
92    }),
93    deps = [
94        ":chunk",
95        ":single_chunk_region_tracker",
96    ],
97)
98
99cc_library(
100    name = "pw_multibuf",
101    srcs = ["multibuf.cc"],
102    hdrs = ["public/pw_multibuf/multibuf.h"],
103    implementation_deps = ["//pw_assert:check"],
104    strip_include_prefix = "public",
105    deps = [
106        ":chunk",
107        "//pw_preprocessor",
108        "//pw_status",
109    ],
110)
111
112pw_cc_test(
113    name = "multibuf_test",
114    srcs = ["multibuf_test.cc"],
115    deps = [
116        ":internal_test_utils",
117        ":pw_multibuf",
118        "//pw_assert:check",
119        "//pw_bytes",
120    ],
121)
122
123cc_library(
124    name = "allocator",
125    srcs = [
126        "allocator.cc",
127    ],
128    hdrs = [
129        "public/pw_multibuf/allocator.h",
130    ],
131    strip_include_prefix = "public",
132    deps = [
133        ":pw_multibuf",
134        "//pw_containers:intrusive_forward_list",
135        "//pw_result",
136        "//pw_sync:interrupt_spin_lock",
137    ],
138)
139
140cc_library(
141    name = "allocator_async",
142    srcs = [
143        "allocator_async.cc",
144    ],
145    hdrs = [
146        "public/pw_multibuf/allocator_async.h",
147    ],
148    implementation_deps = ["//pw_assert:check"],
149    strip_include_prefix = "public",
150    deps = [
151        ":allocator",
152        "//pw_async2:dispatcher",
153        "//pw_async2:poll",
154    ],
155)
156
157# TODO: https://pwbug.dev/384583239 - Split async into its own test.
158pw_cc_test(
159    name = "allocator_test",
160    srcs = ["allocator_test.cc"],
161    deps = [
162        ":allocator",
163        ":allocator_async",
164        "//pw_async2:dispatcher",
165        "//pw_async2:poll",
166    ],
167)
168
169cc_library(
170    name = "simple_allocator",
171    srcs = ["simple_allocator.cc"],
172    hdrs = ["public/pw_multibuf/simple_allocator.h"],
173    implementation_deps = ["//pw_assert:check"],
174    strip_include_prefix = "public",
175    deps = [
176        ":allocator",
177        ":pw_multibuf",
178        "//pw_allocator:allocator",
179        "//pw_bytes:alignment",
180        "//pw_containers:intrusive_list",
181    ],
182)
183
184pw_cc_test(
185    name = "simple_allocator_test",
186    srcs = ["simple_allocator_test.cc"],
187    deps = [
188        ":simple_allocator",
189        "//pw_allocator:null_allocator",
190        "//pw_allocator:testing",
191        "//pw_async2:dispatcher",
192        "//pw_async2:poll",
193    ],
194)
195
196cc_library(
197    name = "stream",
198    srcs = ["stream.cc"],
199    hdrs = ["public/pw_multibuf/stream.h"],
200    strip_include_prefix = "public",
201    deps = [
202        ":pw_multibuf",
203        "//pw_status",
204        "//pw_stream",
205    ],
206)
207
208pw_cc_test(
209    name = "stream_test",
210    srcs = ["stream_test.cc"],
211    deps = [
212        ":internal_test_utils",
213        ":pw_multibuf",
214        ":stream",
215    ],
216)
217
218cc_library(
219    name = "from_span",
220    srcs = ["from_span.cc"],
221    hdrs = ["public/pw_multibuf/from_span.h"],
222    strip_include_prefix = "public",
223    deps = [
224        ":pw_multibuf",
225        "//pw_allocator:allocator",
226        "//pw_function",
227    ],
228)
229
230pw_cc_test(
231    name = "from_span_test",
232    srcs = ["from_span_test.cc"],
233    deps = [
234        ":from_span",
235        "//pw_allocator:testing",
236    ],
237)
238
239cc_library(
240    name = "testing",
241    testonly = True,
242    hdrs = ["public/pw_multibuf/simple_allocator_for_test.h"],
243    strip_include_prefix = "public",
244    deps = [
245        ":simple_allocator",
246        "//pw_allocator:synchronized_allocator",
247        "//pw_allocator:testing",
248        "//pw_assert:assert",
249        "//pw_sync:mutex",
250    ],
251)
252
253cc_library(
254    name = "internal_test_utils",
255    testonly = True,
256    hdrs = ["pw_multibuf_private/test_utils.h"],
257    includes = ["pw_multibuf_private"],
258    visibility = ["//visibility:private"],
259    deps = [
260        ":header_chunk_region_tracker",
261        ":pw_multibuf",
262        "//pw_allocator:testing",
263        "//pw_assert:check",
264        "//pw_bytes",
265        "//pw_status",
266    ],
267)
268
269filegroup(
270    name = "doxygen",
271    srcs = [
272        "public/pw_multibuf/allocator.h",
273        "public/pw_multibuf/allocator_async.h",
274        "public/pw_multibuf/chunk.h",
275        "public/pw_multibuf/from_span.h",
276        "public/pw_multibuf/header_chunk_region_tracker.h",
277        "public/pw_multibuf/multibuf.h",
278        "public/pw_multibuf/simple_allocator.h",
279        "public/pw_multibuf/simple_allocator_for_test.h",
280        "public/pw_multibuf/single_chunk_region_tracker.h",
281        "public/pw_multibuf/stream.h",
282    ],
283)
284
285sphinx_docs_library(
286    name = "docs",
287    srcs = [
288        "docs.rst",
289    ],
290    prefix = "pw_multibuf/",
291    target_compatible_with = incompatible_with_mcu(),
292)
293