Repository: tokio-rs/prost (language: rust)

Issue:
prost-build generates empty files
Here is my `build.rs`:

```
fn main() {
	prost_build::compile_protos(
		&["src/plugin.proto"],
		&["src/"],
	).expect("protobuf compilation failed");
}
```

And `plugin.proto` is copy/pasted from [this page](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.compiler.plugin.pb).

When I `cargo build` it generates no errors, and it does generate these two files:

* `myproject/target/debug/build/myproject-9d87c2b89447dc16/out/google.protobuf.compiler.rs`
* `myproject/target/debug/build/myproject-9d87c2b89447dc16/out/google.protobuf.rs`

However they are both empty files. Any ideas? I've used prost-build successfully on the same machine in a different project with a proto file I wrote myself (using proto3 syntax).


Discussion / hints:
I think it is an issue with `.`s in the package name.
If I change the package name to use underscores instead of dots, it gets a bit further but complains that `FileDescriptorProtos` is an unknown type. It's weird because shouldn't that type be defined in the `import 'google/...` file? And if not shouldn't that `import` line give an error first?
Ok the behaviour seems to be that if the package name contains any `.`'s then it is treated as an empty file.

To get the `plugin.proto` to work I had to also add `descriptor.proto` (both copied from this repo) and then change the package names to the same name (that didn't contain `.`).
`prost-build` has special behavior to recognize when you are attempting to compile any protobuf 'well known types', and skips compiling them. This is because the `prost-types` crate already contains pre-compiled versions of these types.

If you'd like to turn off this special casing, use [`Config::compile_well_known_types`](https://docs.rs/prost-build/0.5.0/prost_build/struct.Config.html#method.compile_well_known_types).
but in case it's not clear, I'd suggest _not_ doing that, and instead using the `prost-types` crate.  It exists so that you don't get a proliferation of unique well known types across a bunch of different invocations to `compile_protos`.
When using `compile_protos` with `prost-types`, shouldn't the empty `google.protobuf.rs` not be created though? 
Hey @danburkert , wanted to ping on this as I'm getting the same issue as @WhoisDavid  - even when using the `prost-types` crate I get an empty `google.protobuf.rs` file
Yep, I think I misunderstood the issue when I closed this issue the first time, apologies.  I've noticed this myself when spelunking through build dirs recently.  I think `prost-build` is just missing some logic to skip writing empty files.  Should be an easy fix if anyone wants to work on it.
Would be interesting to see what the current/nominal behavior with an empty .proto file is, though.  Maybe these prost-types packages should be special cased.
Thanks @danburkert , super fast response time -  https://www.reddit.com/r/rust/comments/czxny2/which_protocol_buffers_crates_to_invest_in/ was definitely right :) Skipping the empty files sounds like the best solution; I'm a Rust newbie as of this week and need to pound out a bindings library by EOW, but if you can point me to where the files are written I might be able to take a stab during lunch

Fix patch:
diff --git a/prost-build/src/lib.rs b/prost-build/src/lib.rs
index edf91a6a8..5259ea4dd 100644
--- a/prost-build/src/lib.rs
+++ b/prost-build/src/lib.rs
@@ -869,6 +869,10 @@ impl Config {
 
         let modules = self.generate(requests)?;
         for (module, content) in &modules {
+            if content.is_empty() {
+                continue;
+            }
+
             let file_name = file_names
                 .get(module)
                 .expect("every module should have a filename");


Test patch: