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

Conversation

LucioFranco
Copy link
Member

Reopen of #140

BREAKING CHANGE: All services generated will be generated into their own module instead of an overall client or server module.

Joao Neves and others added 2 commits November 14, 2019 10:08
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)
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

Successfully merging this pull request may close these issues.

1 participant