orbitalci / orbital

Orbital is a self-hosted CI system for solo/small consulting dev teams. Written in Rust.
GNU General Public License v3.0
29 stars 2 forks source link

tonic-build proto codegen duplicates server/client code when importing proto and fails to compile #229

Closed tjtelan closed 4 years ago

tjtelan commented 4 years ago

Related to #227

While refactoring during migration from tower-grpc to tonic, I started getting strange compiler issues around codegen that weren't about new function signatures being incorrect due to new async types.

After a careful effort of picking apart all my codegen, I narrowed the issue to the generation of models/proto/organization.proto.

When I comment out the import for credential.proto, the compiler errors stop. But uncommented, I get these type related errors for types that are defined in the credential package.

https://github.com/level11consulting/orbitalci/blob/85f1d2e938c2d404c7ea133b2e4e3002324cac22/models/protos/organization.proto#L5


error[E0412]: cannot find type `VcsCredCreateRequest` in module `super`
   --> /Users/telant/src/orbitalci/target/debug/build/orbital_headers-33f24b51d23a648e/out/organization.rs:190:53
    |
190 |             request: impl tonic::IntoRequest<super::VcsCredCreateRequest>,
    |                                                     ^^^^^^^^^^^^^^^^^^^^ not found in `super`
help: possible candidate is found in another module, you can import it into scope
    |
152 |     use crate::credential::VcsCredCreateRequest;
[...]
    |```

It seems that the cause is generated server + client code in the `organization` package that should only be in the `credential` package. The compiler error is because none of the message types from `credential` generate.

My workaround was to break the proto rpc definitions into another proto file, so that I could import all the message types but none of the service rpc definitions. This is inconvenient, but is usable for now.