-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Proto package name must match filename #1007
Comments
Hi, For other languages there are file options to override the generated package (e.g. |
Hello @g0hl1n , I'm looking for the solution of overriding the package name in rust as you mentioned. Is this feature available in tonic now? thanks! |
All of the generated code is possible to be generated into the src dir and changed manually. I don't think we will add specific support for renaming the module unless its specifically breaking some weird part of codegen. |
Changing generated code doesn't seem like a valid approach to me. @beinan whats the reason you want to change the crate name of the generated code? What are the pros/cons of adding something like an |
Thank you @g0hl1n and @LucioFranco for the reply! Another reason is I'm working on a rust client for a Java grpc service, the package names in grpc proto files are a little bit too deep to maintain in rust, so I'm thinking if we could override package name in rust |
Yes, I would recommend doing something like what is done in |
+1 for having a FileOption extension named The recommendation in this discussion of generating the files in the repository and modifying the files by name is not a production-grade solution, especially in huge and polyglot environments where code generation is automated and/or controlled hermetically (see Bazel's philosophy for example). I will try to implement a FileOption extension in a local fork and, in case it does work well, might open a merge request. |
I also believe that having an |
For optional support we will need #674 |
Also need this function! |
+1 for having a way to specify the package name outside of the file path. I'm currently dealing with proto files with long paths, which leads to a deep folder structure and having to import the code through Edit: I wrote this small hack to solve the import issue. use std::fs::OpenOptions;
use std::io::Write;
static suffix: &str = r#"
pub mod foobar {
pub use crate::path::to::package::*;
}
"#;
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::configure()
// ...
.compile(
&["pb/foobar.proto"],
&["pb"]
)?;
let mut file = OpenOptions::new()
.write(true)
.append(true)
.open("src/pb/mod.rs")
.unwrap();
if let Err(e) = write!(file, "{}", suffix) {
eprintln!("Could not write to file: {}", e)
}
Ok(())
} |
Bug Report
Version
Platform
Description
helloworld.proto
:request.proto
:This gives a lot of errors that all look like:
This works fine if I change the package from
r
torequest
(and update relevant references)Things also work fine if the packages match - changing
r
tohelloworld
.There is a decent chance I'm just doing things wrong.
Side Note
It would be nice if we could eschew package names altogether - in other languages, I normally only see packages specified in order to differentiate similarly named types. Rust/tonic is forcing me to update cross language proto use to have packages.
The text was updated successfully, but these errors were encountered: