Skip to content

Commit

Permalink
fix(build): Fix service and rpc name conflict (#92)
Browse files Browse the repository at this point in the history
Closes #89
  • Loading branch information
LucioFranco committed Oct 23, 2019
1 parent 50424a6 commit 1dbde95
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 16 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ members = [
"tonic-build",
"tonic-examples",
"tonic-interop",

"tests/same_name",
"tests/wellknown",
]
16 changes: 16 additions & 0 deletions tests/same_name/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "same_name"
version = "0.1.0"
authors = ["Lucio Franco <luciofranco14@gmail.com>"]
edition = "2018"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tonic = { path = "../../tonic" }
bytes = "0.4"
prost = "0.5"

[build-dependencies]
tonic-build = { path = "../../tonic-build" }
3 changes: 3 additions & 0 deletions tests/same_name/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
tonic_build::compile_protos("proto/foo.proto").unwrap();
}
11 changes: 11 additions & 0 deletions tests/same_name/proto/foo.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";

package foo;

service Foo {
rpc Foo(stream FooRequest) returns (stream FooResponse) {}
}

message FooRequest {}

message FooResponse {}
3 changes: 3 additions & 0 deletions tests/same_name/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod pb {
tonic::include_proto!("foo");
}
17 changes: 17 additions & 0 deletions tests/wellknown/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "wellknown"
version = "0.1.0"
authors = ["Lucio Franco <luciofranco14@gmail.com>"]
edition = "2018"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tonic = { path = "../../tonic" }
bytes = "0.4"
prost = "0.5"
prost-types = "0.5"

[build-dependencies]
tonic-build = { path = "../../tonic-build" }
3 changes: 3 additions & 0 deletions tests/wellknown/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
tonic_build::compile_protos("proto/wellknown.proto").unwrap();
}
File renamed without changes.
3 changes: 3 additions & 0 deletions tests/wellknown/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod pb {
tonic::include_proto!("wellknown");
}
8 changes: 4 additions & 4 deletions tonic-build/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ fn generate_unary(
proto_path: &str,
server_trait: Ident,
) -> TokenStream {
let service_ident = Ident::new(&method.proto_name, Span::call_site());
let service_ident = quote::format_ident!("{}Svc", method.proto_name);

let (request, response) = crate::replace_wellknown(proto_path, &method);

Expand Down Expand Up @@ -262,7 +262,7 @@ fn generate_server_streaming(
proto_path: &str,
server_trait: Ident,
) -> TokenStream {
let service_ident = Ident::new(&method.proto_name, Span::call_site());
let service_ident = quote::format_ident!("{}Svc", method.proto_name);

let (request, response) = crate::replace_wellknown(proto_path, &method);

Expand Down Expand Up @@ -305,7 +305,7 @@ fn generate_client_streaming(
proto_path: &str,
server_trait: Ident,
) -> TokenStream {
let service_ident = Ident::new(&method.proto_name, Span::call_site());
let service_ident = quote::format_ident!("{}Svc", method.proto_name);

let (request, response) = crate::replace_wellknown(proto_path, &method);

Expand Down Expand Up @@ -346,7 +346,7 @@ fn generate_streaming(
proto_path: &str,
server_trait: Ident,
) -> TokenStream {
let service_ident = Ident::new(&method.proto_name, Span::call_site());
let service_ident = quote::format_ident!("{}Svc", method.proto_name);

let (request, response) = crate::replace_wellknown(proto_path, &method);

Expand Down
12 changes: 0 additions & 12 deletions tonic-build/tests/wellknown.rs

This file was deleted.

0 comments on commit 1dbde95

Please sign in to comment.