Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helloworld tutorial is outdated? #765

Closed
zhiburt opened this issue Sep 15, 2021 · 15 comments
Closed

Helloworld tutorial is outdated? #765

zhiburt opened this issue Sep 15, 2021 · 15 comments
Labels
C-question Category: Further information is requested

Comments

@zhiburt
Copy link

zhiburt commented Sep 15, 2021

https://github.com/hyperium/tonic/blob/master/examples/helloworld-tutorial.md

Following the reference I was getting

error: environment variable `OUT_DIR` not defined
 --> src/server.rs:9:5
  |
9 |     tonic::include_proto!("helloworld");
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Then I took a look at build.rs used in examples dir and in a bit different.

And to fix it it was necessary to change a build.rs and Cargo.toml.

    let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
    tonic_build::configure()
        .file_descriptor_set_path(out_dir.join("helloworld_descriptor.bin"))
        .compile(&["proto/helloworld/helloworld.proto"], &["proto"])
        .unwrap();
# include `prost`
[dependencies]
prost = "*"

# include `prost`
[build-dependencies]
tonic-build = { path = "../tonic-build", features = ["prost"] }
@CommoDor64
Copy link

Rust build scripts are being expected to be in the root folder, i.e a sibling folder to src. Cargo then will set OUT_DIR for the compiler to use. So if you insist to move the build script somewhere else, you'll have to set it manually. But if you are willing to put it there, it still works, so the tutorial is correct.

@zhiburt
Copy link
Author

zhiburt commented Sep 17, 2021

Rust build scripts are being expected to be in the root folder, i.e a sibling folder to src. Cargo then will set OUT_DIR for the compiler to use.

That's right but as I remember there will be an erorr because of prost dependency.

I mean that In the tutorial there's snippets like these.

    // don't remember func name
    tonic_build::.compile_prots("proto/helloworld.proto").unwrap();
# include `prost`
[dependencies]

# include `prost`
[build-dependencies]
tonic-build = { path = "../tonic-build", features = [] }

And I was getting errors unless I changed them to the following (Which I found in your examples folder)

    let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
    tonic_build::configure()
        .file_descriptor_set_path(out_dir.join("helloworld_descriptor.bin"))
        .compile(&["proto/helloworld.proto"], &["proto"])
        .unwrap();
# include `prost`
[dependencies]
prost = "*"

# include `prost`
[build-dependencies]
tonic-build = { path = "../tonic-build", features = ["prost"] }

@zhiburt
Copy link
Author

zhiburt commented Sep 17, 2021

To be precise here it is

When you keep things as described in tutorial

https://github.com/hyperium/tonic/blame/master/examples/helloworld-tutorial.md#L101-L122

https://github.com/hyperium/tonic/blame/master/examples/helloworld-tutorial.md#L130-L134

error[E0433]: failed to resolve: could not find `prost` in the list of imported crates
 --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:8:30
  |
8 | #[derive(Clone, PartialEq, ::prost::Message)]
  |                              ^^^^^ could not find `prost` in the list of imported crates

error[E0433]: failed to resolve: could not find `prost` in the list of imported crates
 --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:2:30
  |
2 | #[derive(Clone, PartialEq, ::prost::Message)]
  |                              ^^^^^ could not find `prost` in the list of imported crates

error: cannot find attribute `prost` in this scope
 --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:4:7
  |
4 |     #[prost(string, tag = "1")]
  |       ^^^^^

error: cannot find attribute `prost` in this scope
  --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:10:7
   |
10 |     #[prost(string, tag = "1")]
   |       ^^^^^

error[E0433]: failed to resolve: could not find `prost` in the list of imported crates
 --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:5:17
  |
5 |     pub name: ::prost::alloc::string::String,
  |                 ^^^^^ could not find `prost` in the list of imported crates

error[E0433]: failed to resolve: could not find `prost` in the list of imported crates
  --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:11:20
   |
11 |     pub message: ::prost::alloc::string::String,
   |                    ^^^^^ could not find `prost` in the list of imported crates

error[E0277]: the trait bound `HelloRequest: prost::message::Message` is not satisfied
  --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:87:24
   |
87 |             self.inner.unary(request.into_request(), path, codec).await
   |                        ^^^^^ the trait `prost::message::Message` is not implemented for `HelloRequest`
   |
   = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloRequest, _>`

error[E0277]: the trait bound `HelloReply: prost::message::Message` is not satisfied
  --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:87:24
   |
87 |             self.inner.unary(request.into_request(), path, codec).await
   |                        ^^^^^ the trait `prost::message::Message` is not implemented for `HelloReply`
   |
   = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloRequest, HelloReply>`

error[E0277]: the trait bound `HelloReply: Default` is not satisfied
  --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:87:24
   |
87 |             self.inner.unary(request.into_request(), path, codec).await
   |                        ^^^^^ the trait `Default` is not implemented for `HelloReply`
   |
   = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloRequest, HelloReply>`

error[E0277]: the trait bound `HelloReply: prost::message::Message` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:170:40
    |
170 |                         let res = grpc.unary(method, req).await;
    |                                        ^^^^^ the trait `prost::message::Message` is not implemented for `HelloReply`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error[E0277]: the trait bound `HelloRequest: prost::message::Message` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:170:40
    |
170 |                         let res = grpc.unary(method, req).await;
    |                                        ^^^^^ the trait `prost::message::Message` is not implemented for `HelloRequest`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error[E0277]: the trait bound `HelloRequest: Default` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:170:40
    |
170 |                         let res = grpc.unary(method, req).await;
    |                                        ^^^^^ the trait `Default` is not implemented for `HelloRequest`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error[E0277]: the trait bound `HelloReply: prost::message::Message` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:166:72
    |
166 |                         let mut grpc = tonic::server::Grpc::new(codec).apply_compression_config(
    |                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `prost::message::Message` is not implemented for `HelloReply`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error[E0277]: the trait bound `HelloRequest: prost::message::Message` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:166:72
    |
166 |                         let mut grpc = tonic::server::Grpc::new(codec).apply_compression_config(
    |                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `prost::message::Message` is not implemented for `HelloRequest`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error[E0277]: the trait bound `HelloRequest: Default` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:166:72
    |
166 |                         let mut grpc = tonic::server::Grpc::new(codec).apply_compression_config(
    |                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `HelloRequest`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error[E0277]: the trait bound `HelloReply: prost::message::Message` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:166:40
    |
166 |                         let mut grpc = tonic::server::Grpc::new(codec).apply_compression_config(
    |                                        ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `prost::message::Message` is not implemented for `HelloReply`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error[E0277]: the trait bound `HelloRequest: prost::message::Message` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:166:40
    |
166 |                         let mut grpc = tonic::server::Grpc::new(codec).apply_compression_config(
    |                                        ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `prost::message::Message` is not implemented for `HelloRequest`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error[E0277]: the trait bound `HelloRequest: Default` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:166:40
    |
166 |                         let mut grpc = tonic::server::Grpc::new(codec).apply_compression_config(
    |                                        ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `HelloRequest`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error: aborting due to 18 previous errors

Some errors have detailed explanations: E0277, E0433.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `examples`

To learn more, run the command again with --verbose.

@LucioFranco
Copy link
Member

I don't really see what is missing in the tutorial, but I would accept a PR with suggestions you might have.

@LucioFranco LucioFranco added the C-question Category: Further information is requested label Oct 13, 2021
@small-lei
Copy link

To be precise here it is

When you keep things as described in tutorial

https://github.com/hyperium/tonic/blame/master/examples/helloworld-tutorial.md#L101-L122

https://github.com/hyperium/tonic/blame/master/examples/helloworld-tutorial.md#L130-L134

error[E0433]: failed to resolve: could not find `prost` in the list of imported crates
 --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:8:30
  |
8 | #[derive(Clone, PartialEq, ::prost::Message)]
  |                              ^^^^^ could not find `prost` in the list of imported crates

error[E0433]: failed to resolve: could not find `prost` in the list of imported crates
 --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:2:30
  |
2 | #[derive(Clone, PartialEq, ::prost::Message)]
  |                              ^^^^^ could not find `prost` in the list of imported crates

error: cannot find attribute `prost` in this scope
 --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:4:7
  |
4 |     #[prost(string, tag = "1")]
  |       ^^^^^

error: cannot find attribute `prost` in this scope
  --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:10:7
   |
10 |     #[prost(string, tag = "1")]
   |       ^^^^^

error[E0433]: failed to resolve: could not find `prost` in the list of imported crates
 --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:5:17
  |
5 |     pub name: ::prost::alloc::string::String,
  |                 ^^^^^ could not find `prost` in the list of imported crates

error[E0433]: failed to resolve: could not find `prost` in the list of imported crates
  --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:11:20
   |
11 |     pub message: ::prost::alloc::string::String,
   |                    ^^^^^ could not find `prost` in the list of imported crates

error[E0277]: the trait bound `HelloRequest: prost::message::Message` is not satisfied
  --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:87:24
   |
87 |             self.inner.unary(request.into_request(), path, codec).await
   |                        ^^^^^ the trait `prost::message::Message` is not implemented for `HelloRequest`
   |
   = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloRequest, _>`

error[E0277]: the trait bound `HelloReply: prost::message::Message` is not satisfied
  --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:87:24
   |
87 |             self.inner.unary(request.into_request(), path, codec).await
   |                        ^^^^^ the trait `prost::message::Message` is not implemented for `HelloReply`
   |
   = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloRequest, HelloReply>`

error[E0277]: the trait bound `HelloReply: Default` is not satisfied
  --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:87:24
   |
87 |             self.inner.unary(request.into_request(), path, codec).await
   |                        ^^^^^ the trait `Default` is not implemented for `HelloReply`
   |
   = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloRequest, HelloReply>`

error[E0277]: the trait bound `HelloReply: prost::message::Message` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:170:40
    |
170 |                         let res = grpc.unary(method, req).await;
    |                                        ^^^^^ the trait `prost::message::Message` is not implemented for `HelloReply`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error[E0277]: the trait bound `HelloRequest: prost::message::Message` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:170:40
    |
170 |                         let res = grpc.unary(method, req).await;
    |                                        ^^^^^ the trait `prost::message::Message` is not implemented for `HelloRequest`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error[E0277]: the trait bound `HelloRequest: Default` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:170:40
    |
170 |                         let res = grpc.unary(method, req).await;
    |                                        ^^^^^ the trait `Default` is not implemented for `HelloRequest`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error[E0277]: the trait bound `HelloReply: prost::message::Message` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:166:72
    |
166 |                         let mut grpc = tonic::server::Grpc::new(codec).apply_compression_config(
    |                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `prost::message::Message` is not implemented for `HelloReply`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error[E0277]: the trait bound `HelloRequest: prost::message::Message` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:166:72
    |
166 |                         let mut grpc = tonic::server::Grpc::new(codec).apply_compression_config(
    |                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `prost::message::Message` is not implemented for `HelloRequest`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error[E0277]: the trait bound `HelloRequest: Default` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:166:72
    |
166 |                         let mut grpc = tonic::server::Grpc::new(codec).apply_compression_config(
    |                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `HelloRequest`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error[E0277]: the trait bound `HelloReply: prost::message::Message` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:166:40
    |
166 |                         let mut grpc = tonic::server::Grpc::new(codec).apply_compression_config(
    |                                        ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `prost::message::Message` is not implemented for `HelloReply`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error[E0277]: the trait bound `HelloRequest: prost::message::Message` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:166:40
    |
166 |                         let mut grpc = tonic::server::Grpc::new(codec).apply_compression_config(
    |                                        ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `prost::message::Message` is not implemented for `HelloRequest`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error[E0277]: the trait bound `HelloRequest: Default` is not satisfied
   --> /home/mzhiburt/projects/tonic/target/debug/build/examples-020cf5705affc3b4/out/helloworld.rs:166:40
    |
166 |                         let mut grpc = tonic::server::Grpc::new(codec).apply_compression_config(
    |                                        ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `HelloRequest`
    |
    = note: required because of the requirements on the impl of `Codec` for `ProstCodec<HelloReply, HelloRequest>`

error: aborting due to 18 previous errors

Some errors have detailed explanations: E0277, E0433.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `examples`

To learn more, run the command again with --verbose.

I have the same problem, I solve it , add prost = "0.8" to cargo.toml

@zhiburt
Copy link
Author

zhiburt commented Oct 19, 2021

I don't really see what is missing in the tutorial,

That's what I meant (I guess), that probably it makes sense to note or make it more clear that as @small-lei mentioned

I have the same problem, I solve it , add prost = "0.8" to cargo.toml

prost dependency is required.

@davidpdrsn
Copy link
Member

The prost thing is known #791 👀

@LucioFranco
Copy link
Member

Yeah this should be fixed on master right now and in the next release.

@chokosabe
Copy link

Getting the same issue; following the helloworld tutorial example to the letter.

@LucioFranco
Copy link
Member

@chokosabe can you post your cargo.toml file? The versions in the tutorial look fine to me.

@frederikhors
Copy link

Same issue here after the routeguide tutorial. And I added the prost dep but the error is still there.

@Narayanbhat166
Copy link

Narayanbhat166 commented Sep 2, 2023

Faced the same problem in helloworld turorial, Changed the prost and tonic_build versions and the project compiles

[package]
name = "helloworld-tonic"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[[bin]] # Bin to run the HelloWorld gRPC server
name = "helloworld-server"
path = "src/server.rs"

[[bin]] # Bin to run the HelloWorld gRPC client
name = "helloworld-client"
path = "src/client.rs"

[dependencies]
tonic = "0.7"
prost = "0.10"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }

[build-dependencies]
tonic-build = "0.7"

@vishnu-kumar
Copy link

I solved it as follows:
Looked at Cargo.lock and it was having multiple version of prost dependency like
[[package]]
name = "prost"
version = "0.11.9"

[[package]]
name = "prost"
version = "0.8.0"

So seems like they are conflicting and right version is not getting picked. So I changed the dependencies of prost version to prost = "0.11.9" and it build successfully.

@HMasataka
Copy link

I did confirm the tutorial works with the latest version by to configure Cargo.toml as follows:

[package]
name = "helloworld-tonic"
version = "0.1.0"
edition = "2021"

[[bin]] # Bin to run the HelloWorld gRPC server
name = "helloworld-server"
path = "src/server.rs"

[[bin]] # Bin to run the HelloWorld gRPC client
name = "helloworld-client"
path = "src/client.rs"

[dependencies]
tonic = "0.12"
prost = "0.13"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }

[build-dependencies]
tonic-build = "0.12"

@HMasataka
Copy link

@LucioFranco @zhiburt
Looks like lukem570 fixed it.
Can you close this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-question Category: Further information is requested
Projects
None yet
Development

No branches or pull requests

10 participants