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

fix(build): Allow creating multiple services in the same package #173

Merged
merged 2 commits into from
Dec 11, 2019

Commits on Nov 14, 2019

  1. Enable multiple services in same package across multiple files

    Prior to this change, for each _file_ containing one or more
    services, the code generator would generate with the following
    modules:
    
    ```
    pub mod client {
     //...
    }
    
    pub mod server {
     //...
    }
    ```
    
    While this works fine if all the services in the same protobuf
    package are declared in a single file, this breaks horribly if
    multiple files belonging to the same protobuf package declare
    services. In that case, the code generator would generate several
    modules with the same name in the same `.rs` file, which is
    invalid.
    
    For instance, given two files `foo.proto` and `bar.proto` like:
    
    ```
    // foo.proto
    package mypackage;
    service Foo {
    }
    
    // bar.proto
    package mypackage;
    service Bar {
    }
    ```
    
    The generated code would result in a `mypackage.rs` such as:
    
    ```
    // Generated from foo.proto
    pub mod client {
      //...
    }
    
    pub mod server {
      //...
    }
    
    // Generated from bar.proto
    pub mod client {
      //...
    }
    
    pub mod server {
      //...
    }
    ```
    
    This change makes it so the name of the service is prepended to
    the generated module, and therefore we avoid module name collisions.
    
    After this change, given the two proto files mentioned previously,
    we will generate the following modules inside `mypackage.rs`:
    
    ```
    pub mod foo_client {
     //...
    }
    
    pub mod foo_server {
     //...
    }
    
    pub mod bar_client {
     //...
    }
    
    pub mod bar_server {
     //...
    }
    ```
    
    One codebase where this scenario could be found is in
    [Open Match](https://github.com/googleforgames/open-match/tree/master/api)
    Joao Neves committed Nov 14, 2019
    Configuration menu
    Copy the full SHA
    af75394 View commit details
    Browse the repository at this point in the history

Commits on Dec 11, 2019

  1. Configuration menu
    Copy the full SHA
    5c86fc8 View commit details
    Browse the repository at this point in the history