-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Defining a Skylark py_proto_library via proto_library #3935
Comments
The idea here is that:
|
@dslomov can Bazel team do a worked example of using aspects + providers to implement a |
any update on this would be really appreciated |
Which rule should I use for now? |
A rule can not generate a file that is outside the target package that invoked the rule. Will probably have to use aspects that propogate to all the proto_library dependencies of py_proto_library/py_grpc_library rules, and then combine the outputs and make them available to the py_library rule (bazelbuild/bazel#3935)
@dslomov @brandjon |
+@hlopko since I think there's plans about prioritizing proto support in general. |
Yes, I'm trying to get us a person to work on proto rules. No concrete results yet, only active effort :) |
Any updates on this? |
Yes, we didn't get the person :/ I'm actively trying to prioritize this, but more important stuff keeps coming up. |
Why not leverage the work being done here? It seems they are handling Python and a few more languages. https://github.com/stackb/rules_proto |
Also worth noting that grpc folks did implement https://github.com/grpc/grpc/blob/master/bazel/python_rules.bzl#L88 Here's link to the functioning example: https://github.com/stackb/rules_proto/tree/5050a8a13d6d13d4284c0cc9f3711181f532f4bb/example/py_grpc_library |
What's the Bazel team's philosophy on rules like the As a user of these rules it becomes difficult to understand which one is the best/right one to use since they all tend to function in the same way (except some use the |
As far as I've tried, none of these What I would expect with a proto_library(
name = "foo_proto",
srcs = ["foo.proto"],
deps = [
"bar_proto",
"@com_google_protobuf//:timestamp_proto",
],
)
py_proto_library(
name = "foo_py_pb2",
deps = [":foo_proto"],
)
proto_library(
name = "bar_proto",
srcs = ["bar.proto"],
)
py_proto_library(
name = "bar_py_pb2",
deps = [":bar_proto"],
)
# Using foo_py_pb2 without fuss
py_library(
deps = [":foo_py_pb2"],
) Basically:
|
Has there been any action here? Agree with the last 2 comments, each version has its own quirks and does not align with internal Google use, which is quite frustrating when trying to maintain open-source libraries that Google also uses. |
Hi I'm curious about the current state. Reading the current implementation of py_proto_library in protocobuffer repo, it says
https://github.com/protocolbuffers/protobuf/blob/main/protobuf.bzl#L636 Did it happen? |
I found this doc which has a nice summary of all the options. Between
Does anyone know if using |
Starlark |
py_proto_library provided by @com_google_protobuf//:protobuf.bzl has been deprecated for a while now: This is provided for backwards compatibility only. Bazel 5.3 will introduce support for py_proto_library, which should be used instead. https://github.com/protocolbuffers/protobuf/blob/32af7d211b85f71920acdfa9b796db008f8c2a45/protobuf.bzl#L642-L644 However, native py_proto_library has never been provided, see bazelbuild/bazel#3935. Instead @rules_python//python:proto.bzl is recommended. I attempted switching to this library, but it's not compatible with @com_google_googleapis's py_proto_library targets, see #69. I found a hacky workaround by using cc_proto_library to generate python targets, but downstream integration into Envoy failed (envoyproxy/envoy#30159). This PR migrates py_proto_library implementation to to @com_github_grpc_grpc. This implementation is used by @com_google_googleapis's, and, more importantly, uses bazel aspects. Which decouples cncf/xds and Envoy's dependencies from concrete upstream py_proto_library implementations. This resulted in a significant code improvement of bazel/api_build_system.bzl: No more custom @com_google_googleapis dependency mapping needed via py_proto_library rules override. No more hardcoded dependencies _xds_py_proto_library - proto dependency tree is determined from proto_library definitions via Basel aspects. No more EXTERNAL_PROTO_PY_BAZEL_DEP_MAP dependency map needed - for the same reason. Similar work in Envoy: envoyproxy/envoy#30834. Signed-off-by: Sergii Tkachenko <[email protected]>
Given #2626, I was wondering whether it would be possible to add a pure Skylark
py_proto_library
built onproto_library
.I've played around with rules and had a look at how rules_go does this with toolchains (https://github.com/bazelbuild/rules_go/pull/803/files). These basically involve you maintaining an additional dependency tree (which
proto_library
is supposed to solve) and having your custompy_proto_library
applied across this tree. The most promising approach to avoiding this seems to be to use aspects.It's pretty clear how aspects could be used to invoke
protoc
to generate the_pb2.py
files. What's less clear is how to use these outputs, which are unknown ahead of time and come from theproto_library
transitive dep provider, in conjunction with the nativepy_library
rule (I think this is the sandwich problem?).Any guidance here from the Bazel proto or Python teams?
The text was updated successfully, but these errors were encountered: