Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions api/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ load(
"EXTERNAL_PROTO_CC_BAZEL_DEP_MAP",
"EXTERNAL_PROTO_GO_BAZEL_DEP_MAP",
"EXTERNAL_PROTO_IMPORT_BAZEL_DEP_MAP",
"EXTERNAL_PROTO_PY_BAZEL_DEP_MAP",
)

licenses(["notice"]) # Apache 2
Expand Down Expand Up @@ -38,6 +37,5 @@ json_data(
cc = EXTERNAL_PROTO_CC_BAZEL_DEP_MAP,
go = EXTERNAL_PROTO_GO_BAZEL_DEP_MAP,
imports = EXTERNAL_PROTO_IMPORT_BAZEL_DEP_MAP,
py = EXTERNAL_PROTO_PY_BAZEL_DEP_MAP,
),
)
70 changes: 10 additions & 60 deletions api/bazel/api_build_system.bzl
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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")
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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 0 additions & 12 deletions api/bazel/external_proto_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,3 @@ EXTERNAL_PROTO_CC_BAZEL_DEP_MAP = {
"@opentelemetry_proto//:metrics": "@opentelemetry_proto//:metrics_cc_proto",
"@opentelemetry_proto//:common": "@opentelemetry_proto//:common_cc_proto",
}

# This maps from the Bazel proto_library target to the Python language binding target for external dependencies.
EXTERNAL_PROTO_PY_BAZEL_DEP_MAP = {
"@com_google_googleapis//google/api/expr/v1alpha1:checked_proto": "@com_google_googleapis//google/api/expr/v1alpha1:expr_py_proto",
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_proto": "@com_google_googleapis//google/api/expr/v1alpha1:expr_py_proto",
"@opencensus_proto//opencensus/proto/trace/v1:trace_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_proto_py",
"@opencensus_proto//opencensus/proto/trace/v1:trace_config_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_config_proto_py",
"@opentelemetry_proto//:trace": "@opentelemetry_proto//:trace_py_proto",
"@opentelemetry_proto//:logs": "@opentelemetry_proto//:logs_py_proto",
"@opentelemetry_proto//:metrics": "@opentelemetry_proto//:metrics_py_proto",
"@opentelemetry_proto//:common": "@opentelemetry_proto//:common_py_proto",
}
4 changes: 2 additions & 2 deletions api/bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ REPOSITORY_LOCATIONS_SPEC = dict(
project_desc = "xDS API Working Group (xDS-WG)",
project_url = "https://github.com/cncf/xds",
# During the UDPA -> xDS migration, we aren't working with releases.
version = "523115ebc1014a83e9cf1e85194ef8f8739d87c7",
sha256 = "3bd28b29380372d54848111b12e24ec684f890032b42b2719ee6971658016b72",
version = "83c031ea693357fdf7a7fea9a68a785d97864a38",
sha256 = "35bdcdbcd2e437058ad1f74a91b49525339b028a6b52760ab019fd9efa5a6d44",
Comment on lines +42 to +43
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this will be updated once cncf/xds#74 is merged.

release_date = "2023-06-07",
strip_prefix = "xds-{version}",
urls = ["https://github.com/cncf/xds/archive/{version}.tar.gz"],
Expand Down
4 changes: 1 addition & 3 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,8 @@ def envoy_dependencies(skip_targets = []):
name = "com_google_googleapis_imports",
cc = True,
go = True,
python = True,
grpc = True,
rules_override = {
"py_proto_library": ["@envoy_api//bazel:api_build_system.bzl", ""],
},
)
native.bind(
name = "bazel_runfiles",
Expand Down
23 changes: 18 additions & 5 deletions tools/protodoc/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@base_pip3//:requirements.bzl", "requirement")
load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")
load("@com_github_grpc_grpc//bazel:python_rules.bzl", "py_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//bazel:envoy_build_system.bzl", "envoy_package")
load("//tools/base:envoy_python.bzl", "envoy_genjson", "envoy_jinja_env", "envoy_py_data", "envoy_pytool_binary", "envoy_pytool_library")
load("//tools/protodoc:protodoc.bzl", "protodoc_rule")
Expand All @@ -21,10 +22,22 @@ envoy_pytool_binary(
],
)

