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