Skip to content

Commit 1dbde95

Browse files
authored
fix(build): Fix service and rpc name conflict (#92)
Closes #89
1 parent 50424a6 commit 1dbde95

File tree

11 files changed

+63
-16
lines changed

11 files changed

+63
-16
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ members = [
44
"tonic-build",
55
"tonic-examples",
66
"tonic-interop",
7+
8+
"tests/same_name",
9+
"tests/wellknown",
710
]

tests/same_name/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "same_name"
3+
version = "0.1.0"
4+
authors = ["Lucio Franco <luciofranco14@gmail.com>"]
5+
edition = "2018"
6+
publish = false
7+
8+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
9+
10+
[dependencies]
11+
tonic = { path = "../../tonic" }
12+
bytes = "0.4"
13+
prost = "0.5"
14+
15+
[build-dependencies]
16+
tonic-build = { path = "../../tonic-build" }

tests/same_name/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
tonic_build::compile_protos("proto/foo.proto").unwrap();
3+
}

tests/same_name/proto/foo.proto

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
syntax = "proto3";
2+
3+
package foo;
4+
5+
service Foo {
6+
rpc Foo(stream FooRequest) returns (stream FooResponse) {}
7+
}
8+
9+
message FooRequest {}
10+
11+
message FooResponse {}

tests/same_name/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod pb {
2+
tonic::include_proto!("foo");
3+
}

tests/wellknown/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "wellknown"
3+
version = "0.1.0"
4+
authors = ["Lucio Franco <luciofranco14@gmail.com>"]
5+
edition = "2018"
6+
publish = false
7+
8+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
9+
10+
[dependencies]
11+
tonic = { path = "../../tonic" }
12+
bytes = "0.4"
13+
prost = "0.5"
14+
prost-types = "0.5"
15+
16+
[build-dependencies]
17+
tonic-build = { path = "../../tonic-build" }

tests/wellknown/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
tonic_build::compile_protos("proto/wellknown.proto").unwrap();
3+
}

tests/wellknown/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod pb {
2+
tonic::include_proto!("wellknown");
3+
}

tonic-build/src/server.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ fn generate_unary(
223223
proto_path: &str,
224224
server_trait: Ident,
225225
) -> TokenStream {
226-
let service_ident = Ident::new(&method.proto_name, Span::call_site());
226+
let service_ident = quote::format_ident!("{}Svc", method.proto_name);
227227

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)