tonic
tonic copied to clipboard
Generated filenames with custom suffix
Feature Request
Crate
tonic-build
Motivation
I work a project that runs multiple code generators over our proto files, and I'm encountering a filename conflict between tonic and another generator. This got me thinking that the C++ grpc generator allows you to specify an output suffix, and it'd be great if tonic allowed the same level of flexibility.
Proposal
Looking through the code, I see:
/// Generated services will be output into the directory specified by `out_dir`
/// with files named `<package_name>.<service_name>.rs`.
pub fn compile(self, services: &[Service]) {
...
let out_file = out_dir.join(format!("{}.{}.rs", service.package, service.name));
}
I'd like to change this to something like this:
...
let suffix = format!("{}.rs", service.custom_suffix.unwrap_or(""));
let out_file = out_dir.join(format!("{}.{}{}", service.package, service.name, suffix));
}
So by default the behavior would be unchanged. But it would now allow for more complex build situations, like my own.
My hope is to be able to do this file.proto
-> [package.]service.grpc.rs
Alternatives
Not really. Just thought I'd document a case where the existing solution is not flexible enough for my needs.