# Copyright 2023 The Pigweed Authors # # Licensed under the Apache License, Version 2.0 (the "License"); you may not # use this file except in compliance with the License. You may obtain a copy of # the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. import("//build_overrides/pigweed.gni") import("$dir_pw_bloat/bloat.gni") import("$dir_pw_build/target_types.gni") import("$dir_pw_docgen/docs.gni") import("$dir_pw_fuzzer/fuzz_test.gni") import("$dir_pw_sync/backend.gni") import("$dir_pw_thread/backend.gni") import("$dir_pw_unit_test/test.gni") config("default_config") { include_dirs = [ "public" ] } group("pw_allocator") { public_deps = [ ":allocator", ":block", ":freelist", ":freelist_heap", ] } # Libraries pw_source_set("allocator") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/allocator.h", "public/pw_allocator/as_pmr_allocator.h", ] public_deps = [ ":deallocator", "$dir_pw_assert:check", dir_pw_result, ] sources = [ "allocator.cc", "as_pmr_allocator.cc", ] } pw_source_set("allocator_as_pool") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/allocator_as_pool.h" ] public_deps = [ ":allocator", ":pool", dir_pw_status, ] sources = [ "allocator_as_pool.cc" ] } pw_source_set("best_fit_block_allocator") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/best_fit_block_allocator.h" ] public_deps = [ ":block_allocator_base" ] } pw_source_set("block") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/block.h" ] public_deps = [ ":allocator", ":buffer", "$dir_pw_bytes:alignment", dir_pw_assert, dir_pw_bytes, dir_pw_result, dir_pw_status, ] deps = [ ":buffer", dir_pw_assert, ] sources = [ "block.cc" ] } # TODO(b/326509341): Remove when all customers depend on the correct targets. pw_source_set("block_allocator") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/block_allocator.h" ] public_deps = [ ":best_fit_block_allocator", ":dual_first_fit_block_allocator", ":first_fit_block_allocator", ":last_fit_block_allocator", ":worst_fit_block_allocator", ] } # TODO(b/326509341): Rename when all customers depend on the correct targets. pw_source_set("block_allocator_base") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/block_allocator_base.h" ] public_deps = [ ":allocator", ":block", ":bucket", ":fragmentation", dir_pw_bytes, dir_pw_result, dir_pw_status, ] deps = [ dir_pw_assert ] sources = [ "block_allocator.cc" ] } pw_source_set("bucket") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/bucket.h" ] public_deps = [ dir_pw_function, dir_pw_span, ] deps = [ dir_pw_assert ] sources = [ "bucket.cc" ] } pw_source_set("bucket_block_allocator") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/bucket_block_allocator.h" ] public_deps = [ ":block_allocator_base", ":bucket", dir_pw_status, ] } pw_source_set("buddy_allocator") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/buddy_allocator.h" ] public_deps = [ ":allocator", ":bucket", "$dir_pw_containers:vector", dir_pw_alignment, dir_pw_bytes, ] deps = [ ":buffer", "$dir_pw_bytes:alignment", dir_pw_assert, ] sources = [ "buddy_allocator.cc" ] } pw_source_set("buffer") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/buffer.h" ] public_deps = [ dir_pw_bytes, dir_pw_result, ] deps = [ "$dir_pw_bytes:alignment", dir_pw_assert, ] } pw_source_set("bump_allocator") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/bump_allocator.h" ] public_deps = [ ":allocator", "$dir_pw_bytes:alignment", dir_pw_bytes, ] deps = [ ":buffer" ] sources = [ "bump_allocator.cc" ] } pw_source_set("chunk_pool") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/chunk_pool.h" ] public_deps = [ ":pool", dir_pw_bytes, dir_pw_result, ] deps = [ ":buffer", "$dir_pw_assert:check", "$dir_pw_bytes:alignment", ] sources = [ "chunk_pool.cc" ] } pw_source_set("deallocator") { sources = [ "unique_ptr.cc" ] public = [ "public/pw_allocator/capability.h", "public/pw_allocator/deallocator.h", "public/pw_allocator/layout.h", "public/pw_allocator/unique_ptr.h", ] public_configs = [ ":default_config" ] public_deps = [ dir_pw_assert, dir_pw_preprocessor, dir_pw_result, dir_pw_status, ] } pw_source_set("dual_first_fit_block_allocator") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/dual_first_fit_block_allocator.h" ] public_deps = [ ":block_allocator_base" ] } pw_source_set("fallback_allocator") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/fallback_allocator.h" ] public_deps = [ ":allocator", ":deallocator", dir_pw_result, dir_pw_status, ] sources = [ "fallback_allocator.cc" ] deps = [ "$dir_pw_assert:check" ] } pw_source_set("first_fit_block_allocator") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/first_fit_block_allocator.h" ] public_deps = [ ":block_allocator_base" ] } pw_source_set("fragmentation") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/fragmentation.h" ] sources = [ "fragmentation.cc" ] } pw_source_set("freelist") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/freelist.h" ] public_deps = [ "$dir_pw_containers:vector", dir_pw_span, dir_pw_status, ] sources = [ "freelist.cc" ] } pw_source_set("freelist_heap") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/freelist_heap.h" ] public_deps = [ ":block", ":freelist", ] deps = [ dir_pw_assert, dir_pw_log, dir_pw_span, ] sources = [ "freelist_heap.cc" ] } pw_source_set("last_fit_block_allocator") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/last_fit_block_allocator.h" ] public_deps = [ ":block_allocator_base" ] } pw_source_set("libc_allocator") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/libc_allocator.h" ] public_deps = [ ":allocator" ] sources = [ "libc_allocator.cc" ] } pw_source_set("null_allocator") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/null_allocator.h" ] public_deps = [ ":allocator" ] sources = [ "null_allocator.cc" ] } pw_source_set("pool") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/pool.h" ] public_deps = [ ":deallocator", dir_pw_bytes, dir_pw_result, ] } pw_source_set("synchronized_allocator") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/synchronized_allocator.h" ] public_deps = [ ":allocator", "$dir_pw_sync:borrow", ] } pw_source_set("tracking_allocator") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/metrics.h", "public/pw_allocator/tracking_allocator.h", ] public_deps = [ ":allocator", dir_pw_metric, dir_pw_status, ] deps = [ dir_pw_assert ] } pw_source_set("typed_pool") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/typed_pool.h" ] public_deps = [ ":allocator", ":chunk_pool", dir_pw_bytes, dir_pw_result, ] } pw_source_set("worst_fit_block_allocator") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/worst_fit_block_allocator.h" ] public_deps = [ ":block_allocator_base" ] } # Test support pw_source_set("testing") { public = [ "public/pw_allocator/testing.h" ] public_deps = [ ":allocator", ":block", ":buffer", ":first_fit_block_allocator", ":tracking_allocator", dir_pw_bytes, dir_pw_result, dir_pw_status, dir_pw_unit_test, ] deps = [ dir_pw_assert ] } pw_source_set("block_allocator_testing") { public = [ "public/pw_allocator/block_allocator_testing.h" ] public_deps = [ ":block", ":block_allocator", dir_pw_unit_test, ] deps = [ "$dir_pw_bytes:alignment", dir_pw_assert, dir_pw_status, ] sources = [ "block_allocator_testing.cc" ] } pw_source_set("test_harness") { public = [ "public/pw_allocator/test_harness.h" ] public_deps = [ ":allocator", dir_pw_containers, dir_pw_random, ] deps = [ "$dir_pw_third_party/fuchsia:stdcompat", dir_pw_assert, ] sources = [ "test_harness.cc" ] } pw_source_set("fuzzing") { public = [ "public/pw_allocator/fuzzing.h" ] public_deps = [ ":test_harness", "$dir_pw_fuzzer:fuzztest", ] sources = [ "fuzzing.cc" ] } # Tests pw_test("allocator_as_pool_test") { deps = [ ":allocator_as_pool", ":testing", ] sources = [ "allocator_as_pool_test.cc" ] } pw_test("allocator_test") { deps = [ ":allocator", ":testing", ] sources = [ "allocator_test.cc" ] } pw_test("as_pmr_allocator_test") { deps = [ ":allocator", ":testing", ] sources = [ "as_pmr_allocator_test.cc" ] } pw_test("best_fit_block_allocator_test") { deps = [ ":best_fit_block_allocator", ":block_allocator_testing", ] sources = [ "best_fit_block_allocator_test.cc" ] } pw_test("block_test") { deps = [ ":block", dir_pw_span, ] sources = [ "block_test.cc" ] } pw_test("bucket_block_allocator_test") { deps = [ ":block_allocator_testing", ":bucket_block_allocator", ] sources = [ "bucket_block_allocator_test.cc" ] } pw_test("buddy_allocator_test") { deps = [ ":buddy_allocator" ] sources = [ "buddy_allocator_test.cc" ] } pw_test("buffer_test") { deps = [ ":buffer", dir_pw_bytes, dir_pw_result, ] sources = [ "buffer_test.cc" ] } pw_test("bump_allocator_test") { deps = [ ":bump_allocator" ] sources = [ "bump_allocator_test.cc" ] } pw_test("chunk_pool_test") { deps = [ ":chunk_pool", ":testing", ] sources = [ "chunk_pool_test.cc" ] } pw_test("dual_first_fit_block_allocator_test") { deps = [ ":block_allocator_testing", ":dual_first_fit_block_allocator", ] sources = [ "dual_first_fit_block_allocator_test.cc" ] } pw_test("fallback_allocator_test") { deps = [ ":fallback_allocator", ":testing", dir_pw_status, ] sources = [ "fallback_allocator_test.cc" ] } pw_test("first_fit_block_allocator_test") { deps = [ ":block_allocator_testing", ":buffer", ":first_fit_block_allocator", ] sources = [ "first_fit_block_allocator_test.cc" ] } pw_test("fragmentation_test") { deps = [ ":fragmentation" ] sources = [ "fragmentation_test.cc" ] } pw_test("freelist_test") { deps = [ ":freelist", dir_pw_span, dir_pw_status, ] sources = [ "freelist_test.cc" ] } pw_test("freelist_heap_test") { deps = [ ":freelist_heap" ] sources = [ "freelist_heap_test.cc" ] } pw_test("last_fit_block_allocator_test") { deps = [ ":block_allocator_testing", ":last_fit_block_allocator", ] sources = [ "last_fit_block_allocator_test.cc" ] } pw_test("libc_allocator_test") { deps = [ ":libc_allocator" ] sources = [ "libc_allocator_test.cc" ] } pw_test("null_allocator_test") { deps = [ ":null_allocator" ] sources = [ "null_allocator_test.cc" ] } pw_test("synchronized_allocator_test") { enable_if = pw_sync_BINARY_SEMAPHORE_BACKEND != "" && pw_sync_MUTEX_BACKEND != "" && pw_sync_INTERRUPT_SPIN_LOCK_BACKEND != "" && pw_thread_YIELD_BACKEND != "" && pw_thread_TEST_THREAD_CONTEXT_BACKEND != "" deps = [ ":synchronized_allocator", ":test_harness", ":testing", "$dir_pw_sync:binary_semaphore", "$dir_pw_sync:interrupt_spin_lock", "$dir_pw_sync:mutex", "$dir_pw_sync:virtual_basic_lockable", "$dir_pw_thread:test_thread_context", "$dir_pw_thread:thread", "$dir_pw_thread:thread_core", "$dir_pw_thread:yield", dir_pw_random, ] sources = [ "synchronized_allocator_test.cc" ] } pw_test("tracking_allocator_test") { deps = [ ":testing", ":tracking_allocator", ] sources = [ "tracking_allocator_test.cc" ] } pw_test("typed_pool_test") { deps = [ ":typed_pool", "$dir_pw_bytes:alignment", ] sources = [ "typed_pool_test.cc" ] } pw_test("unique_ptr_test") { deps = [ ":testing" ] sources = [ "unique_ptr_test.cc" ] } pw_test("worst_fit_block_allocator_test") { deps = [ ":block_allocator_testing", ":worst_fit_block_allocator", ] sources = [ "worst_fit_block_allocator_test.cc" ] } pw_test_group("tests") { tests = [ ":allocator_as_pool_test", ":allocator_test", ":as_pmr_allocator_test", ":best_fit_block_allocator_test", ":block_test", ":bucket_block_allocator_test", ":buddy_allocator_test", ":buffer_test", ":bump_allocator_test", ":chunk_pool_test", ":dual_first_fit_block_allocator_test", ":fallback_allocator_test", ":first_fit_block_allocator_test", ":fragmentation_test", ":freelist_test", ":freelist_heap_test", ":last_fit_block_allocator_test", ":libc_allocator_test", ":null_allocator_test", ":typed_pool_test", ":synchronized_allocator_test", ":tracking_allocator_test", ":unique_ptr_test", ":worst_fit_block_allocator_test", ] group_deps = [ "examples" ] } # Docs pw_source_set("size_reporter") { public_configs = [ ":default_config" ] public = [ "public/pw_allocator/size_reporter.h" ] public_deps = [ ":null_allocator", "$dir_pw_bloat:bloat_this_binary", dir_pw_bytes, ] } pw_size_diff("allocator_api_size_report") { title = "Size of an empty implmentation of the Allocator interface" binaries = [ { target = "size_report:null_allocator" base = "size_report:base" label = "NullAllocator" }, ] } pw_size_diff("concrete_allocators_size_report") { title = "Sizes of various concrete allocator implementations" binaries = [ { target = "size_report:best_fit_block_allocator" base = "size_report:null_allocator" label = "BestFitBlockAllocator" }, { target = "size_report:buddy_allocator" base = "size_report:null_allocator" label = "BuddyAllocator" }, { target = "size_report:bump_allocator" base = "size_report:null_allocator" label = "BumpAllocator" }, { target = "size_report:dual_first_fit_block_allocator" base = "size_report:null_allocator" label = "DualFirstFitBlockAllocator" }, { target = "size_report:first_fit_block_allocator" base = "size_report:null_allocator" label = "FirstFitBlockAllocator" }, { target = "size_report:last_fit_block_allocator" base = "size_report:null_allocator" label = "LastFitBlockAllocator" }, { target = "size_report:libc_allocator" base = "size_report:null_allocator" label = "LibCAllocator" }, { target = "size_report:worst_fit_block_allocator" base = "size_report:null_allocator" label = "WorstFitBlockAllocator" }, ] } pw_size_diff("forwarding_allocators_size_report") { title = "Sizes of various forwarding allocator implementations" binaries = [ { target = "size_report:as_pmr_allocator" base = "size_report:as_pmr_allocator_base" label = "AsPmrAllocator" }, { target = "size_report:fallback_allocator" base = "size_report:fallback_allocator_base" label = "FallbackAllocator" }, { target = "size_report:synchronized_allocator_isl" base = "size_report:first_fit_block_allocator" label = "SynchronizedAllocator" }, { target = "size_report:synchronized_allocator_mutex" base = "size_report:first_fit_block_allocator" label = "SynchronizedAllocator" }, { target = "size_report:tracking_allocator_all_metrics" base = "size_report:first_fit_block_allocator" label = "TrackingAllocator" }, { target = "size_report:tracking_allocator_no_metrics" base = "size_report:first_fit_block_allocator" label = "TrackingAllocator" }, ] } pw_size_diff("allocator_utilities_size_report") { title = "Sizes of various allocator utility classes" binaries = [ { target = "size_report:unique_ptr" base = "size_report:first_fit_block_allocator" label = "UniquePtr" }, ] } pw_doc_group("docs") { inputs = [ "doc_resources/pw_allocator_heap_visualizer_demo.png", "examples/basic.cc", "examples/block_allocator.cc", "examples/custom_allocator_perf_test.cc", "examples/custom_allocator_test_harness.h", "examples/custom_allocator_test.cc", "examples/custom_allocator.cc", "examples/custom_allocator.h", "examples/linker_sections.cc", "examples/metrics.cc", "examples/pmr.cc", "examples/size_report.cc", "examples/spin_lock.cc", ] sources = [ "api.rst", "code_size.rst", "design.rst", "docs.rst", "guide.rst", ] report_deps = [ ":allocator_api_size_report", ":concrete_allocators_size_report", ":forwarding_allocators_size_report", "examples:custom_allocator_size_report", ] }