-
Notifications
You must be signed in to change notification settings - Fork 533
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
Customising generated file name #173
Comments
I use the following code in my build.rs file, it's really ugly but it works use std::fs;
use std::io;
use std::path::Path;
fn rename_prost_generated_filenames(dir: &Path) -> io::Result<()> {
if dir.is_dir() {
for entry in fs::read_dir(dir)? {
let entry = entry?;
let path = entry.path();
if path.is_file() {
let file_stem_renamed = &path
.file_stem()
.unwrap()
.to_str()
.unwrap()
.replace(".", "_");
fs::rename(&path, dir.join(format!("{}.rs", file_stem_renamed)))?;
}
}
}
Ok(())
}
fn main() {
let src = Path::new("src");
let mut config = prost_build::Config::default();
config.out_dir(src);
config.compile_protos(&["protobuf/myproto.proto"], &["protobuf"]).unwrap();
rename_prost_generated_filenames(&src).unwrap();
} |
Thanks @harscoet, it's better than nothing. I'll try it out |
Thanks
Thanks! It'd be much better to have configuration option to rename the output names. Otherwise it's painful for versioning package names with things like |
To those who will use this super helpful solution: don't forget to modify the code to keep the extension as is, otherwise extensions like E.g. let ext = path.extension().unwrap().to_str().unwrap();
rename(&path, dir.join(format!("{}.{}", file_stem_renamed, ext)))?; |
I'm using tower-grpc with prost, and I have proto files whose package names I can't change.
Where the package name is
package foo.bar
, I end up withfoo.bar.rs
where it would be better to havefoo_bar.rs
.The
.
instead of_
forces me toinclude!()
the file in my mods, which breaks autocomplete in VS Code.Is there an option that I'm missing? I've already looked into tower-grpc-build, and it doesn't have any options for this as it inherits prost's
Config
.I use
OUT_DIR=src/gen/
, so I ideally would like to exclude the need to use theinclude!()
macro in my module imports. ThanksThe text was updated successfully, but these errors were encountered: