Skip to content

Commit ea7d1c2

Browse files
committed
bazel: Migrate py_proto_library to @com_github_grpc_grpc
Signed-off-by: Sergii Tkachenko <[email protected]>
1 parent 3c3372c commit ea7d1c2

File tree

8 files changed

+47
-86
lines changed

8 files changed

+47
-86
lines changed

api/bazel/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ load(
77
"EXTERNAL_PROTO_CC_BAZEL_DEP_MAP",
88
"EXTERNAL_PROTO_GO_BAZEL_DEP_MAP",
99
"EXTERNAL_PROTO_IMPORT_BAZEL_DEP_MAP",
10-
"EXTERNAL_PROTO_PY_BAZEL_DEP_MAP",
1110
)
1211

1312
licenses(["notice"]) # Apache 2
@@ -38,6 +37,5 @@ json_data(
3837
cc = EXTERNAL_PROTO_CC_BAZEL_DEP_MAP,
3938
go = EXTERNAL_PROTO_GO_BAZEL_DEP_MAP,
4039
imports = EXTERNAL_PROTO_IMPORT_BAZEL_DEP_MAP,
41-
py = EXTERNAL_PROTO_PY_BAZEL_DEP_MAP,
4240
),
4341
)

api/bazel/api_build_system.bzl

