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 15import("//build_overrides/pigweed.gni") 16 17import("$dir_pw_bloat/bloat.gni") 18import("$dir_pw_build/module_config.gni") 19import("$dir_pw_build/target_types.gni") 20import("$dir_pw_docgen/docs.gni") 21import("$dir_pw_unit_test/test.gni") 22 23declare_args() { 24 # The build target that overrides the default configuration options for this 25 # module. This should point to a source set that provides defines through a 26 # public config (which may -include a file or add defines directly). 27 pw_string_CONFIG = pw_build_DEFAULT_MODULE_CONFIG 28} 29 30config("public_include_path") { 31 include_dirs = [ "public" ] 32} 33 34config("enable_decimal_float_expansion_config") { 35 defines = [ "PW_STRING_ENABLE_DECIMAL_FLOAT_EXPANSION=1" ] 36} 37 38pw_source_set("enable_decimal_float_expansion") { 39 public_configs = [ ":enable_decimal_float_expansion_config" ] 40} 41 42pw_source_set("config") { 43 public = [ "public/pw_string/internal/config.h" ] 44 public_configs = [ ":public_include_path" ] 45 public_deps = [ pw_string_CONFIG ] 46} 47 48group("pw_string") { 49 public_deps = [ 50 ":builder", 51 ":format", 52 ":to_string", 53 ] 54} 55 56pw_source_set("builder") { 57 public_configs = [ ":public_include_path" ] 58 public = [ "public/pw_string/string_builder.h" ] 59 sources = [ "string_builder.cc" ] 60 public_deps = [ 61 ":format", 62 ":string", 63 ":to_string", 64 ":util", 65 dir_pw_preprocessor, 66 dir_pw_span, 67 dir_pw_status, 68 ] 69 70 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 71 configs = [ "$dir_pw_build:conversion_warnings" ] 72} 73 74pw_source_set("format") { 75 public_configs = [ ":public_include_path" ] 76 public = [ "public/pw_string/format.h" ] 77 sources = [ "format.cc" ] 78 public_deps = [ 79 ":string", 80 dir_pw_preprocessor, 81 dir_pw_span, 82 dir_pw_status, 83 ] 84 85 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 86 configs = [ "$dir_pw_build:conversion_warnings" ] 87} 88 89pw_source_set("string") { 90 public_configs = [ ":public_include_path" ] 91 public = [ "public/pw_string/string.h" ] 92 sources = [ 93 "public/pw_string/internal/string_common_functions.inc", 94 "public/pw_string/internal/string_impl.h", 95 ] 96 public_deps = [ dir_pw_assert ] 97 98 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 99 configs = [ "$dir_pw_build:conversion_warnings" ] 100} 101 102pw_source_set("to_string") { 103 public_configs = [ ":public_include_path" ] 104 public = [ 105 "public/pw_string/to_string.h", 106 "public/pw_string/type_to_string.h", 107 ] 108 sources = [ "type_to_string.cc" ] 109 public_deps = [ 110 ":config", 111 ":format", 112 ":util", 113 "$dir_pw_third_party/fuchsia:stdcompat", 114 dir_pw_result, 115 dir_pw_span, 116 dir_pw_status, 117 ] 118 119 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 120 configs = [ "$dir_pw_build:conversion_warnings" ] 121} 122 123pw_source_set("utf_codecs") { 124 public_configs = [ ":public_include_path" ] 125 public = [ "public/pw_string/utf_codecs.h" ] 126 sources = [ "utf_codecs.cc" ] 127 public_deps = [ 128 ":builder", 129 dir_pw_assert, 130 dir_pw_result, 131 dir_pw_span, 132 dir_pw_status, 133 ] 134} 135 136pw_source_set("util") { 137 public_configs = [ ":public_include_path" ] 138 public = [ "public/pw_string/util.h" ] 139 sources = [ "public/pw_string/internal/length.h" ] 140 public_deps = [ 141 ":string", 142 dir_pw_assert, 143 dir_pw_result, 144 dir_pw_span, 145 dir_pw_status, 146 ] 147} 148 149pw_test_group("tests") { 150 tests = [ 151 ":string_test", 152 ":format_test", 153 ":string_builder_test", 154 ":to_string_test", 155 ":type_to_string_test", 156 ":utf_codecs_test", 157 ":util_test", 158 ] 159 group_deps = [ 160 "$dir_pw_preprocessor:tests", 161 "$dir_pw_status:tests", 162 ] 163} 164 165pw_test("format_test") { 166 deps = [ ":format" ] 167 sources = [ "format_test.cc" ] 168 169 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 170 configs = [ "$dir_pw_build:conversion_warnings" ] 171} 172 173pw_test("string_test") { 174 deps = [ ":string" ] 175 sources = [ "string_test.cc" ] 176 negative_compilation_tests = true 177 178 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 179 configs = [ "$dir_pw_build:conversion_warnings" ] 180} 181 182pw_test("string_builder_test") { 183 deps = [ ":builder" ] 184 sources = [ "string_builder_test.cc" ] 185 186 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 187 configs = [ "$dir_pw_build:conversion_warnings" ] 188} 189 190pw_test("to_string_test") { 191 deps = [ 192 ":config", 193 ":pw_string", 194 ] 195 sources = [ "to_string_test.cc" ] 196 197 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 198 configs = [ "$dir_pw_build:conversion_warnings" ] 199} 200 201pw_test("type_to_string_test") { 202 deps = [ ":to_string" ] 203 sources = [ "type_to_string_test.cc" ] 204 205 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 206 configs = [ "$dir_pw_build:conversion_warnings" ] 207} 208 209pw_test("utf_codecs_test") { 210 deps = [ ":utf_codecs" ] 211 sources = [ "utf_codecs_test.cc" ] 212} 213 214pw_test("util_test") { 215 deps = [ ":util" ] 216 sources = [ "util_test.cc" ] 217 218 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 219 configs = [ "$dir_pw_build:conversion_warnings" ] 220} 221 222pw_doc_group("docs") { 223 inputs = [ "Kconfig" ] 224 sources = [ 225 "api.rst", 226 "code_size.rst", 227 "design.rst", 228 "docs.rst", 229 "guide.rst", 230 ] 231 report_deps = [ 232 ":format_size_report", 233 ":string_builder_size_report", 234 ] 235} 236 237pw_size_diff("format_size_report") { 238 title = "Using pw::string::Format instead of snprintf" 239 240 binaries = [ 241 { 242 target = "size_report:single_write_format" 243 base = "size_report:single_write_snprintf" 244 label = "Format instead of snprintf once, return size" 245 }, 246 { 247 target = "size_report:multiple_writes_format" 248 base = "size_report:multiple_writes_snprintf" 249 label = "Format instead of snprintf 10 times, handle errors" 250 }, 251 { 252 target = "size_report:many_writes_format" 253 base = "size_report:many_writes_snprintf" 254 label = "Format instead of snprintf 50 times, no error handling" 255 }, 256 ] 257} 258 259pw_size_diff("string_builder_size_report") { 260 title = "Using pw::StringBuilder instead of snprintf" 261 262 binaries = [ 263 { 264 target = "size_report:build_string_with_string_builder" 265 base = "size_report:build_string_with_snprintf" 266 label = "Total StringBuilder cost when used alongside snprintf" 267 }, 268 { 269 target = "size_report:build_string_with_string_builder_no_base_snprintf" 270 base = "size_report:build_string_with_snprintf_no_base_snprintf" 271 label = "StringBuilder cost when completely replacing snprintf" 272 }, 273 { 274 target = "size_report:build_string_incremental_with_string_builder" 275 base = "size_report:build_string_incremental_with_snprintf" 276 label = "Incremental cost relative to snprintf for 10 strings" 277 }, 278 ] 279} 280