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 15load("@rules_cc//cc:cc_library.bzl", "cc_library") 16load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library") 17load("//pw_bloat:pw_cc_size_binary.bzl", "pw_cc_size_binary") 18load("//pw_build:compatibility.bzl", "incompatible_with_mcu") 19 20package(default_visibility = ["//visibility:public"]) 21 22licenses(["notice"]) 23 24cc_library( 25 name = "hardening_none", 26 defines = ["PW_ALLOCATOR_HARDENING=0"], 27) 28 29# Size reporting support libraries. 30 31cc_library( 32 name = "size_report", 33 srcs = ["size_report.cc"], 34 hdrs = ["public/pw_allocator/size_report/size_report.h"], 35 implementation_deps = ["//pw_bytes:alignment"], 36 strip_include_prefix = "public", 37 deps = [ 38 "//pw_allocator", 39 "//pw_allocator:block_allocator", 40 "//pw_allocator/block:small_block", 41 "//pw_bloat:bloat_this_binary", 42 "//pw_bytes", 43 ], 44) 45 46_size_report_deps = [ 47 ":hardening_none", 48 ":size_report", 49 "//pw_bloat:bloat_this_binary", 50] 51 52# Baseline executables for size reporting. 53 54pw_cc_size_binary( 55 name = "base", 56 srcs = ["base.cc"], 57 deps = _size_report_deps, 58) 59 60# Block binaries to be measured for code size. 61 62pw_cc_size_binary( 63 name = "detailed_block", 64 srcs = ["detailed_block.cc"], 65 deps = _size_report_deps + [ 66 "//pw_allocator/block:detailed_block", 67 "//pw_allocator/bucket:fast_sorted", 68 ], 69) 70 71_small_block_deps = [ 72 ":size_report", 73 "//pw_allocator/block:small_block", 74 "//pw_bloat:bloat_this_binary", 75] 76 77pw_cc_size_binary( 78 name = "small_block", 79 srcs = ["small_block.cc"], 80 deps = _small_block_deps + [":hardening_none"], 81) 82 83pw_cc_size_binary( 84 name = "small_alignable_block", 85 srcs = ["small_alignable_block.cc"], 86 deps = _size_report_deps + ["//pw_allocator/block:small_alignable_block"], 87) 88 89pw_cc_size_binary( 90 name = "tiny_block", 91 srcs = ["tiny_block.cc"], 92 deps = _size_report_deps + ["//pw_allocator/block:tiny_block"], 93) 94 95pw_cc_size_binary( 96 name = "small_block_basic", 97 srcs = ["small_block.cc"], 98 deps = _small_block_deps + ["//pw_allocator:hardening_basic"], 99) 100 101pw_cc_size_binary( 102 name = "small_block_robust", 103 srcs = ["small_block.cc"], 104 deps = _small_block_deps + ["//pw_allocator:hardening_robust"], 105) 106 107pw_cc_size_binary( 108 name = "small_block_debug", 109 srcs = ["small_block.cc"], 110 deps = _small_block_deps + ["//pw_allocator:hardening_debug"], 111) 112 113# Bucket binaries to be measured for code size. 114 115_fast_sorted_deps = _size_report_deps + [ 116 "//pw_allocator/bucket:fast_sorted", 117 "//pw_containers/size_report:intrusive_multimap", 118 "//pw_containers/size_report:size_report", 119] 120 121pw_cc_size_binary( 122 name = "fast_sorted_base", 123 srcs = ["fast_sorted_bucket.cc"], 124 defines = ["PW_ALLOCATOR_SIZE_REPORT_BASE"], 125 deps = _fast_sorted_deps, 126) 127 128pw_cc_size_binary( 129 name = "fast_sorted", 130 srcs = ["fast_sorted_bucket.cc"], 131 deps = _fast_sorted_deps, 132) 133 134_sequenced_deps = _size_report_deps + [ 135 "//pw_allocator/bucket:sequenced", 136 "//pw_containers/size_report:intrusive_list", 137 "//pw_containers/size_report:size_report", 138] 139 140pw_cc_size_binary( 141 name = "sequenced_base", 142 srcs = ["sequenced_bucket.cc"], 143 defines = ["PW_ALLOCATOR_SIZE_REPORT_BASE"], 144 deps = _sequenced_deps, 145) 146 147pw_cc_size_binary( 148 name = "sequenced", 149 srcs = ["sequenced_bucket.cc"], 150 deps = _sequenced_deps, 151) 152 153_sorted_deps = _size_report_deps + [ 154 "//pw_allocator/bucket:sorted", 155 "//pw_containers/size_report:intrusive_forward_list", 156 "//pw_containers/size_report:size_report", 157] 158 159pw_cc_size_binary( 160 name = "sorted_base", 161 srcs = ["sorted_bucket.cc"], 162 defines = ["PW_ALLOCATOR_SIZE_REPORT_BASE"], 163 deps = _sorted_deps, 164) 165 166pw_cc_size_binary( 167 name = "sorted", 168 srcs = ["sorted_bucket.cc"], 169 deps = _sorted_deps, 170) 171 172_unordered_deps = _size_report_deps + [ 173 "//pw_allocator/bucket:unordered", 174 "//pw_containers/size_report:intrusive_forward_list", 175 "//pw_containers/size_report:size_report", 176] 177 178pw_cc_size_binary( 179 name = "unordered_base", 180 srcs = ["unordered_bucket.cc"], 181 defines = ["PW_ALLOCATOR_SIZE_REPORT_BASE"], 182 deps = _unordered_deps, 183) 184 185pw_cc_size_binary( 186 name = "unordered", 187 srcs = ["unordered_bucket.cc"], 188 deps = _unordered_deps, 189) 190 191# Concrete allocator binaries to be measured for code size. 192 193pw_cc_size_binary( 194 name = "best_fit", 195 srcs = ["best_fit.cc"], 196 deps = _size_report_deps + ["//pw_allocator:best_fit"], 197) 198 199pw_cc_size_binary( 200 name = "bucket_allocator", 201 srcs = ["bucket_allocator.cc"], 202 deps = _size_report_deps + ["//pw_allocator:bucket_allocator"], 203) 204 205pw_cc_size_binary( 206 name = "buddy_allocator", 207 srcs = ["buddy_allocator.cc"], 208 deps = _size_report_deps + [ 209 "//pw_allocator:buddy_allocator", 210 "//pw_status", 211 ], 212) 213 214pw_cc_size_binary( 215 name = "bump_allocator", 216 srcs = ["bump_allocator.cc"], 217 deps = _size_report_deps + ["//pw_allocator:bump_allocator"], 218) 219 220pw_cc_size_binary( 221 name = "dl_allocator", 222 srcs = ["dl_allocator.cc"], 223 deps = _size_report_deps + ["//pw_allocator:dl_allocator"], 224) 225 226pw_cc_size_binary( 227 name = "first_fit", 228 srcs = ["first_fit.cc"], 229 deps = _size_report_deps + ["//pw_allocator:first_fit"], 230) 231 232pw_cc_size_binary( 233 name = "libc_allocator", 234 srcs = ["libc_allocator.cc"], 235 deps = _size_report_deps + ["//pw_allocator:libc_allocator"], 236) 237 238pw_cc_size_binary( 239 name = "null_allocator", 240 srcs = ["null_allocator.cc"], 241 deps = _size_report_deps + ["//pw_allocator:null_allocator"], 242) 243 244pw_cc_size_binary( 245 name = "tlsf_allocator", 246 srcs = ["tlsf_allocator.cc"], 247 deps = _size_report_deps + ["//pw_allocator:tlsf_allocator"], 248) 249 250pw_cc_size_binary( 251 name = "worst_fit", 252 srcs = ["worst_fit.cc"], 253 deps = _size_report_deps + ["//pw_allocator:worst_fit"], 254) 255 256# Forwarding allocator binaries to be measured for code size. 257 258pw_cc_size_binary( 259 name = "fallback_allocator", 260 srcs = ["fallback_allocator.cc"], 261 deps = _size_report_deps + [ 262 "//pw_allocator:best_fit", 263 "//pw_allocator:fallback_allocator", 264 "//pw_bytes", 265 ], 266) 267 268_pmr_allocator_base_deps = _size_report_deps + [ 269 "//pw_allocator:best_fit", 270 "//pw_allocator/block:detailed_block", 271] 272 273pw_cc_size_binary( 274 name = "pmr_allocator_base", 275 srcs = ["pmr_allocator.cc"], 276 defines = ["PW_ALLOCATOR_SIZE_REPORT_BASE"], 277 deps = _pmr_allocator_base_deps, 278) 279 280pw_cc_size_binary( 281 name = "pmr_allocator", 282 srcs = ["pmr_allocator.cc"], 283 deps = _pmr_allocator_base_deps + ["//pw_allocator:pmr_allocator"], 284) 285 286_synchronized_allocator_deps = _size_report_deps + [ 287 "//pw_allocator:best_fit", 288 "//pw_allocator:synchronized_allocator", 289] 290 291pw_cc_size_binary( 292 name = "synchronized_allocator_isl", 293 srcs = ["synchronized_allocator_isl.cc"], 294 deps = _synchronized_allocator_deps + ["//pw_sync:interrupt_spin_lock"], 295) 296 297pw_cc_size_binary( 298 name = "synchronized_allocator_mutex", 299 srcs = ["synchronized_allocator_mutex.cc"], 300 deps = _synchronized_allocator_deps + ["//pw_sync:mutex"], 301) 302 303_tracking_allocator_deps = _size_report_deps + [ 304 "//pw_allocator:best_fit", 305 "//pw_allocator:metrics", 306 "//pw_allocator:tracking_allocator", 307 "//pw_allocator/block:detailed_block", 308] 309 310pw_cc_size_binary( 311 name = "tracking_allocator_all_metrics", 312 srcs = ["tracking_allocator_all_metrics.cc"], 313 deps = _tracking_allocator_deps, 314) 315 316pw_cc_size_binary( 317 name = "tracking_allocator_no_metrics", 318 srcs = ["tracking_allocator_no_metrics.cc"], 319 deps = _tracking_allocator_deps, 320) 321 322filegroup( 323 name = "doxygen", 324 srcs = ["public/pw_allocator/size_report/size_report.h"], 325) 326 327sphinx_docs_library( 328 name = "docs", 329 prefix = "pw_allocator/size_report/", 330 target_compatible_with = incompatible_with_mcu(), 331) 332