• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(
16    "//pw_build:pigweed.bzl",
17    "pw_cc_test",
18)
19
20package(default_visibility = ["//visibility:public"])
21
22licenses(["notice"])
23
24# Libraries
25
26cc_library(
27    name = "allocator",
28    srcs = [
29        "allocator.cc",
30        "as_pmr_allocator.cc",
31    ],
32    hdrs = [
33        "public/pw_allocator/allocator.h",
34        "public/pw_allocator/as_pmr_allocator.h",
35    ],
36    includes = ["public"],
37    deps = [
38        ":deallocator",
39        "//pw_assert",
40        "//pw_result",
41        "//pw_status",
42    ],
43)
44
45cc_library(
46    name = "allocator_as_pool",
47    srcs = [
48        "allocator_as_pool.cc",
49    ],
50    hdrs = [
51        "public/pw_allocator/allocator_as_pool.h",
52    ],
53    includes = ["public"],
54    deps = [
55        ":allocator",
56        ":pool",
57        "//pw_status",
58    ],
59)
60
61cc_library(
62    name = "best_fit_block_allocator",
63    hdrs = ["public/pw_allocator/best_fit_block_allocator.h"],
64    includes = ["public"],
65    deps = [":block_allocator_base"],
66)
67
68cc_library(
69    name = "block",
70    srcs = ["block.cc"],
71    hdrs = [
72        "public/pw_allocator/block.h",
73    ],
74    includes = ["public"],
75    deps = [
76        ":allocator",
77        ":buffer",
78        "//pw_assert",
79        "//pw_bytes",
80        "//pw_bytes:alignment",
81        "//pw_result",
82        "//pw_status",
83    ],
84)
85
86# TODO(b/326509341): Remove when all customers depend on the correct targets.
87cc_library(
88    name = "block_allocator",
89    hdrs = ["public/pw_allocator/block_allocator.h"],
90    includes = ["public"],
91    deps = [
92        ":best_fit_block_allocator",
93        ":dual_first_fit_block_allocator",
94        ":first_fit_block_allocator",
95        ":last_fit_block_allocator",
96        ":worst_fit_block_allocator",
97    ],
98)
99
100# TODO(b/326509341): Rename when all customers depend on the correct targets.
101cc_library(
102    name = "block_allocator_base",
103    srcs = ["block_allocator.cc"],
104    hdrs = ["public/pw_allocator/block_allocator_base.h"],
105    includes = ["public"],
106    deps = [
107        ":allocator",
108        ":block",
109        ":fragmentation",
110        "//pw_assert",
111        "//pw_bytes:alignment",
112        "//pw_result",
113        "//pw_status",
114    ],
115)
116
117cc_library(
118    name = "bucket",
119    srcs = [
120        "bucket.cc",
121    ],
122    hdrs = [
123        "public/pw_allocator/bucket.h",
124    ],
125    includes = ["public"],
126    deps = [
127        "//pw_assert",
128        "//pw_function",
129        "//pw_span",
130    ],
131)
132
133cc_library(
134    name = "bucket_block_allocator",
135    hdrs = [
136        "public/pw_allocator/bucket_block_allocator.h",
137    ],
138    includes = ["public"],
139    deps = [
140        ":block_allocator_base",
141        ":bucket",
142        "//pw_status",
143    ],
144)
145
146cc_library(
147    name = "buddy_allocator",
148    srcs = [
149        "buddy_allocator.cc",
150    ],
151    hdrs = [
152        "public/pw_allocator/buddy_allocator.h",
153    ],
154    includes = ["public"],
155    deps = [
156        ":allocator",
157        ":bucket",
158        ":buffer",
159        "//pw_alignment",
160        "//pw_assert",
161        "//pw_bytes",
162        "//pw_bytes:alignment",
163        "//pw_containers:vector",
164    ],
165)
166
167cc_library(
168    name = "buffer",
169    hdrs = [
170        "public/pw_allocator/buffer.h",
171    ],
172    includes = ["public"],
173    deps = [
174        "//pw_assert",
175        "//pw_bytes",
176        "//pw_bytes:alignment",
177        "//pw_result",
178    ],
179)
180
181cc_library(
182    name = "bump_allocator",
183    srcs = [
184        "bump_allocator.cc",
185    ],
186    hdrs = [
187        "public/pw_allocator/bump_allocator.h",
188    ],
189    includes = ["public"],
190    deps = [
191        ":allocator",
192        ":buffer",
193        "//pw_bytes",
194        "//pw_bytes:alignment",
195    ],
196)
197
198cc_library(
199    name = "chunk_pool",
200    srcs = [
201        "chunk_pool.cc",
202    ],
203    hdrs = [
204        "public/pw_allocator/chunk_pool.h",
205    ],
206    includes = ["public"],
207    deps = [
208        ":buffer",
209        ":pool",
210        "//pw_assert",
211        "//pw_bytes",
212        "//pw_bytes:alignment",
213        "//pw_result",
214    ],
215)
216
217cc_library(
218    name = "deallocator",
219    srcs = [
220        "unique_ptr.cc",
221    ],
222    hdrs = [
223        "public/pw_allocator/capability.h",
224        "public/pw_allocator/deallocator.h",
225        "public/pw_allocator/layout.h",
226        "public/pw_allocator/unique_ptr.h",
227    ],
228    includes = ["public"],
229    deps = [
230        "//pw_assert",
231        "//pw_preprocessor",
232        "//pw_result",
233        "//pw_status",
234    ],
235)
236
237cc_library(
238    name = "dual_first_fit_block_allocator",
239    hdrs = ["public/pw_allocator/dual_first_fit_block_allocator.h"],
240    includes = ["public"],
241    deps = [":block_allocator_base"],
242)
243
244cc_library(
245    name = "fallback_allocator",
246    srcs = [
247        "fallback_allocator.cc",
248    ],
249    hdrs = [
250        "public/pw_allocator/fallback_allocator.h",
251    ],
252    includes = ["public"],
253    deps = [
254        ":allocator",
255        ":deallocator",
256        "//pw_assert",
257        "//pw_result",
258        "//pw_status",
259    ],
260)
261
262cc_library(
263    name = "first_fit_block_allocator",
264    hdrs = ["public/pw_allocator/first_fit_block_allocator.h"],
265    includes = ["public"],
266    deps = [":block_allocator_base"],
267)
268
269cc_library(
270    name = "fragmentation",
271    srcs = ["fragmentation.cc"],
272    hdrs = ["public/pw_allocator/fragmentation.h"],
273    includes = ["public"],
274)
275
276cc_library(
277    name = "freelist",
278    srcs = [
279        "freelist.cc",
280    ],
281    hdrs = [
282        "public/pw_allocator/freelist.h",
283    ],
284    includes = ["public"],
285    deps = [
286        "//pw_containers",
287        "//pw_span",
288        "//pw_status",
289    ],
290)
291
292cc_library(
293    name = "freelist_heap",
294    srcs = [
295        "freelist_heap.cc",
296    ],
297    hdrs = [
298        "public/pw_allocator/freelist_heap.h",
299    ],
300    includes = ["public"],
301    deps = [
302        ":block",
303        ":freelist",
304        "//pw_log",
305    ],
306)
307
308cc_library(
309    name = "last_fit_block_allocator",
310    hdrs = ["public/pw_allocator/last_fit_block_allocator.h"],
311    includes = ["public"],
312    deps = [":block_allocator_base"],
313)
314
315cc_library(
316    name = "libc_allocator",
317    srcs = [
318        "libc_allocator.cc",
319    ],
320    hdrs = [
321        "public/pw_allocator/libc_allocator.h",
322    ],
323    includes = ["public"],
324    deps = [
325        ":allocator",
326    ],
327)
328
329cc_library(
330    name = "null_allocator",
331    srcs = [
332        "null_allocator.cc",
333    ],
334    hdrs = [
335        "public/pw_allocator/null_allocator.h",
336    ],
337    includes = ["public"],
338    deps = [
339        ":allocator",
340    ],
341)
342
343cc_library(
344    name = "pool",
345    hdrs = ["public/pw_allocator/pool.h"],
346    includes = [":default_config"],
347    deps = [
348        ":deallocator",
349        "//pw_bytes",
350        "//pw_result",
351    ],
352)
353
354cc_library(
355    name = "synchronized_allocator",
356    hdrs = [
357        "public/pw_allocator/synchronized_allocator.h",
358    ],
359    includes = ["public"],
360    deps = [
361        ":allocator",
362        "//pw_sync:borrow",
363    ],
364)
365
366cc_library(
367    name = "tracking_allocator",
368    hdrs = [
369        "public/pw_allocator/metrics.h",
370        "public/pw_allocator/tracking_allocator.h",
371    ],
372    includes = ["public"],
373    deps = [
374        ":allocator",
375        "//pw_assert",
376        "//pw_metric:metric",
377        "//pw_status",
378    ],
379)
380
381cc_library(
382    name = "typed_pool",
383    hdrs = [
384        "public/pw_allocator/typed_pool.h",
385    ],
386    includes = ["public"],
387    deps = [
388        ":allocator",
389        ":chunk_pool",
390        "//pw_bytes",
391        "//pw_result",
392    ],
393)
394
395cc_library(
396    name = "worst_fit_block_allocator",
397    hdrs = ["public/pw_allocator/worst_fit_block_allocator.h"],
398    includes = ["public"],
399    deps = [":block_allocator_base"],
400)
401
402# Test support
403
404cc_library(
405    name = "testing",
406    testonly = True,
407    hdrs = [
408        "public/pw_allocator/testing.h",
409    ],
410    includes = ["public"],
411    deps = [
412        ":allocator",
413        ":block",
414        ":buffer",
415        ":first_fit_block_allocator",
416        ":tracking_allocator",
417        "//pw_assert",
418        "//pw_bytes",
419        "//pw_result",
420        "//pw_status",
421        "//pw_unit_test",
422    ],
423)
424
425cc_library(
426    name = "block_allocator_testing",
427    testonly = True,
428    srcs = [
429        "block_allocator_testing.cc",
430    ],
431    hdrs = [
432        "public/pw_allocator/block_allocator_testing.h",
433    ],
434    includes = ["public"],
435    deps = [
436        ":block",
437        ":block_allocator",
438        "//pw_assert",
439        "//pw_bytes:alignment",
440        "//pw_status",
441        "//pw_unit_test",
442    ],
443)
444
445cc_library(
446    name = "test_harness",
447    testonly = True,
448    srcs = [
449        "test_harness.cc",
450    ],
451    hdrs = [
452        "public/pw_allocator/test_harness.h",
453    ],
454    includes = ["public"],
455    deps = [
456        ":allocator",
457        "//pw_assert",
458        "//pw_containers",
459        "//pw_random",
460        "//third_party/fuchsia:stdcompat",
461    ],
462)
463
464cc_library(
465    name = "fuzzing",
466    testonly = True,
467    srcs = [
468        "fuzzing.cc",
469    ],
470    hdrs = [
471        "public/pw_allocator/fuzzing.h",
472    ],
473    includes = ["public"],
474    deps = [
475        ":test_harness",
476        "//pw_fuzzer:fuzztest",
477    ],
478)
479
480# Tests
481
482pw_cc_test(
483    name = "allocator_as_pool_test",
484    srcs = [
485        "allocator_as_pool_test.cc",
486    ],
487    deps = [
488        ":allocator_as_pool",
489        ":testing",
490        "//pw_unit_test",
491    ],
492)
493
494pw_cc_test(
495    name = "allocator_test",
496    srcs = [
497        "allocator_test.cc",
498    ],
499    deps = [
500        ":allocator",
501        ":testing",
502        "//pw_unit_test",
503    ],
504)
505
506pw_cc_test(
507    name = "as_pmr_allocator_test",
508    srcs = [
509        "as_pmr_allocator_test.cc",
510    ],
511    deps = [
512        ":allocator",
513        ":testing",
514        "//pw_unit_test",
515    ],
516)
517
518pw_cc_test(
519    name = "best_fit_block_allocator_test",
520    srcs = ["best_fit_block_allocator_test.cc"],
521    deps = [
522        ":best_fit_block_allocator",
523        ":block_allocator_testing",
524        "//pw_unit_test",
525    ],
526)
527
528pw_cc_test(
529    name = "block_test",
530    srcs = [
531        "block_test.cc",
532    ],
533    deps = [
534        ":block",
535        "//pw_span",
536        "//pw_unit_test",
537    ],
538)
539
540pw_cc_test(
541    name = "bucket_block_allocator_test",
542    srcs = ["bucket_block_allocator_test.cc"],
543    deps = [
544        ":block_allocator_testing",
545        ":bucket_block_allocator",
546        "//pw_unit_test",
547    ],
548)
549
550pw_cc_test(
551    name = "buddy_allocator_test",
552    srcs = [
553        "buddy_allocator_test.cc",
554    ],
555    deps = [
556        ":buddy_allocator",
557        "//pw_unit_test",
558    ],
559)
560
561pw_cc_test(
562    name = "buffer_test",
563    srcs = [
564        "buffer_test.cc",
565    ],
566    deps = [
567        ":buffer",
568        "//pw_bytes",
569        "//pw_result",
570    ],
571)
572
573pw_cc_test(
574    name = "bump_allocator_test",
575    srcs = [
576        "bump_allocator_test.cc",
577    ],
578    deps = [
579        ":bump_allocator",
580        "//pw_unit_test",
581    ],
582)
583
584pw_cc_test(
585    name = "chunk_pool_test",
586    srcs = [
587        "chunk_pool_test.cc",
588    ],
589    deps = [
590        ":chunk_pool",
591        ":testing",
592    ],
593)
594
595pw_cc_test(
596    name = "dual_first_fit_block_allocator_test",
597    srcs = ["dual_first_fit_block_allocator_test.cc"],
598    deps = [
599        ":block_allocator_testing",
600        ":dual_first_fit_block_allocator",
601        "//pw_unit_test",
602    ],
603)
604
605pw_cc_test(
606    name = "fallback_allocator_test",
607    srcs = [
608        "fallback_allocator_test.cc",
609    ],
610    deps = [
611        ":fallback_allocator",
612        ":testing",
613        "//pw_status",
614        "//pw_unit_test",
615    ],
616)
617
618pw_cc_test(
619    name = "first_fit_block_allocator_test",
620    srcs = ["first_fit_block_allocator_test.cc"],
621    deps = [
622        ":block_allocator_testing",
623        ":buffer",
624        ":first_fit_block_allocator",
625        "//pw_unit_test",
626    ],
627)
628
629pw_cc_test(
630    name = "fragmentation_test",
631    srcs = ["fragmentation_test.cc"],
632    deps = [
633        ":fragmentation",
634        "//pw_unit_test",
635    ],
636)
637
638pw_cc_test(
639    name = "freelist_test",
640    srcs = [
641        "freelist_test.cc",
642    ],
643    deps = [
644        ":freelist",
645        "//pw_span",
646        "//pw_status",
647        "//pw_unit_test",
648    ],
649)
650
651pw_cc_test(
652    name = "freelist_heap_test",
653    srcs = [
654        "freelist_heap_test.cc",
655    ],
656    deps = [
657        ":freelist_heap",
658    ],
659)
660
661pw_cc_test(
662    name = "last_fit_block_allocator_test",
663    srcs = ["last_fit_block_allocator_test.cc"],
664    deps = [
665        ":block_allocator_testing",
666        ":last_fit_block_allocator",
667        "//pw_unit_test",
668    ],
669)
670
671pw_cc_test(
672    name = "libc_allocator_test",
673    srcs = [
674        "libc_allocator_test.cc",
675    ],
676    deps = [
677        ":libc_allocator",
678        "//pw_unit_test",
679    ],
680)
681
682pw_cc_test(
683    name = "null_allocator_test",
684    srcs = [
685        "null_allocator_test.cc",
686    ],
687    deps = [
688        ":null_allocator",
689        "//pw_unit_test",
690    ],
691)
692
693pw_cc_test(
694    name = "synchronized_allocator_test",
695    srcs = [
696        "synchronized_allocator_test.cc",
697    ],
698    deps = [
699        ":synchronized_allocator",
700        ":test_harness",
701        ":testing",
702        "//pw_random",
703        "//pw_sync:binary_semaphore",
704        "//pw_sync:interrupt_spin_lock",
705        "//pw_sync:mutex",
706        "//pw_sync:virtual_basic_lockable",
707        "//pw_thread:test_thread_context",
708        "//pw_thread:thread",
709        "//pw_thread:thread_core",
710        "//pw_thread:yield",
711        "//pw_unit_test",
712    ],
713)
714
715pw_cc_test(
716    name = "tracking_allocator_test",
717    srcs = [
718        "tracking_allocator_test.cc",
719    ],
720    deps = [
721        ":testing",
722        ":tracking_allocator",
723        "//pw_unit_test",
724    ],
725)
726
727pw_cc_test(
728    name = "typed_pool_test",
729    srcs = [
730        "typed_pool_test.cc",
731    ],
732    deps = [
733        ":typed_pool",
734        "//pw_bytes:alignment",
735        "//pw_unit_test",
736    ],
737)
738
739pw_cc_test(
740    name = "unique_ptr_test",
741    srcs = ["unique_ptr_test.cc"],
742    deps = [
743        ":allocator",
744        ":testing",
745        "//pw_unit_test",
746    ],
747)
748
749pw_cc_test(
750    name = "worst_fit_block_allocator_test",
751    srcs = ["worst_fit_block_allocator_test.cc"],
752    deps = [
753        ":block_allocator_testing",
754        ":worst_fit_block_allocator",
755        "//pw_unit_test",
756    ],
757)
758
759# Docs
760
761cc_library(
762    name = "size_reporter",
763    hdrs = ["public/pw_allocator/size_reporter.h"],
764    includes = ["public"],
765    deps = [
766        ":null_allocator",
767        "//pw_bloat:bloat_this_binary",
768        "//pw_bytes",
769    ],
770)
771