blob: d59f877a6874bf57e21c8d9b48b44f26b17bc115 [file] [log] [blame] [edit]
# 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:java_lite_proto_library.bzl", "java_lite_proto_library")
load("@com_google_protobuf//bazel:java_proto_library.bzl", "java_proto_library")
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_fuzzer:fuzzer.bzl", "pw_cc_fuzz_test")
load("//pw_perf_test:pw_cc_perf_test.bzl", "pw_cc_perf_test")
load("//pw_protobuf_compiler:pw_proto_library.bzl", "pw_proto_filegroup", "pwpb_proto_library")
load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
package(
default_visibility = ["//visibility:public"],
features = ["-layering_check"],
)
licenses(["notice"])
cc_library(
name = "config",
hdrs = ["public/pw_protobuf/config.h"],
strip_include_prefix = "public",
deps = [":config_override"],
)
label_flag(
name = "config_override",
build_setting_default = "//pw_build:default_module_config",
)
cc_library(
name = "pw_protobuf",
srcs = [
"decoder.cc",
"encoder.cc",
"find.cc",
"map_utils.cc",
"message.cc",
"stream_decoder.cc",
],
hdrs = [
"public/pw_protobuf/decoder.h",
"public/pw_protobuf/encoder.h",
"public/pw_protobuf/find.h",
"public/pw_protobuf/internal/codegen.h",
"public/pw_protobuf/internal/proto_integer_base.h",
"public/pw_protobuf/map_utils.h",
"public/pw_protobuf/message.h",
"public/pw_protobuf/serialized_size.h",
"public/pw_protobuf/stream_decoder.h",
"public/pw_protobuf/wire_format.h",
],
strip_include_prefix = "public",
deps = [
":config",
"//pw_assert:assert",
"//pw_assert:check",
"//pw_bytes",
"//pw_bytes:bit",
"//pw_containers:vector",
"//pw_function",
"//pw_preprocessor",
"//pw_result",
"//pw_span",
"//pw_status",
"//pw_stream",
"//pw_stream:interval_reader",
"//pw_string:string",
"//pw_toolchain:sibling_cast",
"//pw_varint",
"//pw_varint:stream",
],
)
cc_library(
name = "bytes_utils",
hdrs = ["public/pw_protobuf/bytes_utils.h"],
strip_include_prefix = "public",
deps = [
":pw_protobuf",
"//pw_bytes",
"//pw_result",
"//pw_status",
],
)
pw_cc_test(
name = "decoder_test",
srcs = ["decoder_test.cc"],
deps = [
":pw_protobuf",
"//pw_fuzzer:fuzztest",
"//pw_fuzzer:libfuzzer",
"//pw_preprocessor",
],
)
pw_cc_test(
name = "encoder_test",
srcs = ["encoder_test.cc"],
deps = [":pw_protobuf"],
)
pw_cc_fuzz_test(
name = "encoder_fuzz_test",
srcs = [
"encoder_fuzzer.cc",
"fuzz.h",
],
deps = [
"//pw_protobuf",
"//pw_span",
],
)
pw_cc_fuzz_test(
name = "decoder_fuzz_test",
srcs = [
"decoder_fuzzer.cc",
"fuzz.h",
],
deps = [
"//pw_protobuf",
"//pw_span",
],
)
pw_cc_test(
name = "find_test",
srcs = ["find_test.cc"],
deps = [
":pw_protobuf",
"//pw_string",
],
)
pw_cc_test(
name = "serialized_size_test",
srcs = ["serialized_size_test.cc"],
deps = [":pw_protobuf"],
)
pw_cc_test(
name = "stream_decoder_test",
srcs = ["stream_decoder_test.cc"],
deps = [":pw_protobuf"],
)
pw_cc_test(
name = "map_utils_test",
srcs = ["map_utils_test.cc"],
deps = [":pw_protobuf"],
)
pw_cc_test(
name = "message_test",
srcs = ["message_test.cc"],
deps = [":pw_protobuf"],
)
pw_cc_perf_test(
name = "encoder_perf_test",
srcs = ["encoder_perf_test.cc"],
deps = [
":pw_protobuf",
"//pw_unit_test",
],
)
proto_library(
name = "codegen_protos",
srcs = [
"pw_protobuf_codegen_protos/codegen_options.proto",
],
strip_import_prefix = "/pw_protobuf",
)
py_proto_library(
name = "codegen_protos_pb2",
deps = [":codegen_protos"],
)
proto_library(
name = "common_proto",
srcs = [
"pw_protobuf_protos/common.proto",
],
strip_import_prefix = "/pw_protobuf",
)
py_proto_library(
name = "common_py_pb2",
deps = [":common_proto"],
)
java_proto_library(
name = "common_java_proto",
deps = [":common_proto"],
)
java_lite_proto_library(
name = "common_java_proto_lite",
deps = [":common_proto"],
)
proto_library(
name = "field_options_proto",
srcs = [
"pw_protobuf_protos/field_options.proto",
],
strip_import_prefix = "/pw_protobuf",
deps = [
"@com_google_protobuf//:descriptor_proto",
],
)
py_proto_library(
name = "field_options_proto_pb2",
deps = [
":field_options_proto",
],
)
proto_library(
name = "status_proto",
srcs = [
"pw_protobuf_protos/status.proto",
],
strip_import_prefix = "/pw_protobuf",
)
py_proto_library(
name = "status_proto_pb2",
deps = [":status_proto"],
)
pw_proto_filegroup(
name = "codegen_test_deps_protos_and_options",
srcs = [
"pw_protobuf_test_deps_protos/imported.proto",
],
options_files = ["pw_protobuf_test_deps_protos/imported.pwpb_options"],
)
pw_proto_filegroup(
name = "codegen_import_test_deps_protos_and_options",
srcs = [
"pw_protobuf_test_deps_protos/test_prefix_imported.proto",
],
options_files = ["pw_protobuf_test_deps_protos/test_prefix_imported.pwpb_options"],
)
proto_library(
name = "codegen_test_deps_protos",
srcs = [":codegen_test_deps_protos_and_options"],
strip_import_prefix = "/pw_protobuf",
)
# Test that options files are applied even on protos that are given an import path
# that doesn't correspond to their real file path.
proto_library(
name = "codegen_test_deps_protos_test_prefix",
srcs = [":codegen_import_test_deps_protos_and_options"],
import_prefix = "test_prefix",
strip_import_prefix = "/pw_protobuf/pw_protobuf_test_deps_protos",
)
pw_proto_filegroup(
name = "codegen_test_proto_and_options",
srcs = [
"pw_protobuf_test_protos/edition.proto",
"pw_protobuf_test_protos/edition_file_options.proto",
"pw_protobuf_test_protos/full_test.proto",
"pw_protobuf_test_protos/imported.proto",
"pw_protobuf_test_protos/importer.proto",
"pw_protobuf_test_protos/non_pw_package.proto",
"pw_protobuf_test_protos/optional.proto",
"pw_protobuf_test_protos/proto2.proto",
"pw_protobuf_test_protos/repeated.proto",
"pw_protobuf_test_protos/size_report.proto",
],
options_files = [
"pw_protobuf_test_protos/edition.pwpb_options",
"pw_protobuf_test_protos/edition_file_options.pwpb_options",
"pw_protobuf_test_protos/full_test.pwpb_options",
"pw_protobuf_test_protos/optional.pwpb_options",
"pw_protobuf_test_protos/imported.pwpb_options",
"pw_protobuf_test_protos/repeated.pwpb_options",
],
)
proto_library(
name = "codegen_test_proto",
srcs = [":codegen_test_proto_and_options"],
strip_import_prefix = "/pw_protobuf",
deps = [
":codegen_test_deps_protos",
":codegen_test_deps_protos_test_prefix",
":common_proto",
],
)
pwpb_proto_library(
name = "codegen_test_proto_pwpb",
deps = [":codegen_test_proto"],
)
pw_cc_test(
name = "codegen_decoder_test",
srcs = [
"codegen_decoder_test.cc",
],
deps = [
":codegen_test_proto_pwpb",
":pw_protobuf",
"//pw_containers:vector",
"//pw_span",
],
)
pw_cc_test(
name = "codegen_encoder_test",
srcs = [
"codegen_encoder_test.cc",
],
deps = [
":codegen_test_proto_pwpb",
":pw_protobuf",
"//pw_bytes",
"//pw_span",
],
)
pw_cc_test(
name = "codegen_message_test",
srcs = [
"codegen_message_test.cc",
],
deps = [
":codegen_test_proto_pwpb",
":pw_protobuf",
"//pw_span",
],
)
pw_cc_test(
name = "codegen_editions_test",
srcs = [
"codegen_editions_test.cc",
],
deps = [
":codegen_test_proto_pwpb",
":pw_protobuf",
"//pw_preprocessor",
"//pw_span",
"//pw_status",
"//pw_stream",
],
)
# TODO(frolv): Figure out how to add facade tests to Bazel.
filegroup(
name = "varint_size_test",
srcs = [
"varint_size_test.cc",
],
)
filegroup(
name = "doxygen",
srcs = [
"public/pw_protobuf/find.h",
],
)
sphinx_docs_library(
name = "docs",
srcs = [
"docs.rst",
"pw_protobuf_test_protos/size_report.proto",
"pw_protobuf_test_protos/size_report.pwpb_options",
"size_report.rst",
"//pw_protobuf/size_report:decoder_incremental",
"//pw_protobuf/size_report:decoder_partial",
"//pw_protobuf/size_report:oneof_codegen_size_comparison",
"//pw_protobuf/size_report:protobuf_overview",
"//pw_protobuf/size_report:simple_codegen_size_comparison",
],
prefix = "pw_protobuf/",
target_compatible_with = incompatible_with_mcu(),
)
copy_to_bin(
name = "js_protos",
srcs = [
"pw_protobuf_protos/common.proto",
"pw_protobuf_protos/field_options.proto",
"pw_protobuf_protos/status.proto",
],
)