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