Nathaniel Brough | 9d9a20d | 2020-08-04 16:46:56 +0800 | [diff] [blame] | 1 | # Copyright 2021 The Pigweed Authors |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 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 | |
Nathaniel Brough | 9d9a20d | 2020-08-04 16:46:56 +0800 | [diff] [blame] | 15 | load("@rules_proto//proto:defs.bzl", "proto_library") |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 16 | load( |
| 17 | "//pw_build:pigweed.bzl", |
| 18 | "pw_cc_library", |
| 19 | "pw_cc_test", |
| 20 | ) |
Nathaniel Brough | 9d9a20d | 2020-08-04 16:46:56 +0800 | [diff] [blame] | 21 | load("@rules_python//python:defs.bzl", "py_binary") |
| 22 | load("@rules_proto_grpc//:plugin.bzl", "proto_plugin") |
| 23 | load("//pw_protobuf_compiler:proto.bzl", "pw_proto_library") |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 24 | |
| 25 | package(default_visibility = ["//visibility:public"]) |
| 26 | |
| 27 | licenses(["notice"]) # Apache License 2.0 |
| 28 | |
| 29 | pw_cc_library( |
Alexei Frolov | f9ae189 | 2021-04-01 18:24:27 -0700 | [diff] [blame] | 30 | name = "config", |
| 31 | hdrs = ["public/pw_protobuf/config.h"], |
| 32 | includes = ["public"], |
| 33 | ) |
| 34 | |
| 35 | pw_cc_library( |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 36 | name = "pw_protobuf", |
| 37 | srcs = [ |
Alexei Frolov | dea46f7 | 2020-01-07 13:28:24 -0800 | [diff] [blame] | 38 | "decoder.cc", |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 39 | "encoder.cc", |
Alexei Frolov | bbbedff | 2020-03-11 14:21:38 -0700 | [diff] [blame] | 40 | "find.cc", |
Armando Montanez | 0ed221c | 2021-04-02 18:33:01 -0700 | [diff] [blame] | 41 | "streaming_encoder.cc", |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 42 | ], |
| 43 | hdrs = [ |
| 44 | "public/pw_protobuf/codegen.h", |
Alexei Frolov | dea46f7 | 2020-01-07 13:28:24 -0800 | [diff] [blame] | 45 | "public/pw_protobuf/decoder.h", |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 46 | "public/pw_protobuf/encoder.h", |
Alexei Frolov | bbbedff | 2020-03-11 14:21:38 -0700 | [diff] [blame] | 47 | "public/pw_protobuf/find.h", |
Ewout van Bekkum | c76aa40 | 2020-09-23 10:58:27 -0700 | [diff] [blame] | 48 | "public/pw_protobuf/serialized_size.h", |
Armando Montanez | 0ed221c | 2021-04-02 18:33:01 -0700 | [diff] [blame] | 49 | "public/pw_protobuf/streaming_encoder.h", |
Alexei Frolov | dea46f7 | 2020-01-07 13:28:24 -0800 | [diff] [blame] | 50 | "public/pw_protobuf/wire_format.h", |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 51 | ], |
Wyatt Hepler | 61def0a | 2020-01-06 10:30:14 -0800 | [diff] [blame] | 52 | includes = ["public"], |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 53 | deps = [ |
Alexei Frolov | f9ae189 | 2021-04-01 18:24:27 -0700 | [diff] [blame] | 54 | ":config", |
Armando Montanez | 0ed221c | 2021-04-02 18:33:01 -0700 | [diff] [blame] | 55 | "//pw_assert", |
Nathaniel Brough | 9d9a20d | 2020-08-04 16:46:56 +0800 | [diff] [blame] | 56 | "//pw_bytes", |
| 57 | "//pw_result", |
Rob Mohr | ee8ce08 | 2019-12-20 10:32:16 -0800 | [diff] [blame] | 58 | "//pw_span", |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 59 | "//pw_status", |
Armando Montanez | 0ed221c | 2021-04-02 18:33:01 -0700 | [diff] [blame] | 60 | "//pw_stream", |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 61 | "//pw_varint", |
| 62 | ], |
| 63 | ) |
| 64 | |
| 65 | pw_cc_test( |
Alexei Frolov | dea46f7 | 2020-01-07 13:28:24 -0800 | [diff] [blame] | 66 | name = "decoder_test", |
| 67 | srcs = ["decoder_test.cc"], |
Rob Mohr | 0681948 | 2020-04-06 13:25:43 -0700 | [diff] [blame] | 68 | deps = [ |
| 69 | ":pw_protobuf", |
| 70 | "//pw_preprocessor", |
| 71 | "//pw_unit_test", |
| 72 | ], |
Alexei Frolov | dea46f7 | 2020-01-07 13:28:24 -0800 | [diff] [blame] | 73 | ) |
| 74 | |
| 75 | pw_cc_test( |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 76 | name = "encoder_test", |
| 77 | srcs = ["encoder_test.cc"], |
Rob Mohr | 0681948 | 2020-04-06 13:25:43 -0700 | [diff] [blame] | 78 | deps = [ |
| 79 | ":pw_protobuf", |
| 80 | "//pw_unit_test", |
| 81 | ], |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 82 | ) |
| 83 | |
Alexei Frolov | bbbedff | 2020-03-11 14:21:38 -0700 | [diff] [blame] | 84 | pw_cc_test( |
Armando Montanez | 0ed221c | 2021-04-02 18:33:01 -0700 | [diff] [blame] | 85 | name = "streaming_encoder_test", |
| 86 | srcs = ["streaming_encoder_test.cc"], |
| 87 | deps = [ |
| 88 | ":pw_protobuf", |
| 89 | "//pw_unit_test", |
| 90 | ], |
| 91 | ) |
| 92 | |
| 93 | pw_cc_test( |
Alexei Frolov | bbbedff | 2020-03-11 14:21:38 -0700 | [diff] [blame] | 94 | name = "find_test", |
| 95 | srcs = ["find_test.cc"], |
Rob Mohr | 0681948 | 2020-04-06 13:25:43 -0700 | [diff] [blame] | 96 | deps = [ |
| 97 | ":pw_protobuf", |
| 98 | "//pw_unit_test", |
| 99 | ], |
Alexei Frolov | bbbedff | 2020-03-11 14:21:38 -0700 | [diff] [blame] | 100 | ) |
| 101 | |
Nathaniel Brough | 9d9a20d | 2020-08-04 16:46:56 +0800 | [diff] [blame] | 102 | proto_library( |
| 103 | name = "codegen_test_proto", |
| 104 | srcs = [ |
| 105 | "pw_protobuf_protos/common.proto", |
| 106 | "pw_protobuf_test_protos/full_test.proto", |
| 107 | "pw_protobuf_test_protos/imported.proto", |
| 108 | "pw_protobuf_test_protos/importer.proto", |
| 109 | "pw_protobuf_test_protos/non_pw_package.proto", |
| 110 | "pw_protobuf_test_protos/proto2.proto", |
| 111 | "pw_protobuf_test_protos/repeated.proto", |
| 112 | ], |
| 113 | strip_import_prefix = "//pw_protobuf", |
| 114 | ) |
| 115 | |
| 116 | pw_proto_library( |
| 117 | name = "codegen_test_protos_pwpb", |
| 118 | deps = [":codegen_test_proto"], |
| 119 | ) |
| 120 | |
| 121 | pw_cc_test( |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 122 | name = "codegen_test", |
| 123 | srcs = [ |
| 124 | "codegen_test.cc", |
| 125 | ], |
Nathaniel Brough | 9d9a20d | 2020-08-04 16:46:56 +0800 | [diff] [blame] | 126 | deps = [ |
| 127 | ":codegen_test_protos_pwpb", |
| 128 | ":pw_protobuf", |
| 129 | "//pw_span", |
| 130 | "//pw_unit_test", |
| 131 | ], |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 132 | ) |
Alexei Frolov | 9c2ed46 | 2020-01-13 15:35:42 -0800 | [diff] [blame] | 133 | |
Alexei Frolov | f9ae189 | 2021-04-01 18:24:27 -0700 | [diff] [blame] | 134 | # TODO(frolv): Figure out how to add facade tests to Bazel. |
| 135 | filegroup( |
| 136 | name = "varint_size_test", |
| 137 | srcs = [ |
| 138 | "varint_size_test.cc", |
| 139 | ], |
| 140 | ) |
| 141 | |
Alexei Frolov | 9c2ed46 | 2020-01-13 15:35:42 -0800 | [diff] [blame] | 142 | # TODO(frolv): Figure out what to do about size reports in Bazel. |
| 143 | filegroup( |
| 144 | name = "size_reports", |
| 145 | srcs = glob([ |
| 146 | "size_report/*.cc", |
| 147 | ]), |
| 148 | ) |
Nathaniel Brough | 9d9a20d | 2020-08-04 16:46:56 +0800 | [diff] [blame] | 149 | |
| 150 | py_binary( |
| 151 | name = "plugin", |
| 152 | srcs = glob(["py/pw_protobuf/*.py"]), |
| 153 | imports = ["py"], |
| 154 | main = "py/pw_protobuf/plugin.py", |
| 155 | python_version = "PY3", |
| 156 | deps = ["@com_google_protobuf//:protobuf_python"], |
| 157 | ) |
| 158 | |
| 159 | proto_plugin( |
| 160 | name = "pw_cc_plugin", |
| 161 | outputs = [ |
| 162 | "{protopath}.pwpb.h", |
| 163 | ], |
| 164 | protoc_plugin_name = "pwpb", |
| 165 | tool = "@pigweed//pw_protobuf:plugin", |
| 166 | visibility = ["//visibility:public"], |
| 167 | ) |