build: generate root crate paths correctly (#623)

We shouldn't append `proto_path` (`super` by default) if the path starts
with `crate::`.

Fixes https://github.com/hyperium/tonic/issues/548
This commit is contained in:
David Pedersen
2021-06-02 16:58:43 +02:00
committed by GitHub
parent 0fa391eca4
commit e82f0b0399
6 changed files with 65 additions and 4 deletions
+14
View File
@@ -0,0 +1,14 @@
[package]
name = "root-crate-path"
version = "0.1.0"
authors = ["Lucio Franco <[email protected]>"]
edition = "2018"
publish = false
license = "MIT"
[dependencies]
tonic = { path = "../../tonic" }
prost = "0.7"
[build_dependencies]
tonic-build = { path = "../../tonic-build" }
+7
View File
@@ -0,0 +1,7 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::configure()
.extern_path(".foo.bar.baz.Animal", "crate::Animal")
.compile(&["foo.proto"], &["."])?;
Ok(())
}
+10
View File
@@ -0,0 +1,10 @@
syntax = "proto2";
package foo.bar.baz;
message Animal {
optional string name = 1;
}
service Zoo {
rpc process_animal(Animal) returns (Animal) {};
}
+19
View File
@@ -0,0 +1,19 @@
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Animal {
#[prost(string, optional, tag = "1")]
pub name: ::core::option::Option<::prost::alloc::string::String>,
}
// pub mod foo;
pub mod foo {
pub mod bar {
pub mod baz {
tonic::include_proto!("foo.bar.baz");
}
}
}
fn main() {
println!("Hello, world!");
}