1# Copyright 2024 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("@io_bazel_rules_go//go:def.bzl", "go_test") 16load("@rules_proto//proto:defs.bzl", "proto_library") 17load("//pw_build:compatibility.bzl", "incompatible_with_mcu") 18load( 19 "//pw_protobuf_compiler:pw_proto_library.bzl", 20 "pw_proto_filegroup", 21 "pwpb_proto_library", 22 "pwpb_rpc_proto_library", 23) 24load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test") 25 26package(default_visibility = ["//visibility:public"]) 27 28cc_library( 29 name = "connection", 30 srcs = [ 31 "connection.cc", 32 ], 33 hdrs = [ 34 "public/pw_grpc/connection.h", 35 ], 36 includes = ["public"], 37 target_compatible_with = select({ 38 ":pw_rpc_config_setting": [], 39 "//conditions:default": ["@platforms//:incompatible"], 40 }), 41 deps = [ 42 ":hpack", 43 ":send_queue", 44 "//pw_allocator:allocator", 45 "//pw_assert", 46 "//pw_async:dispatcher", 47 "//pw_async_basic:dispatcher", 48 "//pw_bytes", 49 "//pw_function", 50 "//pw_log", 51 "//pw_result", 52 "//pw_span", 53 "//pw_status", 54 "//pw_stream", 55 "//pw_string", 56 "//pw_sync:inline_borrowable", 57 "//pw_thread:thread", 58 "//pw_thread:thread_core", 59 ], 60) 61 62cc_library( 63 name = "send_queue", 64 srcs = ["send_queue.cc"], 65 hdrs = ["public/pw_grpc/send_queue.h"], 66 includes = ["public"], 67 deps = [ 68 "//pw_async:dispatcher", 69 "//pw_async_basic:dispatcher", 70 "//pw_bytes", 71 "//pw_function", 72 "//pw_log", 73 "//pw_result", 74 "//pw_span", 75 "//pw_status", 76 "//pw_stream", 77 "//pw_string", 78 "//pw_sync:lock_annotations", 79 "//pw_sync:mutex", 80 "//pw_thread:thread", 81 "//pw_thread:thread_core", 82 ], 83) 84 85cc_library( 86 name = "grpc_channel_output", 87 hdrs = ["public/pw_grpc/grpc_channel_output.h"], 88 includes = ["public"], 89 deps = [ 90 ":connection", 91 "//pw_bytes", 92 "//pw_rpc", 93 ], 94) 95 96cc_library( 97 name = "pw_rpc_handler", 98 srcs = ["pw_rpc_handler.cc"], 99 hdrs = ["public/pw_grpc/pw_rpc_handler.h"], 100 includes = ["public"], 101 target_compatible_with = select({ 102 ":pw_rpc_config_setting": [], 103 "//conditions:default": ["@platforms//:incompatible"], 104 }), 105 deps = [ 106 ":connection", 107 ":grpc_channel_output", 108 "//pw_bytes", 109 "//pw_log", 110 "//pw_rpc", 111 "//pw_rpc_transport:rpc_transport", 112 "//pw_string", 113 ], 114) 115 116cc_library( 117 name = "hpack", 118 srcs = [ 119 "hpack.autogen.inc", 120 "hpack.cc", 121 ], 122 hdrs = [ 123 "pw_grpc_private/hpack.h", 124 ], 125 deps = [ 126 "//pw_assert", 127 "//pw_bytes", 128 "//pw_log", 129 "//pw_result", 130 "//pw_span", 131 "//pw_status", 132 "//pw_string", 133 ], 134) 135 136pw_cc_test( 137 name = "hpack_test", 138 srcs = ["hpack_test.cc"], 139 deps = [ 140 ":hpack", 141 ], 142) 143 144cc_binary( 145 name = "test_pw_rpc_server", 146 srcs = ["test_pw_rpc_server.cc"], 147 target_compatible_with = select({ 148 ":pw_rpc_config_setting": [], 149 "//conditions:default": ["@platforms//:incompatible"], 150 }), 151 deps = [ 152 ":connection", 153 ":echo_pwpb_rpc", 154 ":grpc_channel_output", 155 ":pw_rpc_handler", 156 "//pw_allocator:libc_allocator", 157 "//pw_assert_basic:pw_assert_basic_handler", 158 "//pw_assert_log:assert_backend", 159 "//pw_assert_log:check_backend", 160 "//pw_bytes", 161 "//pw_checksum", 162 "//pw_log", 163 "//pw_result", 164 "//pw_rpc", 165 "//pw_rpc_transport:service_registry", 166 "//pw_span", 167 "//pw_status", 168 "//pw_stream", 169 "//pw_stream:socket_stream", 170 "//pw_string", 171 "//pw_thread:test_thread_context", 172 "//pw_thread:thread", 173 ], 174) 175 176pw_proto_filegroup( 177 name = "echo_proto_and_options", 178 srcs = ["examples/echo/echo.proto"], 179 options_files = ["examples/echo/echo.options"], 180) 181 182proto_library( 183 name = "echo_proto", 184 srcs = [":echo_proto_and_options"], 185) 186 187pwpb_proto_library( 188 name = "echo_pwpb", 189 deps = [":echo_proto"], 190) 191 192pwpb_rpc_proto_library( 193 name = "echo_pwpb_rpc", 194 pwpb_proto_library_deps = [":echo_pwpb"], 195 deps = [":echo_proto"], 196) 197 198# Required config options to apply to //pw_rpc:config_override 199cc_library( 200 name = "pw_rpc_config", 201 defines = [ 202 "PW_RPC_COMPLETION_REQUEST_CALLBACK=1", 203 "PW_RPC_METHOD_STORES_TYPE=1", 204 ], 205) 206 207config_setting( 208 name = "pw_rpc_config_setting", 209 flag_values = { 210 "//pw_rpc:config_override": ":pw_rpc_config", 211 }, 212) 213 214# This test requires a special configuration. It's run in CI, and can be 215# run manually via: 216# 217# bazel test --//pw_rpc:config_override=//pw_grpc:pw_rpc_config //pw_grpc:integration_test 218# 219# deps.bzl contains the bazel repositories used in deps for this integration test. 220# It is generated from go.mod using gazelle: 221# gazelle update-repos -from_file=go.mod -to_macro=deps.bzl%pw_grpc_deps -prune 222# See https://github.com/bazelbuild/bazel-gazelle?tab=readme-ov-file#update-repos 223go_test( 224 name = "integration_test", 225 srcs = ["integration_test.go"], 226 data = [ 227 ":test_pw_rpc_server", 228 ], 229 target_compatible_with = incompatible_with_mcu(), 230 deps = [ 231 "@org_golang_google_grpc//:grpc", 232 "@org_golang_google_grpc//codes", 233 "@org_golang_google_grpc//credentials/insecure", 234 "@org_golang_google_grpc//status", 235 "@org_golang_google_grpc_examples//features/proto/echo", 236 ], 237) 238