proto_library() target support?

652 views
Skip to first unread message

Eric Zundel Ayers

unread,
Mar 25, 2015, 8:56:58 AM3/25/15
to bazel-...@googlegroups.com

There are some references to a target named  proto_library()  in the docs, and a definition for objc_proto_library() but no actual entry in the BUILD encyclopedia at http://bazel.io/docs/build-encyclopedia.html. I did some grepping around in the source and didn’t see it included.

I see ‘genproto’ defined in tools/build_rules/genproto.bzl withe comment:

# This is a quick and dirty rule to make Bazel compile itself.  It
# only supports Java.

Is that the recommended course for using protobufs or is something more forthcoming (I didn’t see it on the roadmap)?

Lukács T. Berki

unread,
Mar 25, 2015, 9:11:55 AM3/25/15
to Eric Zundel Ayers, bazel-...@googlegroups.com, Marian Lobur
Marian is working on it, so proper protocol buffer support is coming, but not very soon. It's quite deeply intertwined with rules for other languages we are not open sourcing and it's not very modular (yes, these two are related issues :) ), and it will take some time to disentangle it enough so that we can move it to the open source tree.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To post to this group, send email to bazel-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAOy0ARc8Ax%2BYYhc2s2g%2BPE_%3DYFqiY0MRz2NY-%2Bm4xhnwBdNiAQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Eric Zundel Ayers

unread,
Mar 25, 2015, 9:17:46 AM3/25/15
to Lukács T. Berki, bazel-...@googlegroups.com, Marian Lobur
Thanks for the response.

Something that we dedicated quite a bit of effort to in Pants was getting protobufs to build properly when they import from .protos defined in Jars from Maven.  Hopefully that will be easier in Bazel!

Jeff Cox

unread,
Mar 25, 2015, 9:19:16 AM3/25/15
to Lukács T. Berki, Eric Zundel Ayers, bazel-...@googlegroups.com, Marian Lobur

Han-Wen Nienhuys

unread,
Mar 25, 2015, 10:05:48 AM3/25/15
to Eric Zundel Ayers, Lukács T. Berki, bazel-...@googlegroups.com, Marian Lobur
On Wed, Mar 25, 2015 at 2:17 PM, Eric Zundel Ayers <zun...@squareup.com> wrote:
> Thanks for the response.
>
> Something that we dedicated quite a bit of effort to in Pants was getting
> protobufs to build properly when they import from .protos defined in Jars
> from Maven. Hopefully that will be easier in Bazel!

To be honest, I didn't even know that people packed .proto files
inside jars. I suppose you could use

http://bazel.io/docs/build-encyclopedia.html#new_http_archive

to import the jar as a normal ZIP file, and then write a rule that
consumes the proto file.
> https://groups.google.com/d/msgid/bazel-discuss/CAOy0ARfhknxcWR2uoYHWO18oTdPGAmi_sr5AGgZVQj4y7O%3D%3Dug%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Han-Wen Nienhuys
Google Munich
han...@google.com

Lukács T. Berki

unread,
Mar 25, 2015, 10:19:01 AM3/25/15
to Eric Zundel Ayers, bazel-...@googlegroups.com, Marian Lobur
On Wed, Mar 25, 2015 at 2:17 PM, Eric Zundel Ayers <zun...@squareup.com> wrote:
Thanks for the response.

Something that we dedicated quite a bit of effort to in Pants was getting protobufs to build properly when they import from .protos defined in Jars from Maven.
wat. Can you point me to an example of this? 

Eric Zundel Ayers

unread,
Mar 25, 2015, 10:35:51 AM3/25/15
to Lukács T. Berki, bazel-...@googlegroups.com, Marian Lobur
Hopefully this is not an issue with Bazel. 

Inside of Square, we have a few dozen individual git repos that publish protos.    Some are Java, some are not.  They all publish them in .jar files to our nexus.  

To import protos defined outside of the source tree, the protobuf compiler needs access to the .proto files, not just the generated class files created by the protobuf compiler.  The maven-protobuf-plugin handles this by putting the .protos in the imported .jars on the proto path.

Pants gathers together all of the .protos that need compiling and builds them in one invocation of the protoc compiler.  I think is a difference between Pants and Bazel.

To support this in Pants, we tried 2 things:

1) Extract the .protos from the artifacts, then mimic the maven protobuf compiler and put the .protos on the protopath and then depend on the binary classes created from the other repo.  


  We ultimately abandoned this approach because it required the protobuf compiler and plugins we used to be in sync across all repos.  

2) Unpack the published jars and extract the .proto files and re-compile them in our repo.


  This is what we are using today.  


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To post to this group, send email to bazel-...@googlegroups.com.

Abhishek Parmar

unread,
Mar 28, 2015, 4:17:18 PM3/28/15
to bazel-...@googlegroups.com, zun...@squareup.com, lob...@google.com
Hi Lukacs,
It seems like I should be able to define my own cc_proto extension/macro using the genrules and cc_libarary. Do you see any problems with that specially if all imports/includes paths are fully specified (relate to src root) as in google's codebase?

I am eager to use bazel and this is one thing I would need.

-Abhishek

Ulf Adams

unread,
Mar 29, 2015, 10:14:58 AM3/29/15
to Abhishek Parmar, bazel-...@googlegroups.com, zun...@squareup.com, Marian Lobur
Hi Abhishek,

I don't see any obvious issues. Give it a try and report back if things don't work, in which case we may be able to help.

-- Ulf

Kevin Watts

unread,
Apr 15, 2015, 4:37:00 PM4/15/15
to bazel-...@googlegroups.com, abhi...@carbon3d.com, zun...@squareup.com, lob...@google.com
Here's a "protobuf.bzl" file I wrote for C++ proto generation and library building. You'll need to have a version of the proto compiler in third_party.

Kevin
protobuf.bzl

Kevin Watts

unread,
Apr 15, 2015, 8:34:29 PM4/15/15
to bazel-...@googlegroups.com, abhi...@carbon3d.com, zun...@squareup.com, lob...@google.com
Attached is a protobuf.bzl file that I'm using. It requires the proto compiler in the "//tools" path.



On Sunday, March 29, 2015 at 7:14:58 AM UTC-7, Ulf Adams wrote:
protobuf.bzl

Austin Schuh

unread,
Apr 20, 2015, 4:22:22 PM4/20/15
to Kevin Watts, bazel-...@googlegroups.com, abhi...@carbon3d.com, zun...@squareup.com, lob...@google.com
Looking at the rule, I don't see a way for a proto_library to depend on another proto_library (properly).  For example:

proto_library(
  name = 'foo',
  srcs = ['foo.proto'],
)

proto_library(
  name = 'bar',
  srcs = ['bar.proto'],
  deps = [':foo'],
)

When foo.proto changes, you should re-build bar, no?

Austin

Kevin Watts

unread,
Apr 20, 2015, 5:16:38 PM4/20/15
to bazel-...@googlegroups.com, zun...@squareup.com, kevin...@google.com, lob...@google.com, abhi...@carbon3d.com
You're right, I think I need to add a dependency in the "genrule" part of the macro. Thanks for catching that.
Reply all
Reply to author
Forward
0 new messages