tower-grpc icon indicating copy to clipboard operation
tower-grpc copied to clipboard

Wrong `use` path when using `well known proto type`

Open UkonnRa opened this issue 6 years ago • 2 comments

tower-grpc-build may generate wrong use path when using well known proto types, say google/protobuf/timestamp.proto.

Cargo dependencies:

[dependencies]
tower-grpc          = {version = "~0.1", features = ["tower-hyper"] }
tower-hyper         = "~0.1"
prost               = "~0.5"
prost-types         = "~0.5"
prost-derive        = "~0.5"
futures             = "~0.1"
bytes               = "~0.4"

[build-dependencies]
tower-grpc-build    = { version = "~0.1", features = ["tower-hyper"] }
/// build.rs
extern crate tower_grpc_build;

fn main() {
    println!("Starting build");

    // prefer writing the compiled proto code to src folder
    std::env::set_var("OUT_DIR", "src/");

    tower_grpc_build::Config::new()
        .enable_server(true)
        .enable_client(true)
        .build(&["proto/test.proto"], &["proto"])
        .unwrap_or_else(|e| panic!("protobuf compilation failed: {}", e));
    println!("cargo:rerun-if-changed=proto/test.proto");
}
syntax = "proto3";

package test;
option optimize_for = SPEED;

import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";

service Service {
    rpc GetTime(google.protobuf.Empty) returns (google.protobuf.Timestamp) {}
}

And the generated rust file is:

pub mod client {
    use ::tower_grpc::codegen::client::*;
    use super::::prost_types::Timestamp; // Error line! Which should be `use ::prost_types::Timestamp;`

    #[derive(Debug, Clone)]
    pub struct Service<T> {
        inner: grpc::Grpc<T>,
    }
...

UkonnRa avatar Sep 27 '19 02:09 UkonnRa

Sounds like we may want to detect the issue here? https://github.com/tower-rs/tower-grpc/blob/master/tower-grpc-build/src/client.rs#L28

LucioFranco avatar Sep 29 '19 14:09 LucioFranco

Well, sorry I have not read the source code yet, so I have no idea what's going wrong...

UkonnRa avatar Sep 30 '19 05:09 UkonnRa