-
Notifications
You must be signed in to change notification settings - Fork 113
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
Switch from rust_protobuf
to prost
for protobuf generation
#668
Comments
@tiziano88 rust_protobuf is no longer used for the core components, but is still used in the examples through |
Good question, now that we don't have a hard requirement to be |
I personally prefer Prost, but that could just be because i am more familiar with it. Also, Prost is used by Tonic, so if we plan on using that in future as a gRPC server it might be more natural to use Prost. But, if we are just going to proxy the request body bytes to the nodes, then it probably doesn't matter and the nodes can decide how they interpret it. |
I think it is not quite maintainable to have both. I already ran into some problems with conflicting blanket implementations, when trying to use Prost for LogMessage. So, I think, eventually we should either change the sdk and the examples to use Prost, or change the core components to use rust_protobuf. (I am assuming that the Having said that, I don't really have a preference. Although with my very limited experience, I found Prost to be a bit neater (I did not look into code generation for gRPC). |
@wildarch as part of your experiments, did you figure out whether it is possible to rely on Could you try to define a custom option, assign it to a field, and see whether during code generation time (i.e. as part of running |
I am actually in the process of doing exactly this! For now I got stuck at the situation described in https://github.com/danburkert/prost/issues/256, where for some weird reason the |
@wildarch did you try to dump the incoming message that protoc itself sends to the |
I did, and unfortunately it doesn't contain the custom option. |
Do you have the code you used to test that? I wonder if we could try something similar using |
I have put the code up at https://github.com/wildarch/handle_extract. It contains a dump of the file descriptor set that prost-build uses to generate rust types: https://github.com/wildarch/handle_extract/blob/master/descriptor_set.textproto. Note line https://github.com/wildarch/handle_extract/blob/master/descriptor_set.textproto#L10763 specifically, which shows an options message that is set, but does not contain any elements. |
What if you set a standard option on that field, e.g. |
It sets |
Note that In your case, I believe the parser does recognise it. |
I wonder if the issue is just converting the binary proto file to textproto. Have you tried inspecting the binary file directly from python? It may be that extensions are dropped when printing out (which would make sense to me) |
I have tried to check |
@tiziano88 this discussion is about the lack of extension support in prost, is that correct? Do you see oak using extensions in the foreseeable future? |
We would need it for #673 to annotate handle types. |
@wildarch it's still worth trying to dump the proto descriptor from within a plugin, rather than just from protoc. I am pretty sure I used field extensions from other plugins I wrote in different languages, and the extensions were there. |
Will do! My suspicion is that somehow plugins do get these extensions, but the dumped |
So it turns out that in order to get the python script to work (both the dumper and the plugin) you have to first compile the proto file that contains the extension for python, import the generated module in the script that parses the proto files, and then the extension magically appears. I'm not quite sure yet how this will work for our setup, but at least now we know it is doable to parse these extensions and use them to generate code. |
I don't think this experiment is particularly conclusive for us :) if anything it seems bad news to me, because it means that custom options are indeed serialized as extensions, and we know that prost does not support extensions, so there is probably no way to get access to them from the prost plugin implementation. Or did I miss something? |
Yeah it is definitely bad news for moving to prost. I think there is still a way to save this though: We could patch the protobuf compiler descriptor proto and make the handle type a regular field, which is binary compatible with declaring it as an extension. This would require a bit of hacking on the prost-build crate, but everything else could stay nice and straightforward (we would still have a handle type extension that clients use normally). If this works well we could even upstream changes to prost to allow people to supply their own compiler protos, potentially. |
@wildarch this is the Rust type that we would like to generate for handle fields: oak/sdk/rust/oak/src/io/sender.rs Lines 27 to 31 in 6a6ec36
We can assume that We still need to figure out how to extract handles into a separate slice, and also what to do about repeated fields (or we can just make it work for non-repeated fields to start with). |
#673 is no longer a blocker for switching to Prost, I have a POC that is fully based on Prost. |
Do we have a tracker somewhere to see which parts of the codebase still need to be migrated? |
@wildarch no tracker, everything above the Wasm abi is still rust_protobuf I believe (i.e. sdk and examples). |
@tiziano88, @wildarch: While this is still underway, would it make sense to shift the codebase to use a single consistent protobuf library1 in the meanwhile? I ask because this blocks #764 which blocks #801 (since #772 was merged)… 1: Which I guess would have to be |
I agree, but let me take a quick look to see how much work it would be to just rewrite the gRPC generation logic for prost first. |
BTW @daviddrysdale is there a preference for either rust-protobuf or prost from the point of view of Bazel integration? |
No, I don't think the tool choice should matter for Bazel integration. |
@daviddrysdale I don't know if you were planning on using |
@tiziano88 I don't know whether you have seen this, but Prost build provides a standard way for adding service code generation logic to proto compilation: https://docs.rs/prost-build/0.6.1/prost_build/trait.ServiceGenerator.html |
Thanks @conradgrobler , yes that's exactly what I am planning to use. |
Main differences: - use `::default` instead of `::new` to create instances - use native field accessors - use native Option and Vec types for optional and repeated fields - dispatcher struct has a more qualified name - gRPC generator code is encapsulated in a prost ServiceGenerator - use `quote!` macros instead of string concatenation in the generator Fixes project-oak#668
Main differences: - use `::default` instead of `::new` to create instances - use native field accessors - use native Option and Vec types for optional and repeated fields - dispatcher struct has a more qualified name - gRPC generator code is encapsulated in a prost ServiceGenerator - use `quote!` macros instead of string concatenation in the generator Fixes project-oak#668
Main differences: - use `::default` instead of `::new` to create instances - use native field accessors - use native Option and Vec types for optional and repeated fields - dispatcher struct has a more qualified name - gRPC generator code is encapsulated in a prost ServiceGenerator - use `quote!` macros instead of string concatenation in the generator Fixes project-oak#668
Main differences: - use `::default` instead of `::new` to create instances - use native field accessors - use native Option and Vec types for optional and repeated fields - dispatcher struct has a more qualified name - gRPC generator code is encapsulated in a prost ServiceGenerator - use `quote!` macros instead of string concatenation in the generator Fixes project-oak#668
Main differences: - use `::default` instead of `::new` to create instances - use native field accessors - use native Option and Vec types for optional and repeated fields - dispatcher struct has a more qualified name - gRPC generator code is encapsulated in a prost ServiceGenerator - use `quote!` macros instead of string concatenation in the generator Fixes project-oak#668
Main differences: - use `::default` instead of `::new` to create instances - use native field accessors - use native Option and Vec types for optional and repeated fields - dispatcher struct has a more qualified name - gRPC generator code is encapsulated in a prost ServiceGenerator - use `quote!` macros instead of string concatenation in the generator Fixes project-oak#668
Main differences: - use `::default` instead of `::new` to create instances - use native field accessors - use native Option and Vec types for optional and repeated fields - dispatcher struct has a more qualified name - gRPC generator code is encapsulated in a prost ServiceGenerator - use `quote!` macros instead of string concatenation in the generator Fixes #668
ref:
We already have a few PRs that switched parts of the source tree to use
prost
; if we prefer that, we should go ahead and switch to it fully.pros:
cons:
The text was updated successfully, but these errors were encountered: