|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
load("@com_envoyproxy_protoc_gen_validate//bazel:pgv_proto_library.bzl", "pgv_cc_proto_library") |
|
|
|
|
load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library") |
|
|
|
|
load("@com_google_protobuf//:protobuf.bzl", _py_proto_library = "py_proto_library") |
|
|
|
|
load("@com_github_grpc_grpc//bazel:python_rules.bzl", _py_proto_library = "py_proto_library") |
|
|
|
|
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") |
|
|
|
|
load("@io_bazel_rules_go//go:def.bzl", "go_test") |
|
|
|
|
load("@rules_proto//proto:defs.bzl", "proto_library") |
|
|
|
@ -8,7 +8,6 @@ load( |
|
|
|
|
"//bazel:external_proto_deps.bzl", |
|
|
|
|
"EXTERNAL_PROTO_CC_BAZEL_DEP_MAP", |
|
|
|
|
"EXTERNAL_PROTO_GO_BAZEL_DEP_MAP", |
|
|
|
|
"EXTERNAL_PROTO_PY_BAZEL_DEP_MAP", |
|
|
|
|
) |
|
|
|
|
load( |
|
|
|
|
"//bazel/cc_proto_descriptor_library:builddefs.bzl", |
|
|
|
@ -52,63 +51,6 @@ def _go_proto_mapping(dep): |
|
|
|
|
def _cc_proto_mapping(dep): |
|
|
|
|
return _proto_mapping(dep, EXTERNAL_PROTO_CC_BAZEL_DEP_MAP, _CC_PROTO_SUFFIX) |
|
|
|
|
|
|
|
|
|
def _py_proto_mapping(dep): |
|
|
|
|
return _proto_mapping(dep, EXTERNAL_PROTO_PY_BAZEL_DEP_MAP, _PY_PROTO_SUFFIX) |
|
|
|
|
|
|
|
|
|
# TODO(htuch): Convert this to native py_proto_library once |
|
|
|
|
# https://github.com/bazelbuild/bazel/issues/3935 and/or |
|
|
|
|
# https://github.com/bazelbuild/bazel/issues/2626 are resolved. |
|
|
|
|
def _api_py_proto_library(name, srcs = [], deps = []): |
|
|
|
|
mapped_deps = [_py_proto_mapping(dep) for dep in deps] |
|
|
|
|
mapped_unique_deps = {k: True for k in mapped_deps}.keys() |
|
|
|
|
_py_proto_library( |
|
|
|
|
name = name + _PY_PROTO_SUFFIX, |
|
|
|
|
srcs = srcs, |
|
|
|
|
default_runtime = "@com_google_protobuf//:protobuf_python", |
|
|
|
|
protoc = "@com_google_protobuf//:protoc", |
|
|
|
|
deps = mapped_unique_deps + [ |
|
|
|
|
"@com_envoyproxy_protoc_gen_validate//validate:validate_py", |
|
|
|
|
"@com_google_googleapis//google/rpc:status_py_proto", |
|
|
|
|
"@com_google_googleapis//google/api:annotations_py_proto", |
|
|
|
|
"@com_google_googleapis//google/api:http_py_proto", |
|
|
|
|
"@com_google_googleapis//google/api:httpbody_py_proto", |
|
|
|
|
], |
|
|
|
|
visibility = ["//visibility:public"], |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
# This defines googleapis py_proto_library. The repository does not provide its definition and requires |
|
|
|
|
# overriding it in the consuming project (see https://github.com/grpc/grpc/issues/19255 for more details). |
|
|
|
|
def py_proto_library(name, deps = [], plugin = None): |
|
|
|
|
srcs = [dep[:-6] + ".proto" if dep.endswith("_proto") else dep for dep in deps] |
|
|
|
|
proto_deps = [] |
|
|
|
|
|
|
|
|
|
# py_proto_library in googleapis specifies *_proto rules in dependencies. |
|
|
|
|
# By rewriting *_proto to *.proto above, the dependencies in *_proto rules are not preserved. |
|
|
|
|
# As a workaround, manually specify the proto dependencies for the imported python rules. |
|
|
|
|
if name == "annotations_py_proto": |
|
|
|
|
proto_deps = proto_deps + [":http_py_proto"] |
|
|
|
|
|
|
|
|
|
# checked.proto depends on syntax.proto, we have to add this dependency manually as well. |
|
|
|
|
if name == "checked_py_proto": |
|
|
|
|
proto_deps = proto_deps + [":syntax_py_proto"] |
|
|
|
|
|
|
|
|
|
# Special handling for expr_proto target |
|
|
|
|
if srcs[0] == ":expr_moved.proto": |
|
|
|
|
srcs = ["checked.proto", "eval.proto", "explain.proto", "syntax.proto", "value.proto"] |
|
|
|
|
proto_deps = proto_deps + ["@com_google_googleapis//google/rpc:status_py_proto"] |
|
|
|
|
|
|
|
|
|
# py_proto_library does not support plugin as an argument yet at gRPC v1.25.0: |
|
|
|
|
# https://github.com/grpc/grpc/blob/v1.25.0/bazel/python_rules.bzl#L72. |
|
|
|
|
# plugin should also be passed in here when gRPC version is greater than v1.25.x. |
|
|
|
|
_py_proto_library( |
|
|
|
|
name = name, |
|
|
|
|
srcs = srcs, |
|
|
|
|
default_runtime = "@com_google_protobuf//:protobuf_python", |
|
|
|
|
protoc = "@com_google_protobuf//:protoc", |
|
|
|
|
deps = proto_deps + ["@com_google_protobuf//:protobuf_python"], |
|
|
|
|
visibility = ["//visibility:public"], |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
def _api_cc_grpc_library(name, proto, deps = []): |
|
|
|
|
cc_grpc_library( |
|
|
|
|
name = name, |
|
|
|
@ -157,7 +99,15 @@ def api_cc_py_proto_library( |
|
|
|
|
deps = [relative_name], |
|
|
|
|
visibility = ["//visibility:public"], |
|
|
|
|
) |
|
|
|
|
_api_py_proto_library(name, srcs, deps) |
|
|
|
|
|
|
|
|
|
# Uses gRPC implementation of py_proto_library. |
|
|
|
|
# https://github.com/grpc/grpc/blob/v1.59.1/bazel/python_rules.bzl#L160 |
|
|
|
|
_py_proto_library( |
|
|
|
|
name = name + _PY_PROTO_SUFFIX, |
|
|
|
|
# Actual dependencies are resolved automatically from the proto_library dep tree. |
|
|
|
|
deps = [relative_name], |
|
|
|
|
visibility = ["//visibility:public"], |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
# Optionally define gRPC services |
|
|
|
|
if has_services: |
|
|
|
|