1# Copyright 2024 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_build:pw_cc_binary.bzl", "pw_cc_binary") 19load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test") 20 21package(default_visibility = ["//visibility:public"]) 22 23licenses(["notice"]) 24 25# Libraries 26 27cc_library( 28 name = "named_u32", 29 testonly = True, 30 hdrs = ["public/examples/named_u32.h"], 31 strip_include_prefix = "public", 32 deps = [ 33 "//pw_bytes", 34 "//pw_string", 35 ], 36) 37 38cc_library( 39 name = "custom_allocator", 40 testonly = True, 41 srcs = ["custom_allocator.cc"], 42 hdrs = ["public/examples/custom_allocator.h"], 43 strip_include_prefix = "public", 44 deps = [ 45 "//pw_allocator", 46 "//pw_log", 47 "//pw_result", 48 ], 49) 50 51cc_library( 52 name = "custom_allocator_test_harness", 53 testonly = True, 54 hdrs = ["public/examples/custom_allocator_test_harness.h"], 55 strip_include_prefix = "public", 56 deps = [ 57 ":custom_allocator", 58 "//pw_allocator:test_harness", 59 "//pw_allocator:testing", 60 ], 61) 62 63# Examples 64 65pw_cc_test( 66 name = "basic", 67 srcs = ["basic.cc"], 68 deps = [ 69 ":named_u32", 70 "//pw_allocator", 71 "//pw_allocator:testing", 72 ], 73) 74 75pw_cc_test( 76 name = "block_allocator", 77 srcs = ["block_allocator.cc"], 78 deps = [ 79 ":named_u32", 80 "//pw_allocator:first_fit", 81 ], 82) 83 84pw_cc_test( 85 name = "custom_allocator_perf_test", 86 srcs = ["custom_allocator_perf_test.cc"], 87 deps = [ 88 ":custom_allocator_test_harness", 89 "//pw_perf_test", 90 "//pw_perf_test:state", 91 "//pw_random", 92 ], 93) 94 95pw_cc_test( 96 name = "custom_allocator_test", 97 srcs = ["custom_allocator_test.cc"], 98 deps = [ 99 ":custom_allocator", 100 ":custom_allocator_test_harness", 101 ":named_u32", 102 "//pw_allocator:fuzzing", 103 "//pw_allocator:testing", 104 "//pw_containers:vector", 105 "//pw_fuzzer:fuzztest", 106 ], 107) 108 109pw_cc_test( 110 name = "linker_sections", 111 srcs = ["linker_sections.cc"], 112 deps = [ 113 ":named_u32", 114 "//pw_allocator", 115 "//pw_allocator:first_fit", 116 "//pw_allocator:worst_fit", 117 "//pw_allocator/block:detailed_block", 118 ], 119) 120 121pw_cc_test( 122 name = "metrics", 123 srcs = ["metrics.cc"], 124 deps = [ 125 ":named_u32", 126 "//pw_allocator:metrics", 127 "//pw_allocator:testing", 128 "//pw_allocator:tracking_allocator", 129 "//pw_tokenizer", 130 ], 131) 132 133pw_cc_test( 134 name = "pmr", 135 testonly = True, 136 srcs = ["pmr.cc"], 137 deps = [ 138 "//pw_allocator", 139 "//pw_allocator:pmr_allocator", 140 "//pw_allocator:testing", 141 ], 142) 143 144pw_cc_binary( 145 name = "size_report", 146 testonly = True, 147 srcs = ["size_report.cc"], 148 deps = [ 149 ":custom_allocator", 150 "//pw_allocator:best_fit", 151 "//pw_allocator/size_report", 152 "//pw_bloat:bloat_this_binary", 153 ], 154) 155 156pw_cc_test( 157 name = "spin_lock", 158 srcs = ["spin_lock.cc"], 159 # TODO: b/358411629 - This test times out on rp2. 160 target_compatible_with = select({ 161 "@pico-sdk//bazel/constraint:rp2040": ["@platforms//:incompatible"], 162 "@pico-sdk//bazel/constraint:rp2350": ["@platforms//:incompatible"], 163 "//conditions:default": [], 164 }), 165 deps = [ 166 ":named_u32", 167 "//pw_allocator:synchronized_allocator", 168 "//pw_allocator:testing", 169 "//pw_assert:check", 170 "//pw_sync:interrupt_spin_lock", 171 "//pw_thread:test_thread_context", 172 "//pw_thread:thread", 173 "//pw_thread:thread_core", 174 ], 175) 176 177sphinx_docs_library( 178 name = "docs", 179 srcs = [ 180 "basic.cc", 181 "block_allocator.cc", 182 "custom_allocator.cc", 183 "custom_allocator_perf_test.cc", 184 "custom_allocator_test.cc", 185 "linker_sections.cc", 186 "metrics.cc", 187 "pmr.cc", 188 "public/examples/custom_allocator.h", 189 "public/examples/custom_allocator_test_harness.h", 190 "size_report.cc", 191 "spin_lock.cc", 192 ], 193 target_compatible_with = incompatible_with_mcu(), 194) 195