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