1# Copyright 2019 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_size_diff.bzl", "pw_size_diff") 18load("//pw_bloat:pw_size_table.bzl", "pw_size_table") 19load("//pw_build:compatibility.bzl", "incompatible_with_mcu") 20load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test") 21 22package( 23 default_visibility = ["//visibility:public"], 24 features = ["-layering_check"], 25) 26 27licenses(["notice"]) 28 29cc_library( 30 name = "config", 31 hdrs = ["public/pw_string/internal/config.h"], 32 strip_include_prefix = "public", 33 deps = [":config_override"], 34) 35 36label_flag( 37 name = "config_override", 38 build_setting_default = "//pw_build:default_module_config", 39) 40 41cc_library( 42 name = "pw_string", 43 deps = [ 44 ":builder", 45 ":format", 46 ":to_string", 47 ":util", 48 ], 49) 50 51cc_library( 52 name = "builder", 53 srcs = ["string_builder.cc"], 54 hdrs = ["public/pw_string/string_builder.h"], 55 strip_include_prefix = "public", 56 deps = [ 57 ":format", 58 ":string", 59 ":to_string", 60 ":util", 61 "//pw_preprocessor", 62 "//pw_span", 63 "//pw_status", 64 ], 65) 66 67cc_library( 68 name = "format", 69 srcs = ["format.cc"], 70 hdrs = ["public/pw_string/format.h"], 71 strip_include_prefix = "public", 72 deps = [ 73 ":string", 74 "//pw_preprocessor", 75 "//pw_span", 76 "//pw_status", 77 ], 78) 79 80cc_library( 81 name = "string", 82 hdrs = [ 83 "public/pw_string/internal/string_common_functions.inc", 84 "public/pw_string/internal/string_impl.h", 85 "public/pw_string/string.h", 86 ], 87 strip_include_prefix = "public", 88 tags = ["noclangtidy"], 89 deps = [ 90 "//pw_assert:assert", 91 "//pw_preprocessor", 92 ], 93) 94 95cc_library( 96 name = "to_string", 97 srcs = ["type_to_string.cc"], 98 hdrs = [ 99 "public/pw_string/to_string.h", 100 "public/pw_string/type_to_string.h", 101 ], 102 strip_include_prefix = "public", 103 deps = [ 104 ":config", 105 ":format", 106 ":util", 107 "//pw_result", 108 "//pw_span", 109 "//pw_status", 110 "//third_party/fuchsia:stdcompat", 111 ], 112) 113 114cc_library( 115 name = "utf_codecs", 116 srcs = ["utf_codecs.cc"], 117 hdrs = ["public/pw_string/utf_codecs.h"], 118 strip_include_prefix = "public", 119 deps = [ 120 ":builder", 121 "//pw_result", 122 "//pw_span", 123 "//pw_status", 124 ], 125) 126 127cc_library( 128 name = "util", 129 hdrs = [ 130 "public/pw_string/internal/length.h", 131 "public/pw_string/util.h", 132 ], 133 strip_include_prefix = "public", 134 deps = [ 135 ":string", 136 "//pw_assert:assert", 137 "//pw_result", 138 "//pw_span", 139 "//pw_status", 140 ], 141) 142 143pw_cc_test( 144 name = "format_test", 145 srcs = ["format_test.cc"], 146 deps = [ 147 ":format", 148 "//pw_span", 149 ], 150) 151 152pw_cc_test( 153 name = "string_test", 154 srcs = ["string_test.cc"], 155 deps = [ 156 ":string", 157 "//pw_compilation_testing:negative_compilation_testing", 158 ], 159) 160 161pw_cc_test( 162 name = "type_to_string_test", 163 srcs = ["type_to_string_test.cc"], 164 deps = [":to_string"], 165) 166 167pw_cc_test( 168 name = "string_builder_test", 169 srcs = ["string_builder_test.cc"], 170 deps = [":builder"], 171) 172 173pw_cc_test( 174 name = "to_string_test", 175 srcs = ["to_string_test.cc"], 176 deps = [ 177 ":config", 178 ":to_string", 179 "//pw_status", 180 ], 181) 182 183pw_cc_test( 184 name = "utf_codecs_test", 185 srcs = ["utf_codecs_test.cc"], 186 deps = [":utf_codecs"], 187) 188 189pw_cc_test( 190 name = "util_test", 191 srcs = ["util_test.cc"], 192 deps = [":util"], 193) 194 195filegroup( 196 name = "doxygen", 197 srcs = [ 198 "public/pw_string/format.h", 199 "public/pw_string/string.h", 200 "public/pw_string/string_builder.h", 201 "public/pw_string/utf_codecs.h", 202 "public/pw_string/util.h", 203 ], 204) 205 206sphinx_docs_library( 207 name = "docs", 208 srcs = [ 209 "Kconfig", 210 "api.rst", 211 "code_size.rst", 212 "design.rst", 213 "docs.rst", 214 "guide.rst", 215 ":string_builder_size_report", 216 ], 217 prefix = "pw_string/", 218 target_compatible_with = incompatible_with_mcu(), 219) 220 221pw_size_diff( 222 name = "string_builder_size_report_both", 223 base = "//pw_string/size_report:build_string_with_snprintf", 224 label = "Total StringBuilder cost when used alongside snprintf", 225 # TODO: https://pwbug.dev/388905812 - Make size reports always build. 226 tags = ["manual"], 227 target = "//pw_string/size_report:build_string_with_string_builder", 228) 229 230pw_size_diff( 231 name = "string_builder_size_report_replace", 232 base = "//pw_string/size_report:build_string_with_snprintf_no_base_snprintf", 233 label = "StringBuilder cost when completely replacing snprintf", 234 # TODO: https://pwbug.dev/388905812 - Make size reports always build. 235 tags = ["manual"], 236 target = "//pw_string/size_report:build_string_with_string_builder_no_base_snprintf", 237) 238 239pw_size_diff( 240 name = "string_builder_size_report_incremental", 241 base = "//pw_string/size_report:build_string_incremental_with_snprintf", 242 label = "Incremental cost relative to snprintf for 10 strings", 243 # TODO: https://pwbug.dev/388905812 - Make size reports always build. 244 tags = ["manual"], 245 target = "//pw_string/size_report:build_string_incremental_with_string_builder", 246) 247 248pw_size_table( 249 name = "string_builder_size_report", 250 reports = [ 251 ":string_builder_size_report_both", 252 ":string_builder_size_report_replace", 253 ":string_builder_size_report_incremental", 254 ], 255 # TODO: https://pwbug.dev/388905812 - Make size reports always build. 256 tags = ["manual"], 257) 258