Lines changed: 10 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
load("@com_envoyproxy_protoc_gen_validate//bazel:pgv_proto_library.bzl", "pgv_cc_proto_library")
22
load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
3-
load("@com_google_protobuf//:protobuf.bzl", _py_proto_library = "py_proto_library")
3+
load("@com_github_grpc_grpc//bazel:python_rules.bzl", _py_proto_library = "py_proto_library")
44
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
55
load("@io_bazel_rules_go//go:def.bzl", "go_test")
66
load("@rules_proto//proto:defs.bzl", "proto_library")
77
load(
88
"//bazel:external_proto_deps.bzl",
99
"EXTERNAL_PROTO_CC_BAZEL_DEP_MAP",
1010
"EXTERNAL_PROTO_GO_BAZEL_DEP_MAP",
11-
"EXTERNAL_PROTO_PY_BAZEL_DEP_MAP",
1211
)
1312
load(
1413
"//bazel/cc_proto_descriptor_library:builddefs.bzl",
@@ -52,63 +51,6 @@ def _go_proto_mapping(dep):
5251
def _cc_proto_mapping(dep):
5352
return _proto_mapping(dep, EXTERNAL_PROTO_CC_BAZEL_DEP_MAP, _CC_PROTO_SUFFIX)
5453

55-
def _py_proto_mapping(dep):
56-
return _proto_mapping(dep, EXTERNAL_PROTO_PY_BAZEL_DEP_MAP, _PY_PROTO_SUFFIX)
57-
58-
# TODO(htuch): Convert this to native py_proto_library once
59-
# https://github.com/bazelbuild/bazel/issues/3935 and/or
60-
# https://github.com/bazelbuild/bazel/issues/2626 are resolved.
61-
def _api_py_proto_library(name, srcs = [], deps = []):
62-
mapped_deps = [_py_proto_mapping(dep) for dep in deps]
63-
mapped_unique_deps = {k: True for k in mapped_deps}.keys()
64-
_py_proto_library(
65-
name = name + _PY_PROTO_SUFFIX,
66-
srcs = srcs,
67-
default_runtime = "@com_google_protobuf//:protobuf_python",
68-
protoc = "@com_google_protobuf//:protoc",
69-
deps = mapped_unique_deps + [
70-
"@com_envoyproxy_protoc_gen_validate//validate:validate_py",
71-
"@com_google_googleapis//google/rpc:status_py_proto",
72-
"@com_google_googleapis//google/api:annotations_py_proto",
73-
"@com_google_googleapis//google/api:http_py_proto",
74-
"@com_google_googleapis//google/api:httpbody_py_proto",
75-
],
76-
visibility = ["//visibility:public"],
77-
)
78-
79-
# This defines googleapis py_proto_library. The repository does not provide its definition and requires
80-
# overriding it in the consuming project (see https://github.com/grpc/grpc/issues/19255 for more details).
81-
def py_proto_library(name, deps = [], plugin = None):
82-
srcs = [dep[:-6] + ".proto" if dep.endswith("_proto") else dep for dep in deps]
83-
proto_deps = []
84-
85-
# py_proto_library in googleapis specifies *_proto rules in dependencies.
86-
# By rewriting *_proto to *.proto above, the dependencies in *_proto rules are not preserved.
87-
# As a workaround, manually specify the proto dependencies for the imported python rules.
88-
if name == "annotations_py_proto":
89-
proto_deps = proto_deps + [":http_py_proto"]
90-
91-
# checked.proto depends on syntax.proto, we have to add this dependency manually as well.
92-
if name == "checked_py_proto":
93-
proto_deps = proto_deps + [":syntax_py_proto"]
94-
95-
# Special handling for expr_proto target
96-
if srcs[0] == ":expr_moved.proto":
97-
srcs = ["checked.proto", "eval.proto", "explain.proto", "syntax.proto", "value.proto"]
98-
proto_deps = proto_deps + ["@com_google_googleapis//google/rpc:status_py_proto"]
99-
100-
# py_proto_library does not support plugin as an argument yet at gRPC v1.25.0:
101-
# https://github.com/grpc/grpc/blob/v1.25.0/bazel/python_rules.bzl#L72.
102-
# plugin should also be passed in here when gRPC version is greater than v1.25.x.
103-
_py_proto_library(
104-
name = name,
105-
srcs = srcs,
106-
default_runtime = "@com_google_protobuf//:protobuf_python",
107-
protoc = "@com_google_protobuf//:protoc",
108-
deps = proto_deps + ["@com_google_protobuf//:protobuf_python"],
109-
visibility = ["//visibility:public"],
110-
)
111-
11254
def _api_cc_grpc_library(name, proto, deps = []):
11355
cc_grpc_library(
11456
name = name,
@@ -157,7 +99,15 @@ def api_cc_py_proto_library(
15799
deps = [relative_name],
158100
visibility = ["//visibility:public"],
159101
)
160-
_api_py_proto_library(name, srcs, deps)
102+
103+
# Uses gRPC implementation of py_proto_library.
104+
# https://github.com/grpc/grpc/blob/v1.59.1/bazel/python_rules.bzl#L160
105+
_py_proto_library(
106+
name = name + _PY_PROTO_SUFFIX,
107+
# Actual dependencies are resolved automatically from the proto_library dep tree.
108+
deps = [relative_name],
109+
visibility = ["//visibility:public"],
110+
)
161111

162112
# Optionally define gRPC services
163113
if has_services:

api/bazel/external_proto_deps.bzl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,3 @@ EXTERNAL_PROTO_CC_BAZEL_DEP_MAP = {
4949
"@opentelemetry_proto//:metrics": "@opentelemetry_proto//:metrics_cc_proto",
5050
"@opentelemetry_proto//:common": "@opentelemetry_proto//:common_cc_proto",
5151
}
52-
53-
# This maps from the Bazel proto_library target to the Python language binding target for external dependencies.
54-
EXTERNAL_PROTO_PY_BAZEL_DEP_MAP = {
55-
"@com_google_googleapis//google/api/expr/v1alpha1:checked_proto": "@com_google_googleapis//google/api/expr/v1alpha1:expr_py_proto",
56-
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_proto": "@com_google_googleapis//google/api/expr/v1alpha1:expr_py_proto",
57-
"@opencensus_proto//opencensus/proto/trace/v1:trace_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_proto_py",
58-
"@opencensus_proto//opencensus/proto/trace/v1:trace_config_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_config_proto_py",
59-
"@opentelemetry_proto//:trace": "@opentelemetry_proto//:trace_py_proto",
60-
"@opentelemetry_proto//:logs": "@opentelemetry_proto//:logs_py_proto",
61-
"@opentelemetry_proto//:metrics": "@opentelemetry_proto//:metrics_py_proto",
62-
"@opentelemetry_proto//:common": "@opentelemetry_proto//:common_py_proto",
63-
}

api/bazel/repository_locations.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ REPOSITORY_LOCATIONS_SPEC = dict(
3939
project_desc = "xDS API Working Group (xDS-WG)",
4040
project_url = "https://github.com/cncf/xds",
4141
# During the UDPA -> xDS migration, we aren't working with releases.
42-
version = "523115ebc1014a83e9cf1e85194ef8f8739d87c7",
43-
sha256 = "3bd28b29380372d54848111b12e24ec684f890032b42b2719ee6971658016b72",
42+
version = "83c031ea693357fdf7a7fea9a68a785d97864a38",
43+
sha256 = "35bdcdbcd2e437058ad1f74a91b49525339b028a6b52760ab019fd9efa5a6d44",
4444
release_date = "2023-06-07",
4545
strip_prefix = "xds-{version}",
4646
urls = ["https://github.com/cncf/xds/archive/{version}.tar.gz"],

bazel/repositories.bzl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,8 @@ def envoy_dependencies(skip_targets = []):
368368
name = "com_google_googleapis_imports",
369369
cc = True,
370370
go = True,
371+
python = True,
371372
grpc = True,
372-
rules_override = {
373-
"py_proto_library": ["@envoy_api//bazel:api_build_system.bzl", ""],
374-
},
375373
)
376374
native.bind(
377375
name = "bazel_runfiles",

tools/protodoc/BUILD

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("@base_pip3//:requirements.bzl", "requirement")
2-
load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")
2+
load("@com_github_grpc_grpc//bazel:python_rules.bzl", "py_proto_library")
3+
load("@rules_proto//proto:defs.bzl", "proto_library")
34
load("//bazel:envoy_build_system.bzl", "envoy_package")
45
load("//tools/base:envoy_python.bzl", "envoy_genjson", "envoy_jinja_env", "envoy_py_data", "envoy_pytool_binary", "envoy_pytool_library")
56
load("//tools/protodoc:protodoc.bzl", "protodoc_rule")
@@ -21,10 +22,22 @@ envoy_pytool_binary(
2122
],
2223
)
2324

24-
py_proto_library(
25+
proto_library(
2526
name = "manifest_proto",
2627
srcs = ["manifest.proto"],
27-
deps = ["@com_google_protobuf//:protobuf_python"],
28+
deps = [
29+
"@com_google_protobuf//:struct_proto",
30+
],
31+
)
32+
33+
py_proto_library(
34+
name = "manifest_py_pb2",
35+
deps = [":manifest_proto"],
36+
)
37+
38+
py_proto_library(
39+
name = "validate_py_pb2",
40+
deps = ["@com_envoyproxy_protoc_gen_validate//validate:validate_proto"],
2841
)
2942

3043
envoy_py_data(
@@ -39,7 +52,7 @@ envoy_pytool_binary(
3952
data = ["@envoy_api//:v3_proto_set"],
4053
deps = [
4154
requirement("envoy.base.utils"),
42-
":manifest_proto",
55+
":manifest_py_pb2",
4356
":protodoc_manifest_untyped",
4457
"@com_google_protobuf//:protobuf_python",
4558
],
@@ -110,8 +123,8 @@ envoy_pytool_binary(
110123
deps = [
111124
":data",
112125
":jinja",
126+
":validate_py_pb2",
113127
"//tools/api_proto_plugin",
114-
"@com_envoyproxy_protoc_gen_validate//validate:validate_py",
115128
"@com_github_cncf_xds//udpa/annotations:pkg_py_proto",
116129
"@com_github_cncf_xds//xds/annotations/v3:pkg_py_proto",
117130
requirement("envoy.code.check"),

tools/protoprint/BUILD

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@base_pip3//:requirements.bzl", "requirement")
2+
load("@com_github_grpc_grpc//bazel:python_rules.bzl", "py_proto_library")
23
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
34
load("@rules_pkg//pkg:pkg.bzl", "pkg_tar")
45
load("//bazel:envoy_build_system.bzl", "envoy_package")
@@ -22,14 +23,14 @@ envoy_pytool_binary(
2223
],
2324
visibility = ["//visibility:public"],
2425
deps = [
26+
":validate_py_pb2",
2527
"//tools/api_versioning:utils",
2628
"//tools/protoxform:options",
2729
"//tools/protoxform:utils",
2830
"@envoy_repo",
2931
requirement("packaging"),
3032
"//tools/type_whisperer",
3133
"//tools/type_whisperer:api_type_db_proto_py_proto",
32-
"@com_envoyproxy_protoc_gen_validate//validate:validate_py",
3334
"@com_github_cncf_xds//udpa/annotations:pkg_py_proto",
3435
"@com_github_cncf_xds//xds/annotations/v3:pkg_py_proto",
3536
"@com_google_googleapis//google/api:annotations_py_proto",
@@ -38,6 +39,11 @@ envoy_pytool_binary(
3839
],
3940
)
4041

42+
py_proto_library(
43+
name = "validate_py_pb2",
44+
deps = ["@com_envoyproxy_protoc_gen_validate//validate:validate_proto"],
45+
)
46+
4147
protoprint_rule(
4248
name = "protoprinted_srcs",
4349
deps = [

tools/protoxform/BUILD

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@aspect_bazel_lib//lib:jq.bzl", "jq")
2+
load("@com_github_grpc_grpc//bazel:python_rules.bzl", "py_proto_library")
23
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
34
load("@rules_pkg//pkg:pkg.bzl", "pkg_tar")
45
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
@@ -15,7 +16,6 @@ py_binary(
1516
":utils",
1617
"//tools/api_proto_plugin",
1718
"//tools/type_whisperer:api_type_db_proto_py_proto",
18-
"@com_envoyproxy_protoc_gen_validate//validate:validate_py",
1919
"@com_github_cncf_xds//udpa/annotations:pkg_py_proto",
2020
"@com_github_cncf_xds//xds/annotations/v3:pkg_py_proto",
2121
"@com_google_googleapis//google/api:annotations_py_proto",
@@ -33,6 +33,14 @@ py_library(
3333
name = "utils",
3434
srcs = ["utils.py"],
3535
visibility = ["//visibility:public"],
36+
deps = [
37+
":validate_py_pb2",
38+
],
39+
)
40+
41+
py_proto_library(
42+
name = "validate_py_pb2",
43+
deps = ["@com_envoyproxy_protoc_gen_validate//validate:validate_proto"],
3644
)
3745

3846
protoxform_rule(

0 commit comments

Comments
 (0)