# Copyright 2023 The Pigweed Authors # # Licensed under the Apache License, Version 2.0 (the "License"); you may not # use this file except in compliance with the License. You may obtain a copy of # the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_python//python:proto.bzl", "py_proto_library") load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library") load("//pw_build:compatibility.bzl", "incompatible_with_mcu") load("//pw_build:copy_to_bin.bzl", "copy_to_bin") load("//pw_build:pw_cc_binary.bzl", "pw_cc_binary") load("//pw_build:pw_cc_blob_library.bzl", "pw_cc_blob_info", "pw_cc_blob_library") load("//pw_build:pw_linker_script.bzl", "pw_linker_script") load("//pw_fuzzer:fuzzer.bzl", "pw_cc_fuzz_test") load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test") package( default_visibility = ["//visibility:public"], ) licenses(["notice"]) cc_library( name = "pw_tokenizer", srcs = [ "encode_args.cc", "hash.cc", "tokenize.cc", ], hdrs = [ "public/pw_tokenizer/config.h", "public/pw_tokenizer/encode_args.h", "public/pw_tokenizer/enum.h", "public/pw_tokenizer/hash.h", "public/pw_tokenizer/internal/argument_types.h", "public/pw_tokenizer/internal/argument_types_macro_4_byte.h", "public/pw_tokenizer/internal/argument_types_macro_8_byte.h", "public/pw_tokenizer/internal/enum.h", "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_128_hash_macro.h", "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_256_hash_macro.h", "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_80_hash_macro.h", "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_96_hash_macro.h", "public/pw_tokenizer/internal/tokenize_string.h", "public/pw_tokenizer/nested_tokenization.h", "public/pw_tokenizer/tokenize.h", ], strip_include_prefix = "public", tags = ["noclangtidy"], deps = [ ":config_override", "//pw_bytes:bit", "//pw_containers:to_array", "//pw_polyfill", "//pw_preprocessor", "//pw_span", "//pw_varint", ], ) label_flag( name = "config_override", build_setting_default = "//pw_build:default_module_config", ) pw_linker_script( name = "linker_script", linker_script = "pw_tokenizer_linker_sections.ld", ) cc_library( name = "test_backend", visibility = ["//targets:__pkg__"], ) cc_library( name = "base64", srcs = [ "base64.cc", ], hdrs = [ "public/pw_tokenizer/base64.h", ], strip_include_prefix = "public", deps = [ ":pw_tokenizer", "//pw_base64", "//pw_preprocessor", "//pw_span", "//pw_string:string", ], ) cc_library( name = "decoder", srcs = [ "decode.cc", "detokenize.cc", "token_database.cc", ], hdrs = [ "public/pw_tokenizer/detokenize.h", "public/pw_tokenizer/internal/decode.h", "public/pw_tokenizer/token_database.h", ], implementation_deps = [ "//pw_elf:reader", ], strip_include_prefix = "public", deps = [ ":base64", ":csv", ":pw_tokenizer", "//pw_bytes", "//pw_bytes:bit", "//pw_log", "//pw_preprocessor", "//pw_result", "//pw_span", "//pw_status", "//pw_stream", "//pw_varint", ], ) cc_library( name = "csv", srcs = ["csv.cc"], hdrs = ["pw_tokenizer_private/csv.h"], implementation_deps = ["//pw_log"], visibility = ["//visibility:private"], ) pw_cc_test( name = "csv_test", srcs = ["csv_test.cc"], deps = [":csv"], ) proto_library( name = "tokenizer_proto", srcs = [ "pw_tokenizer_proto/options.proto", ], strip_import_prefix = "/pw_tokenizer", deps = [ "@com_google_protobuf//:descriptor_proto", ], ) py_proto_library( name = "tokenizer_proto_py_pb2", deps = [":tokenizer_proto"], ) # Executable for generating test data for the C++ and Python detokenizers. This # target should only be built for the host. pw_cc_binary( name = "generate_decoding_test_data", srcs = [ "generate_decoding_test_data.cc", ], target_compatible_with = select( { "@platforms//os:linux": [], "@platforms//os:macos": [], "@platforms//os:windows": [], "//conditions:default": ["@platforms//:incompatible"], }, ), deps = [ ":decoder", ":pw_tokenizer", "//pw_preprocessor", "//pw_span", "//pw_varint", ], ) pw_cc_test( name = "argument_types_test", srcs = [ "argument_types_test.cc", "argument_types_test_c.c", "pw_tokenizer_private/argument_types_test.h", ], deps = [ ":pw_tokenizer", "//pw_polyfill", "//pw_preprocessor", ], ) pw_cc_test( name = "base64_test", srcs = [ "base64_test.cc", ], deps = [ ":base64", "//pw_span", ], ) pw_cc_test( name = "decode_test", srcs = [ "decode_test.cc", "pw_tokenizer_private/tokenized_string_decoding_test_data.h", "pw_tokenizer_private/varint_decoding_test_data.h", ], # TODO: https://pwbug.dev/346628514 - Fix this for rp2040 target_compatible_with = select({ "//pw_build/constraints/chipset:rp2040": ["@platforms//:incompatible"], "//conditions:default": [], }), deps = [ ":decoder", "//pw_varint", ], ) pw_cc_blob_info( name = "detokenizer_example_elf_blob", file_path = "//pw_tokenizer/py:example_binary_with_tokenized_strings", symbol_name = "kElfSection", ) pw_cc_blob_library( name = "detokenizer_elf_test_blob", blobs = [ ":detokenizer_example_elf_blob", ], namespace = "test::ns", out_header = "pw_tokenizer/example_binary_with_tokenized_strings.h", ) pw_cc_test( name = "detokenize_test", srcs = [ "detokenize_test.cc", ], deps = [ ":decoder", ":detokenizer_elf_test_blob", "//pw_stream", ], ) pw_cc_fuzz_test( name = "detokenize_fuzzer", srcs = ["detokenize_fuzzer.cc"], deps = [ ":decoder", ":pw_tokenizer", "//pw_preprocessor", ], ) pw_cc_test( name = "encode_args_test", srcs = ["encode_args_test.cc"], deps = [":pw_tokenizer"], ) pw_cc_test( name = "hash_test", srcs = [ "hash_test.cc", "pw_tokenizer_private/generated_hash_test_cases.h", ], tags = ["noclangtidy"], deps = [ ":pw_tokenizer", "//pw_preprocessor", ], ) pw_cc_test( name = "simple_tokenize_test", srcs = [ "simple_tokenize_test.cc", ], deps = [":pw_tokenizer"], ) pw_cc_test( name = "token_database_test", srcs = [ "token_database_test.cc", ], deps = [":decoder"], ) pw_cc_test( name = "tokenize_test", srcs = [ "pw_tokenizer_private/tokenize_test.h", "tokenize_test.cc", "tokenize_test_c.c", ], # TODO: b/344050496 - get working on rp2040 and stm32f429i target_compatible_with = incompatible_with_mcu(), deps = [ ":pw_tokenizer", "//pw_preprocessor", "//pw_varint", ], ) pw_cc_test( name = "tokenize_c99_test", srcs = ["tokenize_c99_test_entry_point.cc"], deps = [":tokenize_c99_test_c"], ) pw_cc_test( name = "enum_test", srcs = [ "enum_test.cc", ], deps = [ "//pw_compilation_testing:negative_compilation_testing", "//pw_tokenizer", ], ) cc_library( name = "tokenize_c99_test_c", srcs = ["tokenize_c99_test.c"], copts = [ "-std=c99", # pw_tokenizer uses static_assert, so this test uses a static_assert to # verify that it works. Silence warnings about preadopting C11 features. "-Wno-c11-extensions", ], visibility = ["//visibility:private"], deps = [ ":pw_tokenizer", "//pw_containers:inline_var_len_entry_queue", "//pw_varint", ], ) # Create a shared library for the tokenizer JNI wrapper. The include paths for # the JNI headers must be available in the system or provided with the # pw_java_native_interface_include_dirs variable. filegroup( name = "detokenizer_jni", srcs = [ "java/dev/pigweed/tokenizer/detokenizer.cc", ], ) filegroup( name = "doxygen", srcs = [ "public/pw_tokenizer/config.h", "public/pw_tokenizer/detokenize.h", "public/pw_tokenizer/encode_args.h", "public/pw_tokenizer/enum.h", "public/pw_tokenizer/nested_tokenization.h", "public/pw_tokenizer/token_database.h", "public/pw_tokenizer/tokenize.h", ], ) sphinx_docs_library( name = "docs", srcs = [ "Kconfig", "api.rst", "detokenization.rst", "docs.rst", "enum_test.cc", "get_started.rst", "public/pw_tokenizer/internal/tokenize_string.h", "token_databases.rst", "tokenization.rst", ], prefix = "pw_tokenizer/", target_compatible_with = incompatible_with_mcu(), ) copy_to_bin( name = "js_protos", srcs = ["pw_tokenizer_proto/options.proto"], )