-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Using proto_source_root in proto_library breaks java_grpc_library #4896
Comments
To help reproduce this problem easily, I've isolated the problem on a branch on my repo: https://github.com/haikalpribadi/grakn/tree/bazel-init-grpc-java-broken-with-proto-source-root The Once you clone the repo, you just need to run Thank you! |
The cleanest way to solve this is to use the dsc file/transitive_descriptor_sets from the proto_library plus descriptor_set_in to protoc, as then java_grpc_library no longer has to deal with imports and listing files and means java_grpc_library wouldn't break as proto_library adds new features. The code change for this is trivial, but last time I tried to do that I broke some existing users as the dsc building was stricter. I may try to do that again and figure out exactly where the incompatibility came from. Although it's probably also fairly easy to add support for proto_source_root directly to java_grpc_library, but I'll need to research it some. |
Thanks, @ejona86. Is there any examples on how to use file/transitive_descriptor_sets ? Although, I do think adding |
This is what I was suggesting with the descriptor set.
For the solution like this, java_grpc_library wouldn't need any additional configuration, it would just be changed to look at proto_library's configuration. |
I see! Sorry I didn't get your first point, but I do now. :)
Do you mean |
No, I was meaning it would use the value directly from the proto_library. Although we're not using aspects in java_grpc_library, that's more of the style of how proto_library is expected to be integrated with. For reference, here's the type of changes necessary for using the descriptor set. But it is based on the internal copy which is basically slowly being rewritten and I've not yet exported the changes (limited time and I'm "not done yet"). --- a/java/grpc/build_defs.bzl 2018-07-23 17:24:35.000000000 -0700
+++ b/java/grpc/build_defs.bzl 2018-07-25 13:48:29.000000000 -0700
@@ -10,9 +10,6 @@
-def _create_include_path(include):
- return "-I{0}={1}".format(include.short_path, include.path)
-
def _short_path(src):
return src.short_path
@@ -24,7 +21,7 @@
"same package as consuming rule").format(ctx.label, ctx.attr.srcs[0].label))
srcs = ctx.attr.srcs[0].proto.direct_sources
- includes = ctx.attr.srcs[0].proto.transitive_imports
+ descriptor_set_in = ctx.attr.srcs[0].proto.transitive_descriptor_sets
flavor = ctx.attr.flavor
if flavor == "normal":
flavor = ""
@@ -32,11 +29,11 @@
args = ctx.actions.args()
args.add(ctx.executable._java_plugin.path, format = "--plugin=protoc-gen-grpc-java=%s")
args.add("--grpc-java_out={0}:{1}".format(flavor, ctx.outputs.srcjar.path))
- args.add_all(includes, map_each = _create_include_path)
+ args.add_joined("--descriptor_set_in", descriptor_set_in, join_with = ":")
args.add_all(srcs, map_each = _short_path)
ctx.action(
- inputs = depset([ctx.executable._java_plugin] + srcs, transitive = [includes]),
+ inputs = depset([ctx.executable._java_plugin] + srcs, transitive = [descriptor_set_in]),
outputs = [ctx.outputs.srcjar],
executable = ctx.executable._protoc,
arguments = [args], |
Alright, I see. It makes to me from a high level, but unfortunately, my 2 weeks old knowledge of Bazel might not be enough for me to submit a PR for this. :/ |
Hello, I have a similar problem but I didn't understand the solution. I used proto source root in my proto_library and it can be compiled fine but when I use grpc_proto_library to generate grpc stubs, it gives import not found and file not found (i.e. it cannot fine the imports in the protobuf that I define the services) |
Eric, May I ask you what is the status of this change? Can you give me some guidelines If I want to work on it. We need to get it fixed to use for a project. Thanks, |
Honestly, for the while my recommendation is "don't do that;" always import from the base directory. This is what Blaze has required of us, for example. So I see this more as a feature request with a possible workaround. Why is this fix required for a project? |
Let me explain our situation: Please take a look at: https://github.com/dnosproject/dnos-core-grpc/blob/master/protobuf/proto/BUILD Does that mean we should change our imports or can we still use net/link/LinkEvent.proto? Is my explanation clear? If not let me know and I will try to explain it in a better way. |
Ah, I understand more. I didn't realize proto_source_ root was available now-a-days. I want to use that internally to make the import easier! (Right now we apply some diffs to just to fix the .proto imports.) (Yes, I know it was all mentioned clearly earlier, but I had been dealing with various "proto did something interesting in random case X". Instead of investigating what the new option was I was thinking of swapping to the descriptor set approach gets us out of the business of tracking them.) proto_source_root is available in ProtoInfo, so this should be pretty easy. Basically it would be an additional string concat any place we use _path_ignoring_repository (to add I'd be happy to accept a PR; this is something that someone else could figure out semi-easily (unless anything goes wrong!). But I also agree that Skylark/Bazel rules are quite involved. I might be able to get to this next week. |
I am not completely familiar with grpc-java code so I will try but I think you will get it work before I do. Please update me if you fix it so I can get a new version of that to test. Thanks. |
@adibrastegarnia, I tried this out today. It turned out to be "not easy." So don't waste your time trying to figure it out; I am still debugging what's wrong. |
@ejona86 |
Eric, Any updates on this issue? |
No, no updates. |
I dug into this more. I may be missing something simple, but it currently seems mostly unsupportable. It seems like it requires using an aspect, plus some very specific logic. I tried using the transitive descriptors, and they appear not to save any effort with this particular feature. The only ways this could be implemented would be for ProtoInfo to include more information or for proto_toolchain to open itself up to Skylark implementations. To give a sampling of how Bazel itself is using this stuff: Part of the problem is that when using proto_source_root you can still do imports based on the full path. (That is, it seems you can take any proto_library and add proto_source_root to it without breaking the build.) I'll need to have some conversations with the Bazel folks at some point. |
Thanks Eric for the update.
Part of the problem is that when using proto_source_root you can still do
imports based on the full path. (That is, it seems you can take any
proto_library and add proto_source_root to it without breaking the build.)
This is exactly what I do as a workaround. Do you think should we go for
that workaround or wait to get it fixed?
Adib
…On Fri, Jan 25, 2019 at 12:23 PM Eric Anderson ***@***.***> wrote:
I dug into this more. I may be missing something simple, but it currently
seems mostly unsupportable. It seems like it requires using an aspect, plus
some very specific logic. I tried using the transitive descriptors, and
they appear not to save any effort with this particular feature.
The only ways this could be implemented would be for ProtoInfo to include
more information or for proto_toolchain to open itself up to Skylark
implementations.
To give a sampling of how Bazel itself is using this stuff:
https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java#L288
https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java#L698
Part of the problem is that when using proto_source_root you can still do
imports based on the full path. (That is, it seems you can take any
proto_library and add proto_source_root to it without breaking the build.)
I'll need to have some conversations with the Bazel folks at some point.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4896 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AJ4q3KMpY1DeI480wMZLjFABH02J-JKZks5vGz2hgaJpZM4XDFay>
.
|
@adibrastegarnia, I don't really see how that is a "workaround" as it is equivalent to not using proto_source_root. For now, I'd recommend not using proto_source_root. I'm not expecting a quick fix. But I also need to talk with the Bazel folks. |
@ejona86 |
FYI: bazelbuild/bazel#7153 , |
Thanks Eric for the update. Glad to hear it gets fixed.
…On Wed, Feb 13, 2019 at 3:45 PM Eric Anderson ***@***.***> wrote:
FYI: bazelbuild/bazel#7153
<bazelbuild/bazel#7153> , proto_source_root is
being replaced with strip_import_prefix
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4896 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AJ4q3JffoFuzbsFI-G75yBqmc6B6Y_lIks5vNHlxgaJpZM4XDFay>
.
|
Fixed by #5959 |
Please answer these questions before submitting your issue.
What version of gRPC are you using?
v1.15.0
What did you expect to see?
Say I have 2 proto files sitting in
//some-package/
//some-package/A.proto
whichimports B.proto
(withoutsome-package
as prefix)//some-package/B.proto
Then I compile the
proto_library in
//some-package/BUILD`, like the following:The above works well because
proto_source_root
, which allows us to not have to import one proto file into another using the full path relative from WORKSPACE.As instructed on GRPC docs (https://grpc.io/docs/reference/java/generated-code.html) Next I compile
java_proto_library
:This also works fine. But finally, I compile
java_grpc_library
:And here it breaks.
java_grpc_library
failes to compile with error:So basically,
A.proto
cannot findB.proto
. However, when I replace the import statement inA.proto
withimport some-package/B.proto
and remove usage ofproto_source_root
inproto_library
everything works, but we really don't want to do this for many reasons.Does anyone know what could be the cause and how to work around this?
The text was updated successfully, but these errors were encountered: