fix(build): Fix service and rpc name conflict (#92)

Closes #89
This commit is contained in:
Lucio Franco
2019-10-23 15:01:04 -04:00
committed by GitHub
parent 50424a66ef
commit 1dbde95d84
11 changed files with 63 additions and 16 deletions
+3
View File
@@ -4,4 +4,7 @@ members = [
"tonic-build",
"tonic-examples",
"tonic-interop",
"tests/same_name",
"tests/wellknown",
]
+16
View File
@@ -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
View File
@@ -0,0 +1,3 @@
fn main() {
tonic_build::compile_protos("proto/foo.proto").unwrap();
}
+11
View File
@@ -0,0 +1,11 @@
syntax = "proto3";
package foo;
service Foo {
rpc Foo(stream FooRequest) returns (stream FooResponse) {}
}
message FooRequest {}
message FooResponse {}
+3
View File
@@ -0,0 +1,3 @@
pub mod pb {
tonic::include_proto!("foo");
}
+17
View File
@@ -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
View File
@@ -0,0 +1,3 @@
fn main() {
tonic_build::compile_protos("proto/wellknown.proto").unwrap();
}
+3
View File
@@ -0,0 +1,3 @@
pub mod pb {
tonic::include_proto!("wellknown");
}
+4 -4
View File
@@ -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);
@@ -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);
@@ -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);
@@ -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);
-12
View File
@@ -1,12 +0,0 @@
#[test]
fn wellknown() {
let tmp = std::env::temp_dir();
tonic_build::configure()
.out_dir(tmp)
.format(false)
.type_attribute(".", "#[derive(Serialize, Deserialize)]")
.type_attribute(".", "#[serde(rename_all = \"camelCase\")]")
.field_attribute("in", "#[serde(rename = \"in\")]")
.compile(&["tests/protos/wellknown.proto"], &["tests/protos"])
.unwrap();
}