Open vorner opened 5 years ago
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.
I think this is a good idea, definitely worth exploring. Taking a step back, it seems that prost
s 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.
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: