Skip to content
This repository has been archived by the owner on Apr 16, 2020. It is now read-only.

Wrong use path when using well known proto type #209

Open
UkonnRa opened this issue Sep 27, 2019 · 2 comments
Open

Wrong use path when using well known proto type #209

UkonnRa opened this issue Sep 27, 2019 · 2 comments

Comments

@UkonnRa
Copy link

UkonnRa commented Sep 27, 2019

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>,
    }
...
@LucioFranco
Copy link
Member

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

@UkonnRa
Copy link
Author

UkonnRa commented Sep 30, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants