Skip to content
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

google.protobuf.rs becomes bigger after each build #63

Open
Chaoses-Ib opened this issue Apr 5, 2024 · 2 comments
Open

google.protobuf.rs becomes bigger after each build #63

Chaoses-Ib opened this issue Apr 5, 2024 · 2 comments

Comments

@Chaoses-Ib
Copy link

I ran into a problem where add_serde() will append trait impls to google.protobuf.rs after each build, but neither prost nor prost-wkt would clear it, so it only becomes bigger and bigger.

pub fn add_serde(out: PathBuf, descriptor: FileDescriptorSet) {
for fd in &descriptor.file {
let package_name = match fd.package {
Some(ref pkg) => pkg,
None => continue,
};
let rust_path = out
.join(Module::from_protobuf_package_name(package_name).to_file_name_or(package_name));
// In some cases the generated file would be in empty. These files are no longer created by Prost, so
// we'll create here. Otherwise we append.
let mut rust_file = OpenOptions::new()
.create(true)
.append(true)
.open(rust_path)
.unwrap();
for msg in &fd.message_type {
let message_name = match msg.name {
Some(ref name) => name,
None => continue,
};
let type_url = format!("type.googleapis.com/{package_name}.{message_name}");
gen_trait_impl(&mut rust_file, package_name, message_name, &type_url);
}
}
}

And I found the generated google.protobuf.rs isn't actually used, so the duplicated code won't break the build. But if anyone includes the generated files in VCS, there will be a problem. A simple workaround I currently use is to remove google.protobuf.rs after add_serde():

_ = fs::remove_file(out.join("google.protobuf.rs"));
@fdeantoni
Copy link
Owner

Thanks for raising this! Indeed not good if the file keeps growing. I will dig a little deeper to see what the best solution is.

@wtzhang23
Copy link

I played around with creating a derive proc-macro which could help in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants