-
Notifications
You must be signed in to change notification settings - Fork 37
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
Build: one proto per proto_library #26
Conversation
Hi @srikrsna-buf thanks for the prompt reply! I see, gazelle does indeed bundle all I am not super familiar with gazelle but I found discussions and PRs related to enabling a "per-file" mode (directive
I guess we can close this PR as the solution would be to enable this mode instead of manually changing the build files, right? As per your question, the rule throwing the error is from an internal tool that is enforcing the |
@srikrsna-buf I have updated the PR by reverting the previous changes and adding the |
Hey @ggirelli You'll also need to run gazelle for it to update the targets. |
@srikrsna-buf sounds good. I ended up changing it to set the directive only in that directory because otherwise it breaks most build files due to an inconsistent naming of the |
@@ -42,3 +42,16 @@ cc_proto_library( | |||
visibility = ["//visibility:public"], | |||
deps = [":validate_proto"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will need to add the expression_proto
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not so sure 🤔 :expression_proto
is already in the dependencies of :validate_proto
so it should work correctly as is, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That won't generate for dependencies we will need a second cc_proto_library
rule for generating the corresponding cc files for expression_proto
. That should be a dependency for this library.
Output of bazel build //proto/protovalidate/buf/validate:validate_proto_cc
:
Target //proto/protovalidate/buf/validate:validate_proto_cc up-to-date:
bazel-bin/proto/protovalidate/buf/validate/_virtual_imports/validate_proto/buf/validate/validate.pb.h
bazel-bin/proto/protovalidate/buf/validate/_virtual_imports/validate_proto/buf/validate/validate.pb.cc
bazel-bin/proto/protovalidate/buf/validate/libvalidate_proto.a
Notice how it only generates validate files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc_proto_library
supports only a singular proto_library
dependency, so I cannot add :expression_proto
directly there.
But, I can add a cc_proto_library
for expression.proto
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I meant the new cc_proto_library
should be the dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But cc_proto_library
supports only a single proto_library
dependency, with no other dependencies. If I try to pass an extra cc_proto_library
as a dependency, the build will fail.
Honestly, I feel like the extra cc_proto_library
is not helping.
With the previous build file (without the expression_proto_cc
rule), while it is true that bazel build
lists only the direct targets, I do see the dependency proto c
code being generated:
$ bazel build //proto/protovalidate/buf/validate:validate_proto_cc
INFO: Streaming build results to: ###
INFO: Analyzed target //proto/protovalidate/buf/validate:validate_proto_cc (1 packages loaded, 5 targets configured).
INFO: Found 1 target...
Target //proto/protovalidate/buf/validate:validate_proto_cc up-to-date:
bazel-bin/proto/protovalidate/buf/validate/_virtual_imports/validate_proto/buf/validate/validate.pb.h
bazel-bin/proto/protovalidate/buf/validate/_virtual_imports/validate_proto/buf/validate/validate.pb.cc
bazel-bin/proto/protovalidate/buf/validate/libvalidate_proto.a
bazel-bin/proto/protovalidate/buf/validate/libvalidate_proto.so
INFO: Elapsed time: 5.506s, Critical Path: 4.76s
INFO: 27 processes: 19 internal, 8 linux-sandbox.
INFO: Streaming build results to: ###
INFO: Build completed successfully, 27 total actions
$ ls bazel-bin/proto/protovalidate/buf/validate/_virtual_imports/
expression_proto validate_proto
$ ls bazel-bin/proto/protovalidate/buf/validate/_virtual_imports/expression_proto/buf/validate/expression.p*
bazel-bin/proto/protovalidate/buf/validate/_virtual_imports/expression_proto/buf/validate/expression.pb.cc
bazel-bin/proto/protovalidate/buf/validate/_virtual_imports/expression_proto/buf/validate/expression.pb.h
bazel-bin/proto/protovalidate/buf/validate/_virtual_imports/expression_proto/buf/validate/expression.proto
$ ls bazel-bin/proto/protovalidate/buf/validate/_virtual_imports/validate_proto/buf/validate/validate.p*
bazel-bin/proto/protovalidate/buf/validate/_virtual_imports/validate_proto/buf/validate/validate.pb.cc
bazel-bin/proto/protovalidate/buf/validate/_virtual_imports/validate_proto/buf/validate/validate.pb.h
bazel-bin/proto/protovalidate/buf/validate/_virtual_imports/validate_proto/buf/validate/validate.proto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ggirelli!
Bazel docs recommend:
I also encountered the following error when trying to include
protovalidate
in some internal repos:This is a very small change but it would be amazing to get it into the next release 🙏🏻