1# Copyright 2020 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("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") 16load("@rules_cc//cc:cc_library.bzl", "cc_library") 17load("@rules_python//python:proto.bzl", "py_proto_library") 18load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library") 19load("//pw_build:compatibility.bzl", "incompatible_with_mcu") 20load( 21 "//pw_protobuf_compiler:pw_proto_library.bzl", 22 "nanopb_proto_library", 23 "nanopb_rpc_proto_library", 24 "pw_proto_filegroup", 25 "pwpb_proto_library", 26 "raw_rpc_proto_library", 27) 28load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test") 29 30package( 31 default_visibility = ["//visibility:public"], 32 features = ["-layering_check"], 33) 34 35licenses(["notice"]) 36 37cc_library( 38 name = "metric", 39 srcs = ["metric.cc"], 40 hdrs = [ 41 "public/pw_metric/global.h", 42 "public/pw_metric/metric.h", 43 ], 44 implementation_deps = ["//pw_assert:check"], 45 strip_include_prefix = "public", 46 deps = [ 47 "//pw_containers:intrusive_list", 48 "//pw_log", 49 "//pw_preprocessor", 50 "//pw_span", 51 "//pw_tokenizer", 52 "//pw_tokenizer:base64", 53 ], 54) 55 56cc_library( 57 name = "global", 58 srcs = ["global.cc"], 59 hdrs = [ 60 "public/pw_metric/global.h", 61 ], 62 deps = [ 63 ":metric", 64 "//pw_containers:intrusive_list", 65 ], 66) 67 68# Common MetricWalker/MetricWriter used by RPC service. 69cc_library( 70 name = "metric_walker", 71 hdrs = ["pw_metric_private/metric_walker.h"], 72 tags = ["noclangtidy"], 73 visibility = ["//visibility:private"], 74 deps = [ 75 ":metric", 76 "//pw_assert:check", 77 "//pw_containers:intrusive_list", 78 "//pw_containers:vector", 79 "//pw_status", 80 "//pw_tokenizer", 81 ], 82) 83 84cc_library( 85 name = "metric_service_nanopb", 86 srcs = ["metric_service_nanopb.cc"], 87 hdrs = ["public/pw_metric/metric_service_nanopb.h"], 88 implementation_deps = [ 89 "//pw_assert:check", 90 "//pw_containers:vector", 91 ], 92 strip_include_prefix = "public", 93 deps = [ 94 ":metric", 95 ":metric_proto_nanopb_rpc", 96 ":metric_walker", 97 ], 98) 99 100cc_library( 101 name = "metric_service_pwpb", 102 srcs = ["metric_service_pwpb.cc"], 103 hdrs = ["public/pw_metric/metric_service_pwpb.h"], 104 implementation_deps = [ 105 "//pw_assert:check", 106 "//pw_containers:vector", 107 ], 108 includes = [ 109 "metric_proto_cc.pwpb.pb/pw_metric", 110 "metric_proto_cc.raw_rpc.pb/pw_metric", 111 ], 112 strip_include_prefix = "public", 113 deps = [ 114 ":metric", 115 ":metric_proto_pwpb", 116 ":metric_proto_raw_rpc", 117 ":metric_walker", 118 "//pw_bytes", 119 "//pw_containers:intrusive_list", 120 "//pw_preprocessor", 121 "//pw_rpc/raw:server_api", 122 "//pw_span", 123 "//pw_status", 124 ], 125) 126 127pw_proto_filegroup( 128 name = "metric_proto_and_options", 129 srcs = [ 130 "pw_metric_proto/metric_service.proto", 131 ], 132 options_files = [ 133 "pw_metric_proto/metric_service.options", 134 "pw_metric_proto/metric_service.pwpb_options", 135 ], 136) 137 138proto_library( 139 name = "metric_proto", 140 srcs = [":metric_proto_and_options"], 141 strip_import_prefix = "/pw_metric", 142) 143 144py_proto_library( 145 name = "metric_proto_py_pb2", 146 deps = [":metric_proto"], 147) 148 149pwpb_proto_library( 150 name = "metric_proto_pwpb", 151 deps = [":metric_proto"], 152) 153 154nanopb_proto_library( 155 name = "metric_proto_nanopb", 156 deps = [":metric_proto"], 157) 158 159nanopb_rpc_proto_library( 160 name = "metric_proto_nanopb_rpc", 161 nanopb_proto_library_deps = [":metric_proto_nanopb"], 162 deps = [":metric_proto"], 163) 164 165raw_rpc_proto_library( 166 name = "metric_proto_raw_rpc", 167 deps = [":metric_proto"], 168) 169 170pw_cc_test( 171 name = "metric_test", 172 srcs = [ 173 "metric_test.cc", 174 ], 175 deps = [ 176 ":metric", 177 ], 178) 179 180pw_cc_test( 181 name = "global_test", 182 srcs = [ 183 "global_test.cc", 184 ], 185 # TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; has test 186 # failures. 187 target_compatible_with = select({ 188 "//pw_build/constraints/chipset:rp2040": ["@platforms//:incompatible"], 189 "//conditions:default": [], 190 }), 191 deps = [ 192 ":global", 193 ], 194) 195 196pw_cc_test( 197 name = "metric_service_nanopb_test", 198 srcs = [ 199 "metric_service_nanopb_test.cc", 200 ], 201 deps = [ 202 ":metric_service_nanopb", 203 "//pw_rpc/nanopb:test_method_context", 204 ], 205) 206 207pw_cc_test( 208 name = "metric_service_pwpb_test", 209 srcs = [ 210 "metric_service_pwpb_test.cc", 211 ], 212 deps = [ 213 ":metric_service_pwpb", 214 "//pw_rpc/pwpb:test_method_context", 215 "//pw_rpc/raw:test_method_context", 216 ], 217) 218 219sphinx_docs_library( 220 name = "docs", 221 srcs = [ 222 "docs.rst", 223 ], 224 prefix = "pw_metric/", 225 target_compatible_with = incompatible_with_mcu(), 226) 227