py_proto_library(
proto_library(
name = "manifest_proto",
srcs = ["manifest.proto"],
deps = ["@com_google_protobuf//:protobuf_python"],
deps = [
"@com_google_protobuf//:struct_proto",
],
)

py_proto_library(
name = "manifest_py_pb2",
deps = [":manifest_proto"],
)

py_proto_library(
name = "validate_py_pb2",
deps = ["@com_envoyproxy_protoc_gen_validate//validate:validate_proto"],
)

envoy_py_data(
Expand All @@ -39,7 +52,7 @@ envoy_pytool_binary(
data = ["@envoy_api//:v3_proto_set"],
deps = [
requirement("envoy.base.utils"),
":manifest_proto",
":manifest_py_pb2",
":protodoc_manifest_untyped",
"@com_google_protobuf//:protobuf_python",
],
Expand Down Expand Up @@ -110,8 +123,8 @@ envoy_pytool_binary(
deps = [
":data",
":jinja",
":validate_py_pb2",
"//tools/api_proto_plugin",
"@com_envoyproxy_protoc_gen_validate//validate:validate_py",
"@com_github_cncf_xds//udpa/annotations:pkg_py_proto",
"@com_github_cncf_xds//xds/annotations/v3:pkg_py_proto",
requirement("envoy.code.check"),
Expand Down
8 changes: 7 additions & 1 deletion tools/protoprint/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@base_pip3//:requirements.bzl", "requirement")
load("@com_github_grpc_grpc//bazel:python_rules.bzl", "py_proto_library")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_pkg//pkg:pkg.bzl", "pkg_tar")
load("//bazel:envoy_build_system.bzl", "envoy_package")
Expand All @@ -22,14 +23,14 @@ envoy_pytool_binary(
],
visibility = ["//visibility:public"],
deps = [
":validate_py_pb2",
"//tools/api_versioning:utils",
"//tools/protoxform:options",
"//tools/protoxform:utils",
"@envoy_repo",
requirement("packaging"),
"//tools/type_whisperer",
"//tools/type_whisperer:api_type_db_proto_py_proto",
"@com_envoyproxy_protoc_gen_validate//validate:validate_py",
"@com_github_cncf_xds//udpa/annotations:pkg_py_proto",
"@com_github_cncf_xds//xds/annotations/v3:pkg_py_proto",
"@com_google_googleapis//google/api:annotations_py_proto",
Expand All @@ -38,6 +39,11 @@ envoy_pytool_binary(
],
)

py_proto_library(
name = "validate_py_pb2",
deps = ["@com_envoyproxy_protoc_gen_validate//validate:validate_proto"],
)

protoprint_rule(
name = "protoprinted_srcs",
deps = [
Expand Down
10 changes: 9 additions & 1 deletion tools/protoxform/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@aspect_bazel_lib//lib:jq.bzl", "jq")
load("@com_github_grpc_grpc//bazel:python_rules.bzl", "py_proto_library")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_pkg//pkg:pkg.bzl", "pkg_tar")
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
Expand All @@ -15,7 +16,6 @@ py_binary(
":utils",
"//tools/api_proto_plugin",
"//tools/type_whisperer:api_type_db_proto_py_proto",
"@com_envoyproxy_protoc_gen_validate//validate:validate_py",
"@com_github_cncf_xds//udpa/annotations:pkg_py_proto",
"@com_github_cncf_xds//xds/annotations/v3:pkg_py_proto",
"@com_google_googleapis//google/api:annotations_py_proto",
Expand All @@ -33,6 +33,14 @@ py_library(
name = "utils",
srcs = ["utils.py"],
visibility = ["//visibility:public"],
deps = [
":validate_py_pb2",
],
)

py_proto_library(
name = "validate_py_pb2",
deps = ["@com_envoyproxy_protoc_gen_validate//validate:validate_proto"],
)

protoxform_rule(
Expand Down