fix(build): Allow creating multiple services in the same package#173
Merged
LucioFranco merged 2 commits intomasterfrom Dec 11, 2019
Merged
fix(build): Allow creating multiple services in the same package#173LucioFranco merged 2 commits intomasterfrom
LucioFranco merged 2 commits intomasterfrom
Conversation
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)
This was referenced Dec 11, 2019
This was referenced Dec 12, 2019
rabbitinspace
pushed a commit
to satelit-project/tonic
that referenced
this pull request
Jan 1, 2020
…erium#173) BREAKING CHANGE: Build will now generate each service client and server into their own modules.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reopen of #140
BREAKING CHANGE: All services generated will be generated into their own module instead of an overall
clientorservermodule.