grpc / grpc/grpc-rust

Generated filenames with custom suffix

Open
#1,107 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
12.5k
Forks
1.3k
Avg merge
4d 7h
Merged PRs (30d)
24

Description

## 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 `..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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.