containerd / ttrpc-rust

Rust implementation of ttrpc (GRPC for low-memory environments)
Apache License 2.0
195 stars 45 forks source link

Fix examples #8

Closed Tim-Zhang closed 4 years ago

Tim-Zhang commented 4 years ago

Got: cargo run --example server unix:///tmp/1 error[E0425]: cannot find value VERSION_2_8_0 in crate protobuf

The above error is caused by protobuf version checking mechanism in the generated codes in examples.

For more information:

This PR remove generated files in example and add instructions to README to fix the above error and explain how to avoid the error.

teawater commented 4 years ago

I would like we keep these files until this file can be auto generated with build. Do you mind to take a look on build.rs that can do it.

Tim-Zhang commented 4 years ago

@teawater I have tried to generate *.rs file from .proto automatically by build.rs today, it works but I think it is not a good idea because build.rs will run with cargo build, but 'cargo build' is not supposed to generate codes in examples, maybe it's not an action which Rustaceans will do.

teawater commented 4 years ago

@teawater I have tried to generate *.rs file from .proto automatically by build.rs today, it works but I think it is not a good idea because build.rs will run with cargo build, but 'cargo build' is not supposed to generate codes in examples, maybe it's not an action which Rustaceans will do.

@Tim-Zhang Cool! I really like build.rs example. That is a really important example for user. Please keep it. If it cannot be a part of normal example, maybe we can change example to a special directory name or something. What do you think about it? @lifupan

Tim-Zhang commented 4 years ago

@teawater @lifupan I have pushed the commit. In this commit I have renamed examples to example to make it a standalone cargo project, and I have created a file example/build.rs which will generate example/protocols/*.rs when users run cargo run --example server/client in the folder example the first time.

teawater commented 4 years ago
teawater@teawater-HP-ProDesk-680-G1-TWR:~/ttrpc-rust/example$ rm -rf protocols/*_ttrpc.rs
teawater@teawater-HP-ProDesk-680-G1-TWR:~/ttrpc-rust/example$ cargo build --examples
error[E0583]: file not found for module `agent_ttrpc`
 --> protocols/mod.rs:2:9
  |
2 | pub mod agent_ttrpc;
  |         ^^^^^^^^^^^
  |
  = help: name the file either agent_ttrpc.rs or agent_ttrpc/mod.rs inside the directory "protocols"

error: aborting due to previous error

For more information about this error, try `rustc --explain E0583`.
error[E0583]: file not found for module `agent_ttrpc`
 --> protocols/mod.rs:2:9
  |
2 | pub mod agent_ttrpc;
  |         ^^^^^^^^^^^
  |
  = help: name the file either agent_ttrpc.rs or agent_ttrpc/mod.rs inside the directory "protocols"

error: aborting due to previous error

For more information about this error, try `rustc --explain E0583`.
error: could not compile `ttrpc-example`.
warning: build failed, waiting for other jobs to finish...
error: could not compile `ttrpc-example`.

To learn more, run the command again with --verbose.
teawater@teawater-HP-ProDesk-680-G1-TWR:~/ttrpc-rust/example$ cd protocols/
teawater@teawater-HP-ProDesk-680-G1-TWR:~/ttrpc-rust/example/protocols$ hack/update-generated-proto.sh
/usr/local/bin/protoc
/home/teawater/.cargo/bin/protoc-gen-rust
/home/teawater/gopath//bin//ttrpc_rust_plugin
protoc --rust_out=./ --ttrpc_out=./,plugins=ttrpc:./ --plugin=protoc-gen-ttrpc=/home/teawater/gopath//bin//ttrpc_rust_plugin -I ./protos/ ./protos/agent.proto
protoc --rust_out=./ --ttrpc_out=./,plugins=ttrpc:./ --plugin=protoc-gen-ttrpc=/home/teawater/gopath//bin//ttrpc_rust_plugin -I ./protos/ ./protos/health.proto
protoc --rust_out=./ --ttrpc_out=./,plugins=ttrpc:./ --plugin=protoc-gen-ttrpc=/home/teawater/gopath//bin//ttrpc_rust_plugin -I ./protos/ ./protos/github.com/kata-containers/agent/pkg/types/types.proto
protoc --rust_out=./ --ttrpc_out=./,plugins=ttrpc:./ --plugin=protoc-gen-ttrpc=/home/teawater/gopath//bin//ttrpc_rust_plugin -I ./protos/ ./protos/google/protobuf/empty.proto
protoc --rust_out=./ --ttrpc_out=./,plugins=ttrpc:./ --plugin=protoc-gen-ttrpc=/home/teawater/gopath//bin//ttrpc_rust_plugin -I ./protos/ ./protos/oci.proto
oci.proto:12:1: warning: Import google/protobuf/wrappers.proto but not used.
teawater@teawater-HP-ProDesk-680-G1-TWR:~/ttrpc-rust/example/protocols$ cd ..
teawater@teawater-HP-ProDesk-680-G1-TWR:~/ttrpc-rust/example$ cargo build --examples
Finished dev [unoptimized + debuginfo] target(s) in 3.16s

Why "cargo build --examples" cannot generate "protocols/*_ttrpc.rs" but "hack/update-generated-proto.sh" can generate them?

Tim-Zhang commented 4 years ago

@teawater I just updated the pull request: remove *_ttrpc.rs and call ./hack/update-generated-proto.sh to generate codes.