diff --git a/Cargo.toml b/Cargo.toml index cebf247..0fe450a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,6 @@ members = [ "planetwars-rules", "planetwars-matchrunner", - "planetwars-cli", "planetwars-server", + "planetwars-client", ] diff --git a/planetwars-client/Cargo.toml b/planetwars-client/Cargo.toml new file mode 100644 index 0000000..10de887 --- /dev/null +++ b/planetwars-client/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "planetwars-client" +version = "0.0.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tokio = { version = "1.15", features = ["full"] } +prost = "0.10" +tonic = "0.7.2" + +[build-dependencies] +tonic-build = "0.7.2" diff --git a/planetwars-client/build.rs b/planetwars-client/build.rs new file mode 100644 index 0000000..acabd08 --- /dev/null +++ b/planetwars-client/build.rs @@ -0,0 +1,9 @@ +extern crate tonic_build; + +fn main() -> Result<(), Box> { + tonic_build::configure() + .build_server(false) + .build_client(true) + .compile(&["../proto/bot_api.proto"], &["../proto"])?; + Ok(()) +} diff --git a/planetwars-client/src/main.rs b/planetwars-client/src/main.rs new file mode 100644 index 0000000..9d9bdab --- /dev/null +++ b/planetwars-client/src/main.rs @@ -0,0 +1,21 @@ +pub mod pb { + tonic::include_proto!("grpc.planetwars.bot_api"); +} + +use pb::test_service_client::TestServiceClient; +use pb::{Hello, HelloResponse}; +use tonic::Response; + +#[tokio::main] +async fn main() { + let mut client = TestServiceClient::connect("http://localhost:50051") + .await + .unwrap(); + let response: Response = client + .greet(Hello { + hello_message: "robbe".to_string(), + }) + .await + .unwrap(); + println!("{}", response.get_ref().response); +}