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_python//python:proto.bzl", "py_proto_library") 16load( 17 "//pw_build:pigweed.bzl", 18 "pw_cc_binary", 19 "pw_cc_blob_info", 20 "pw_cc_blob_library", 21 "pw_cc_test", 22 "pw_linker_script", 23) 24load("//pw_build:selects.bzl", "TARGET_COMPATIBLE_WITH_HOST_SELECT") 25load("//pw_fuzzer:fuzzer.bzl", "pw_cc_fuzz_test") 26 27package(default_visibility = ["//visibility:public"]) 28 29licenses(["notice"]) 30 31cc_library( 32 name = "pw_tokenizer", 33 srcs = [ 34 "encode_args.cc", 35 "hash.cc", 36 "public/pw_tokenizer/config.h", 37 "public/pw_tokenizer/internal/argument_types.h", 38 "public/pw_tokenizer/internal/argument_types_macro_4_byte.h", 39 "public/pw_tokenizer/internal/argument_types_macro_8_byte.h", 40 "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_128_hash_macro.h", 41 "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_256_hash_macro.h", 42 "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_80_hash_macro.h", 43 "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_96_hash_macro.h", 44 "public/pw_tokenizer/internal/tokenize_string.h", 45 "tokenize.cc", 46 ], 47 hdrs = [ 48 "public/pw_tokenizer/encode_args.h", 49 "public/pw_tokenizer/hash.h", 50 "public/pw_tokenizer/nested_tokenization.h", 51 "public/pw_tokenizer/tokenize.h", 52 ], 53 includes = ["public"], 54 deps = [ 55 ":config_override", 56 "//pw_bytes:bit", 57 "//pw_containers:to_array", 58 "//pw_polyfill", 59 "//pw_preprocessor", 60 "//pw_span", 61 "//pw_varint", 62 ], 63) 64 65label_flag( 66 name = "config_override", 67 build_setting_default = "//pw_build:default_module_config", 68) 69 70pw_linker_script( 71 name = "linker_script", 72 linker_script = "pw_tokenizer_linker_sections.ld", 73) 74 75cc_library( 76 name = "test_backend", 77 visibility = ["@pigweed//targets:__pkg__"], 78) 79 80cc_library( 81 name = "base64", 82 srcs = [ 83 "base64.cc", 84 ], 85 hdrs = [ 86 "public/pw_tokenizer/base64.h", 87 ], 88 includes = ["public"], 89 deps = [ 90 ":pw_tokenizer", 91 "//pw_base64", 92 "//pw_preprocessor", 93 "//pw_span", 94 "//pw_string:string", 95 ], 96) 97 98cc_library( 99 name = "decoder", 100 srcs = [ 101 "decode.cc", 102 "detokenize.cc", 103 "token_database.cc", 104 ], 105 hdrs = [ 106 "public/pw_tokenizer/detokenize.h", 107 "public/pw_tokenizer/internal/decode.h", 108 "public/pw_tokenizer/token_database.h", 109 ], 110 includes = ["public"], 111 deps = [ 112 ":base64", 113 "//pw_bytes", 114 "//pw_result", 115 "//pw_span", 116 "//pw_varint", 117 ], 118) 119 120proto_library( 121 name = "tokenizer_proto", 122 srcs = [ 123 "pw_tokenizer_proto/options.proto", 124 ], 125 strip_import_prefix = "/pw_tokenizer", 126 deps = [ 127 "@com_google_protobuf//:descriptor_proto", 128 ], 129) 130 131py_proto_library( 132 name = "tokenizer_proto_py_pb2", 133 deps = [":tokenizer_proto"], 134) 135 136# Executable for generating test data for the C++ and Python detokenizers. This 137# target should only be built for the host. 138pw_cc_binary( 139 name = "generate_decoding_test_data", 140 srcs = [ 141 "generate_decoding_test_data.cc", 142 ], 143 target_compatible_with = select( 144 { 145 "@platforms//os:linux": [], 146 "@platforms//os:macos": [], 147 "@platforms//os:windows": [], 148 "//conditions:default": ["@platforms//:incompatible"], 149 }, 150 ), 151 deps = [ 152 ":decoder", 153 ":pw_tokenizer", 154 "//pw_preprocessor", 155 "//pw_span", 156 "//pw_varint", 157 ], 158) 159 160pw_cc_test( 161 name = "argument_types_test", 162 srcs = [ 163 "argument_types_test.cc", 164 "argument_types_test_c.c", 165 "pw_tokenizer_private/argument_types_test.h", 166 ], 167 deps = [ 168 ":pw_tokenizer", 169 "//pw_preprocessor", 170 "//pw_unit_test", 171 ], 172) 173 174pw_cc_test( 175 name = "base64_test", 176 srcs = [ 177 "base64_test.cc", 178 ], 179 deps = [ 180 ":base64", 181 "//pw_span", 182 "//pw_unit_test", 183 ], 184) 185 186pw_cc_test( 187 name = "decode_test", 188 srcs = [ 189 "decode_test.cc", 190 "pw_tokenizer_private/tokenized_string_decoding_test_data.h", 191 "pw_tokenizer_private/varint_decoding_test_data.h", 192 ], 193 deps = [ 194 ":decoder", 195 "//pw_unit_test", 196 "//pw_varint", 197 ], 198) 199 200pw_cc_blob_info( 201 name = "detokenizer_example_elf_blob", 202 file_path = "//pw_tokenizer/py:example_binary_with_tokenized_strings", 203 symbol_name = "kElfSection", 204) 205 206pw_cc_blob_library( 207 name = "detokenizer_elf_test_blob", 208 blobs = [ 209 ":detokenizer_example_elf_blob", 210 ], 211 namespace = "test::ns", 212 out_header = "pw_tokenizer/example_binary_with_tokenized_strings.h", 213) 214 215pw_cc_test( 216 name = "detokenize_test", 217 srcs = [ 218 "detokenize_test.cc", 219 ], 220 deps = [ 221 ":decoder", 222 ":detokenizer_elf_test_blob", 223 "//pw_unit_test", 224 ], 225) 226 227pw_cc_fuzz_test( 228 name = "detokenize_fuzzer", 229 srcs = ["detokenize_fuzzer.cc"], 230 deps = [ 231 ":decoder", 232 ":pw_tokenizer", 233 ], 234) 235 236pw_cc_test( 237 name = "encode_args_test", 238 srcs = ["encode_args_test.cc"], 239 deps = [ 240 ":pw_tokenizer", 241 "//pw_unit_test", 242 ], 243) 244 245pw_cc_test( 246 name = "hash_test", 247 srcs = [ 248 "hash_test.cc", 249 "pw_tokenizer_private/generated_hash_test_cases.h", 250 ], 251 deps = [ 252 ":pw_tokenizer", 253 "//pw_preprocessor", 254 "//pw_unit_test", 255 ], 256) 257 258pw_cc_test( 259 name = "simple_tokenize_test", 260 srcs = [ 261 "simple_tokenize_test.cc", 262 ], 263 deps = [ 264 ":pw_tokenizer", 265 "//pw_unit_test", 266 ], 267) 268 269pw_cc_test( 270 name = "token_database_test", 271 srcs = [ 272 "token_database_test.cc", 273 ], 274 deps = [ 275 ":decoder", 276 "//pw_unit_test", 277 ], 278) 279 280pw_cc_test( 281 name = "tokenize_test", 282 srcs = [ 283 "pw_tokenizer_private/tokenize_test.h", 284 "tokenize_test.cc", 285 "tokenize_test_c.c", 286 ], 287 # TODO: b/344050496 - get working on rp2040 and stm32f429i 288 target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT), 289 deps = [ 290 ":pw_tokenizer", 291 "//pw_preprocessor", 292 "//pw_unit_test", 293 "//pw_varint", 294 ], 295) 296 297pw_cc_test( 298 name = "tokenize_c99_test", 299 srcs = ["tokenize_c99_test_entry_point.cc"], 300 deps = [ 301 ":tokenize_c99_test_c", 302 "//pw_unit_test", 303 ], 304) 305 306cc_library( 307 name = "tokenize_c99_test_c", 308 srcs = ["tokenize_c99_test.c"], 309 copts = [ 310 "-std=c99", 311 # pw_tokenizer uses static_assert, so this test uses a static_assert to 312 # verify that it works. Silence warnings about preadopting C11 features. 313 "-Wno-c11-extensions", 314 ], 315 visibility = ["//visibility:private"], 316 deps = [ 317 ":pw_tokenizer", 318 "//pw_containers:inline_var_len_entry_queue", 319 ], 320) 321 322# Create a shared library for the tokenizer JNI wrapper. The include paths for 323# the JNI headers must be available in the system or provided with the 324# pw_java_native_interface_include_dirs variable. 325filegroup( 326 name = "detokenizer_jni", 327 srcs = [ 328 "java/dev/pigweed/tokenizer/detokenizer.cc", 329 ], 330) 331