Bazel support for protos

1,291 views
Skip to first unread message

dione...@gmail.com

unread,
Dec 22, 2016, 10:06:35 AM12/22/16
to bazel-discuss
Given the update of cc_proto_library in 0.4.3, I wanted to ask: what is the state of Bazel proto support at the moment?

Are Bazel proto rules usable for C++ and Java or are they not quite there yet? Do they support proto alone or is grpc also included? How do the rules actually work (genrule, action)?

(I know there are unofficial repos providing some of these rules but I'm particularly curious about the Bazel road map for protos).

Thanks!

ca...@google.com

unread,
Dec 22, 2016, 4:30:36 PM12/22/16
to bazel-discuss, dione...@gmail.com
I believe https://github.com/bazelbuild/rules_go/pull/121#issuecomment-251515362 sheds some light.

You should be able to use cc_proto_library() -
1. Clone the google/protobuf repo (git clone https://github.com/google/protobuf.git)
2. "import" it into your Bazel workspace, by adding

local_repository(
name = "com_google_protobuf_cc",
path = "/path/to/protobuf/repo",
)

3. Build your favorite proto -
(in a BUILD file:)

proto_library(name = "favorite_proto", srcs = ["favorite.proto"])
cc_proto_library(name = "favorite_cc_proto", deps = [":favorite_proto"])

4. File bugs!

dione...@gmail.com

unread,
Dec 22, 2016, 10:17:18 PM12/22/16
to bazel-discuss, dione...@gmail.com
Thanks for the pointer. That github post provides more info but it does not appear to give concrete details about Bazel Grpc support for C++ and Java.

For this release, I tried the cc_proto_library rule, both with local and git repo rules but could not get it to work.

The first issue was that the latest protobuf release is too old and does not have a cc_toolchain rule defined in its BUILD file. To solve this, I cloned from head but ran into another issue: --direct_dependencies_violation_msg is not found by protoc. Reading https://github.com/google/protobuf/issues/2426, my guess is that the flag was not yet implemented.

Am I missing something here or is the cc_proto_library depending on some protobuf work that is not yet complete?

>>>> # //examples:bank_proto [action 'Generating Descriptor Set proto_library //examples:bank_proto']
(cd /home/dragos/.cache/bazel/_bazel_dragos/46c01e0b42c636fbf0a61595f67d333d/execroot/proto_test && \
exec env - \
LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/mesa:/usr/lib/x86_64-linux-gnu/dri:/usr/lib/x86_64-linux-gnu/gallium-pipe \
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games \
bazel-out/host/bin/third_party/protobuf/protoc '--descriptor_set_out=bazel-out/local-fastbuild/genfiles/examples/bank_proto-descriptor-set.proto.bin' '-Iexamples/bank.proto=examples/bank.proto' '--direct_dependencies=' '--direct_dependencies_violation_msg=%s is imported, but //examples:bank_proto doesn'\''t directly depend on a proto_library that '\''srcs'\'' it.' examples/bank.proto)
ERROR: /home/dragos/proto_test/examples/BUILD:1:1: Generating Descriptor Set proto_library //examples:bank_proto failed: linux-sandbox failed: error executing command /home/dragos/.cache/bazel/_bazel_dragos/46c01e0b42c636fbf0a61595f67d333d/execroot/proto_test/_bin/linux-sandbox ... (remaining 8 argument(s) skipped).
Unknown flag: --direct_dependencies_violation_msg

On Thursday, December 22, 2016 at 10:06:35 AM UTC-5, dione...@gmail.com wrote:

Carmi Grushko

unread,
Dec 22, 2016, 11:58:51 PM12/22/16
to dione...@gmail.com, bazel-discuss
Right - I'm afraid you'll need to build proto-compiler from head. 
I won't be able to help in the next couple of weeks - hopefully other bazel team members are still around. 



--
You received this message because you are subscribed to a topic in the Google Groups "bazel-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bazel-discuss/651R_0JvDLk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/409c4277-b33b-4b31-bb89-25503beb366d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

dione...@gmail.com

unread,
Dec 23, 2016, 10:46:40 AM12/23/16
to bazel-discuss, dione...@gmail.com, ca...@google.com
Thanks! I opened https://github.com/bazelbuild/bazel/issues/2291 with Bazel. The issue is that the flag --direct_dependencies_violation_msg does not exist at all in the proto compiler code, not even at head.
> To unsubscribe from this group and all its topics, send an email to bazel-discus...@googlegroups.com.

Carmi Grushko

unread,
Dec 23, 2016, 1:03:04 PM12/23/16
to dione...@gmail.com, bazel-discuss
Thanks! This is more for /google/protobuf. I'll move it once I'm back.

To unsubscribe from this group and all its topics, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/d9d2e72e-f319-4032-ae45-779ebb8cfa1a%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages