-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
464 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("//rust:rules.bzl", "rust_proto_library") | ||
|
||
rust_proto_library( | ||
name = "helloworld", | ||
proto_deps = [ | ||
"//examples/proto:rust", | ||
], | ||
protos = ["//examples/helloworld/proto:protos"], | ||
verbose = 0, | ||
visibility = ["//examples/helloworld/rust:__subpackages__"], | ||
with_grpc = True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary") | ||
load("//rust:rules.bzl", "GRPC_COMPILE_DEPS", "rust_proto_library") | ||
|
||
rust_binary( | ||
name = "greeter_client", | ||
srcs = ["greeter_client.rs"], | ||
deps = ["//examples/helloworld/rust:helloworld"] + GRPC_COMPILE_DEPS, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
extern crate grpc; | ||
extern crate helloworld; | ||
|
||
use std::env; | ||
|
||
use helloworld::*; | ||
|
||
fn main() { | ||
let name = env::args().nth(1).unwrap_or("world".to_owned()); | ||
let client = GreeterClient::new_plain("::1", 50051, Default::default()).unwrap(); | ||
let mut req = HelloRequest::new(); | ||
req.set_name(name); | ||
let resp = client.say_hello(grpc::RequestOptions::new(), req); | ||
println!("{:?}", resp.wait()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary") | ||
load("//rust:rules.bzl", "GRPC_COMPILE_DEPS", "rust_proto_library") | ||
|
||
rust_binary( | ||
name = "greeter_server", | ||
srcs = ["greeter_server.rs"], | ||
deps = ["//examples/helloworld/rust:helloworld"] + GRPC_COMPILE_DEPS, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
extern crate helloworld; | ||
extern crate grpc; | ||
extern crate tls_api_stub; | ||
|
||
use std::thread; | ||
|
||
use helloworld::*; | ||
|
||
struct GreeterImpl; | ||
|
||
impl Greeter for GreeterImpl { | ||
fn say_hello(&self, _m: grpc::RequestOptions, req: HelloRequest) -> grpc::SingleResponse<HelloReply> { | ||
let mut r = HelloReply::new(); | ||
let name = if req.get_name().is_empty() { "world" } else { req.get_name() }; | ||
println!("greeting request from {}", name); | ||
r.set_message(format!("Hello {}", name)); | ||
grpc::SingleResponse::completed(r) | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut server = grpc::ServerBuilder::<tls_api_stub::TlsAcceptor>::new(); | ||
server.http.set_port(50051); | ||
server.add_service(GreeterServer::new_service_def(GreeterImpl)); | ||
server.http.set_cpu_pool_threads(4); | ||
let _server = server.build().expect("server"); | ||
|
||
println!("greeter server started on port 50051"); | ||
|
||
loop { | ||
thread::park(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("//protobuf:rules.bzl", "proto_language") | ||
|
||
proto_language( | ||
name = "rust", | ||
grpc_file_extensions = ["_grpc.rs"], | ||
grpc_plugin = "@com_github_stepancheg_grpc_rust//:protoc_gen_rust_grpc", | ||
output_to_libsubdir = True, | ||
pb_file_extensions = [".rs"], | ||
pb_plugin = "@com_github_stepancheg_rust_protobuf//:protoc_gen_rust", | ||
pb_plugin_implements_grpc = False, | ||
supports_grpc = True, | ||
) |
Oops, something went wrong.