Skip to content
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

How to compile protos using protoc directly #330

Closed
DrRibosome opened this issue May 14, 2020 · 7 comments
Closed

How to compile protos using protoc directly #330

DrRibosome opened this issue May 14, 2020 · 7 comments

Comments

@DrRibosome
Copy link

DrRibosome commented May 14, 2020

Is there a way to compile .proto files using prost as a protoc plugin directly (eg, by calling protoc ... directly), without compiling via a build.rs? Ive been looking through the documentation but cant find any examples.

I've been looking through the source but didnt see any suitable binary targets that might be used with protoc

@danburkert
Copy link
Collaborator

prost currently doesn't ship a protoc plugin. Previous versions did, and I wouldn't be surprised if we did again in the future, but for now it's not a part of the project. You may be interested in https://github.com/danburkert/prost/pull/313

@avinassh
Copy link

avinassh commented May 20, 2020

why the newer versions did not include plugin? or why was it removed

@benma
Copy link

benma commented Jun 29, 2020

If it helps, I made a quick Rust cli tool to compile my protobufs. It does not use protoc ... but does the job anyway without build.rs.

fn main() {
    let messages_dir = std::env::var("MESSAGES_DIR").expect("MESSAGES_DIR env var not set");
    // OUT_DIR env var also required and is handled by prost.
    prost_build::compile_protos(&["my.proto"], &[&messages_dir]).unwrap();
}

@danburkert
Copy link
Collaborator

why the newer versions did not include plugin? or why was it removed

It was removed because no one was using it at the time, and I didn't want to continue supporting it. The way prost-build works out of the box is, in my opinion, the correct way for the vast majority of applications. Adding it back is non trivial for a few reasons:

  • It would require some refactoring to the prost-build APIs
  • It's not clear how the prost_build::Config options would get set in this scenario. Perhaps through env vars,but it would need to be figured out.

@henrikrudstrom
Copy link

But it does use the protoc binary under the hood right? at least i've stumbled upon some references to it in the docs.
regarding config options, protoc plugins can recieve options from the command line which are available in the CodeGeneratorRequest passed to the plugin. For example if the plugin is called protoc-gen-prost we can pass an arg to protoc --prost_opt=key=value,another_key=another_value.

I think a good usecase for the protoc plugin is to be compatible with grpc tooling, in-house tooling or for example buf/build

@neoeinstein
Copy link
Contributor

I know that this is a long old issue, but as mentioned, buf has come out with some great tooling around the use of protoc plugins to generate code for many languages. Having prost capable there would make it easy to snap into an ecosystem built around effective polyglot protobuf. (And that could then flow up to tonic as well.)

@LucioFranco
Copy link
Member

As of now support for anything major in prost will not likely happen inside the prost crate but might come as support externally #492 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants