I've been introduced to this discussion group by Ofer from the Bazel team. Very excited to see a Bazel+Python specialist group!
'm trying to work on this issue (https://github.com/protocolbuffers/protobuf/issues/5147) and submit a PR to extend protobuf example documentation for Bazel by adding py_proto_library.
I'm starting by trying to integrate py_proto_library into our repository, aiming to have it look like how java_proto_library is shown in the examples/BUILD and examples/WORKSPACE files in protobuf's repository.
So I thought I'd share what I have here and where I'm stuck. Perhaps someone can help. Please do let me know if I should post this somewhere else, or in a new issue.
So far I've defined the following:
//dependencies/compilers:dependencies.bzl:
```
def protobuf_dependencies():
native.http_archive(
name = "bazel_skylib",
sha256 = "bbccf674aa441c266df9894182d80de104cabd19be98be002f6d478aaa31574d",
strip_prefix = "bazel-skylib-2169ae1c374aab4a09aa90e65efe1a3aad4e279b",
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"],
)
native.bind(name = "six", actual = "@six_archive//:six")
native.new_http_archive(
name = "six_archive",
build_file = "@com_google_protobuf//:six.BUILD",
sha256 = "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a",
urls = ["https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz#md5=34eed507548117b2ab523ab14b2f8b55"],
)
# This com_google_protobuf repository is required for proto_library rule.
# It provides the protocol compiler binary (i.e., protoc).
native.http_archive(
name = "com_google_protobuf",
sha256 = "0a4c6d0678eb2f063df332cff1a41647ef692c067b5cfb19e51bca778e79d9e0",
strip_prefix = "protobuf-3.6.1",
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protobuf-all-3.6.1.zip"],
)
```
WORKSPACE:
```
load("//dependencies/compilers:dependencies.bzl", "protobuf_dependencies")
protobuf_dependencies()
load("@bazel_skylib//:lib.bzl", "versions")
versions.check(minimum_bazel_version = "0.5.4")
//client-protocol/BUILD
proto_library(
name = "client-protocol",
srcs = glob(["proto/*.proto"]),
visibility = [
"//server:__subpackages__",
"//client-java:__subpackages__",
"//client-python:__subpackages__",
]
)
```
//client-python/BUILD
```
load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")
py_proto_library(
name = "protocol",
deps = ["//client-protocol:client-protocol"],
protoc = "@com_google_protobuf//:protoc",
)
```
Everything works fine for //server:... and //client-java:.... But when I try to bazel build //client-python:protocol, I get the following error:
```
ERROR: /Users/haikalpribadi/Workspace/repos/graknlabs/grakn/client-python/BUILD:21:1: in deps attribute of py_library rule //client-python:protocol: '//client-protocol:client-protocol' does not have mandatory providers: 'py'. Since this rule was created by the macro 'py_proto_library', the error might have been caused by the macro implementation in /private/var/tmp/_bazel_haikalpribadi/3cdeaa1301f056ec7b4e7ee46bda5c79/external/com_google_protobuf/protobuf.bzl:382:12
```
I can't find any reference on the internet to the error message shown above, except for this bazelbuild/bazel#4237
Does anyone have any idea what is the cause of this problem and how to solve it?
Thank you so much!