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

Fix examples #8

Merged
merged 3 commits into from Jan 13, 2020
Merged

Fix examples #8

merged 3 commits into from Jan 13, 2020

Conversation

Tim-Zhang
Copy link
Member

@Tim-Zhang Tim-Zhang commented Jan 2, 2020

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.

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

This commit makes it necessary for users to generate codes themeselves
before running examples to avoid above errors.

Signed-off-by: Tim Zhang <tim@hyper.sh>
Add instructions of how to run examples and notes about protobuf version.

Signed-off-by: Tim Zhang <tim@hyper.sh>
@teawater
Copy link
Collaborator

teawater commented Jan 4, 2020

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.

@teawater teawater mentioned this pull request Jan 5, 2020
@Tim-Zhang
Copy link
Member Author

@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
Copy link
Collaborator

teawater commented Jan 8, 2020

@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
Copy link
Member Author

@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.

.gitignore Outdated
example/protocols/empty.rs
example/protocols/health.rs
example/protocols/oci.rs
example/protocols/types.rs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xxx_ttrpc.rs should add to this file?

Copy link
Member Author

@Tim-Zhang Tim-Zhang Jan 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think ttrpc supports generate codes programmatically for now, so leave it alone.

@teawater
Copy link
Collaborator

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
Copy link
Member Author

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

Rename examples to example to make it a standalone cargo project so that
we can use build script, independent dependencies, etc. in example.

Signed-off-by: Tim Zhang <tim@hyper.sh>
@teawater teawater merged commit d450ee7 into containerd:master Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants