andrewhickman / protox

A pure-rust protobuf compiler, designed for use with prost-build
Apache License 2.0
73 stars 6 forks source link

Docs/Example request: example for integration with `tonic_build` #7

Closed nathan-at-least closed 1 year ago

nathan-at-least commented 1 year ago

I'm somewhat familiar with using tonic_build as a black-box, and I'm looking for a way to avoid the non-rust protoc dependency.

The only example I see here is integrating with prost_build but I haven't yet figured out the relationship between tonic_build and prost_build.

The only mention of prost_types::FileDescriptorSet I see in in tonic_build is tonic_build::Builder::file_descriptor_set_path and that reads to me like it causes tonic_build to generate the FileDescriptorSet which seems like the same purpose of protox::compile.

How can I integrate protox and tonic_build to enable a build free of non-rust dependencies for tonic server/client?

nathan-at-least commented 1 year ago

After more digging, I see prost_build::Config::compile_fds and tonic_build::Builder::compile_with_config so there's almost a connection.

However, it appears that tonic_build::Builder::compile_with_config (line 534) delegates directly to prost_build::Config::compile_protos. Since that is an alternate "entry point" vs compile_fds I currently believe it's not possible to connect up protox into the tonic_build flow.

I'm going to go file a ticket with tonic_build to highlight this issue.

andrewhickman commented 1 year ago

I've not tried this with tonic_build, but it should be possible to write the file descriptor set to a file, set file_descriptor_set_path() to point at it, and then set skip_protoc_run to bypass the normal protoc invocation

compile_fds is much nicer though, I think tonic just hasn't got a wrapper for it yet since its a newer API.

nathan-at-least commented 1 year ago

Tangential question: I'm only familiar with the tonic use case. What are use cases that rely directly on prost?

andrewhickman commented 1 year ago

My personal use-case is lanquetta, a tool for testing gRPC services. It uses tonic and prost but not tonic-build/prost-build (since all the protobuf definitions are loaded at runtime). The fact it can be used in build scripts is a nice bonus 😄