Skip to content
This repository has been archived by the owner on Apr 16, 2020. It is now read-only.

Codegen generates invalid code for proto files containing multiple service definitions #9

Closed
hawkw opened this issue Dec 22, 2017 · 1 comment

Comments

@hawkw
Copy link
Member

hawkw commented Dec 22, 2017

Noticed this while working on #3 (gRPC interop test cases). When a .proto file defines multiple services, tower-grpc-build will generate a separate pub mod server and pub mod client for each service in the generated code's root module. Needless to say, the Rust compiler doesn't like this.

Failing example (I modified helloworld.proto):

syntax = "proto3";

package helloworld;

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

service Welcomer {
  rpc SayHi (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
  string name = 1;
}

message HelloReply {
  string message = 1;
}

and compiler errors:

   Compiling tower-grpc-examples v0.1.0 (file:///Users/eliza/Code/tower-grpc/tower-grpc-examples)
error[E0428]: the name `client` is defined multiple times
   --> /Users/eliza/Code/tower-grpc/target/debug/build/tower-grpc-examples-e932e45db921086e/out/helloworld.rs:232:1
    |
14  | / pub mod client {
15  | |     use ::tower_grpc::codegen::client::*;
16  | |     use super::{HelloRequest, HelloReply};
17  | |
...   |
44  | |     }
45  | | }
    | |_- previous definition of the module `client` here
...
232 | / pub mod client {
233 | |     use ::tower_grpc::codegen::client::*;
234 | |     use super::{HelloRequest, HelloReply};
235 | |
...   |
262 | |     }
263 | | }
    | |_^ `client` redefined here
    |
    = note: `client` must be defined only once in the type namespace of this module

error[E0428]: the name `server` is defined multiple times
   --> /Users/eliza/Code/tower-grpc/target/debug/build/tower-grpc-examples-e932e45db921086e/out/helloworld.rs:265:1
    |
47  | / pub mod server {
48  | |     use ::tower_grpc::codegen::server::*;
49  | |     use super::{HelloRequest, HelloReply};
50  | |
...   |
229 | |     }
230 | | }
    | |_- previous definition of the module `server` here
...
265 | / pub mod server {
266 | |     use ::tower_grpc::codegen::server::*;
267 | |     use super::{HelloRequest, HelloReply};
268 | |
...   |
447 | |     }
448 | | }
    | |_^ `server` redefined here
    |
    = note: `server` must be defined only once in the type namespace of this module

error: aborting due to 2 previous errors
@hawkw hawkw self-assigned this Dec 22, 2017
@hawkw
Copy link
Member Author

hawkw commented Dec 22, 2017

Of course, generating server code from protos with multiple services won't really work until #2 is done, since we can only serve one service per socket address, but it seems like we should be able to at least generate that compiles --- we might want to generate client code from a proto with multiple services, or have a server select which service to serve?

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

No branches or pull requests

1 participant