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

Crazy idea: generating messages through function-style proc macro instead of build.rs #144

Open
vorner opened this issue Jan 8, 2019 · 2 comments

Comments

@vorner
Copy link
Contributor

vorner commented Jan 8, 2019

The build.rs approach to compiling proto files works, but is in some ways cumbersome.

I wonder if it would be possible to abuse the function-style procedural macros to generate the messages „inline“ somehow. From what I get, the input of the macro is only tokenized, but not checked in other ways, and .proto might be similar enough to pass through the rust tokenizer.

So I wonder if it would make sense to try to do something like that and see if/how that would work and how much effort that would take:

prost_derive::compile! {
    input!("../protos/my_message.proto");
}
@timthelion
Copy link
Contributor

This would be nice except that this might interfering with learning/debugging. Currently, it's often easier to look directly in target/debug/../out/fooproto.rs and read the generated code to figure out how something works, than it is to try to figure out how the documentation relates to your exact protobuf file.

@danburkert
Copy link
Collaborator

I think this is a good idea, definitely worth exploring. Taking a step back, it seems that prosts inflexibility regarding codegen[1] is working well for the 80% case, but there's a long tail of applications which need something a bit more tailored. Perhaps it would be worth looking into an additional api in prost-build to make it more like a library. It may be as simple as exposing Config::generate publicaly, although more thought should probably be put into it. Two potential consumers are a proc-macro, and a protoc plugin for doing ahead-of-time code generation[2].

[1]: specifically, prost strongly encourages or requires codegen to be done in a build.rs with the help of prost-build.

[2]: prost used to provide this, but I removed it citing lack of interest; the project has grown significantly in user base since then, though.

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

3 participants