blob: 0f7b970e7d735c2cf51d23b18ed1699608b7116c [file] [log] [blame]
# 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_deps = [
":deallocator",
dir_pw_result,
]
sources = [ "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("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" ]
}
pw_source_set("block_allocator") {
public_configs = [ ":default_config" ]
public = [ "public/pw_allocator/block_allocator.h" ]
public_deps = [
":allocator",
":block",
dir_pw_bytes,
dir_pw_result,
dir_pw_status,
]
deps = [ dir_pw_assert ]
sources = [ "block_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" ]
sources = [ "buffer.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",
]
sources = [ "chunk_pool.cc" ]
}
pw_source_set("deallocator") {
sources = [
"deallocator.cc",
"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("fallback_allocator") {
public_configs = [ ":default_config" ]
public = [ "public/pw_allocator/fallback_allocator.h" ]
public_deps = [
":allocator",
":tracking_allocator",
dir_pw_metric,
dir_pw_result,
dir_pw_status,
dir_pw_tokenizer,
]
}
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("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" ]
}
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,
]
}
# Test support
pw_source_set("testing") {
public = [ "public/pw_allocator/testing.h" ]
public_deps = [
":allocator",
":block",
":block_allocator",
":buffer",
":tracking_allocator",
dir_pw_bytes,
dir_pw_result,
dir_pw_status,
dir_pw_unit_test,
]
deps = [ dir_pw_assert ]
}
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("block_test") {
deps = [
":block",
dir_pw_span,
]
sources = [ "block_test.cc" ]
# TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; hangs
# indefinitely.
if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") {
enable_if = false
}
}
pw_test("block_allocator_test") {
deps = [
":block",
":block_allocator",
":buffer",
dir_pw_bytes,
]
sources = [ "block_allocator_test.cc" ]
# TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; hangs
# indefinitely.
if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") {
enable_if = false
}
}
pw_test("buffer_test") {
deps = [
":buffer",
dir_pw_bytes,
dir_pw_result,
]
sources = [ "buffer_test.cc" ]
}
pw_test("chunk_pool_test") {
deps = [
":chunk_pool",
":testing",
]
sources = [ "chunk_pool_test.cc" ]
}
pw_test("fallback_allocator_test") {
deps = [
":fallback_allocator",
":testing",
dir_pw_status,
]
sources = [ "fallback_allocator_test.cc" ]
}
pw_test("freelist_test") {
deps = [
":freelist",
dir_pw_span,
dir_pw_status,
]
sources = [ "freelist_test.cc" ]
# TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; hangs
# indefinitely.
if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") {
enable_if = false
}
}
pw_test("freelist_heap_test") {
deps = [ ":freelist_heap" ]
sources = [ "freelist_heap_test.cc" ]
# TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; after test
# finishes device locks up.
if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") {
enable_if = false
}
}
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" ]
# TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; hangs
# indefinitely.
enable_if = pw_build_EXECUTABLE_TARGET_TYPE != "pico_executable"
}
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_group("tests") {
tests = [
":allocator_as_pool_test",
":allocator_test",
":block_allocator_test",
":block_test",
":buffer_test",
":chunk_pool_test",
":fallback_allocator_test",
":freelist_test",
":freelist_heap_test",
":libc_allocator_test",
":null_allocator_test",
":typed_pool_test",
":synchronized_allocator_test",
":tracking_allocator_test",
":unique_ptr_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: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: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<sync::InterruptSpinLock>"
},
{
target = "size_report:synchronized_allocator_mutex"
base = "size_report:first_fit_block_allocator"
label = "SynchronizedAllocator<sync::Mutex>"
},
{
target = "size_report:tracking_allocator_all_metrics"
base = "size_report:first_fit_block_allocator"
label = "TrackingAllocator<AllMetrics>"
},
{
target = "size_report:tracking_allocator_no_metrics"
base = "size_report:first_fit_block_allocator"
label = "TrackingAllocator<NoMetrics>"
},
]
}
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/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",
]
}