Skip to content

Commit b978698

Browse files
committed
add gRPC callout support
Signed-off-by: Rei Shimizu <[email protected]>
1 parent a30f30c commit b978698

File tree

13 files changed

+771
-0
lines changed

13 files changed

+771
-0
lines changed

.github/workflows/rust.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ jobs:
8888

8989
- name: Update Rust
9090
run: |
91+
sudo apt install -y protobuf-compiler
9192
rustup toolchain install stable --component clippy --component rustfmt
9293
rustup target add wasm32-unknown-unknown
9394
rustup target add wasm32-wasi
@@ -142,6 +143,7 @@ jobs:
142143

143144
- name: Update Rust
144145
run: |
146+
sudo apt install -y protobuf-compiler
145147
rustup toolchain install nightly --component clippy --component rustfmt
146148
rustup +nightly target add wasm32-unknown-unknown
147149
rustup +nightly target add wasm32-wasi

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ wee_alloc = { version = "0.4", optional = true }
1919
[dev-dependencies]
2020
cfg-if = "1.0"
2121
chrono = "0.4"
22+
protobuf = "2"
23+
24+
[build-dependencies]
25+
protoc-rust = "2.0"
2226

2327
[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dev-dependencies]
2428
getrandom = "0.2"
@@ -57,3 +61,8 @@ crate-type = ["cdylib"]
5761
name = "http_config"
5862
path = "examples/http_config.rs"
5963
crate-type = ["cdylib"]
64+
65+
[[example]]
66+
name = "grpc_call"
67+
path = "examples/grpc_call/main.rs"
68+
crate-type = ["cdylib"]

bazel/cargo/BUILD.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ alias(
5757
],
5858
)
5959

60+
alias(
61+
name = "protobuf",
62+
actual = "@raze__protobuf__2_22_1//:protobuf",
63+
tags = [
64+
"cargo-raze",
65+
"manual",
66+
],
67+
)
68+
6069
# Export file for Stardoc support
6170
exports_files(
6271
[

bazel/cargo/crates.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ def raze_fetch_remote_crates():
121121
build_file = Label("//bazel/cargo/remote:BUILD.once_cell-1.7.2.bazel"),
122122
)
123123

124+
maybe(
125+
http_archive,
126+
name = "raze__protobuf__2_22_1",
127+
url = "https://crates.io/api/v1/crates/protobuf/2.22.1/download",
128+
type = "tar.gz",
129+
strip_prefix = "protobuf-2.22.1",
130+
build_file = Label("//bazel/cargo/remote:BUILD.protobuf-2.22.1.bazel"),
131+
)
132+
124133
maybe(
125134
http_archive,
126135
name = "raze__time__0_1_43",
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"""
2+
@generated
3+
cargo-raze crate build file.
4+
5+
DO NOT EDIT! Replaced on runs of cargo-raze
6+
"""
7+
8+
# buildifier: disable=load
9+
load("@bazel_skylib//lib:selects.bzl", "selects")
10+
11+
# buildifier: disable=load
12+
load(
13+
"@rules_rust//rust:rust.bzl",
14+
"rust_binary",
15+
"rust_library",
16+
"rust_test",
17+
)
18+
19+
package(default_visibility = [
20+
# Public for visibility by "@raze__crate__version//" targets.
21+
#
22+
# Prefer access through "//bazel/cargo", which limits external
23+
# visibility to explicit Cargo.toml dependencies.
24+
"//visibility:public",
25+
])
26+
27+
licenses([
28+
"notice", # MIT from expression "MIT"
29+
])
30+
31+
# Generated Targets
32+
# buildifier: disable=out-of-order-load
33+
# buildifier: disable=load-on-top
34+
load(
35+
"@rules_rust//cargo:cargo_build_script.bzl",
36+
"cargo_build_script",
37+
)
38+
39+
cargo_build_script(
40+
name = "protobuf_build_script",
41+
srcs = glob(["**/*.rs"]),
42+
build_script_env = {
43+
},
44+
crate_features = [
45+
],
46+
crate_root = "build.rs",
47+
data = glob(["**"]),
48+
edition = "2018",
49+
rustc_flags = [
50+
"--cap-lints=allow",
51+
],
52+
tags = [
53+
"cargo-raze",
54+
"manual",
55+
],
56+
version = "2.22.1",
57+
visibility = ["//visibility:private"],
58+
deps = [
59+
],
60+
)
61+
62+
# Unsupported target "coded_input_stream" with type "bench" omitted
63+
64+
# Unsupported target "coded_output_stream" with type "bench" omitted
65+
66+
rust_library(
67+
name = "protobuf",
68+
srcs = glob(["**/*.rs"]),
69+
crate_features = [
70+
],
71+
crate_root = "src/lib.rs",
72+
crate_type = "lib",
73+
data = [],
74+
edition = "2018",
75+
rustc_flags = [
76+
"--cap-lints=allow",
77+
],
78+
tags = [
79+
"cargo-raze",
80+
"manual",
81+
],
82+
version = "2.22.1",
83+
# buildifier: leave-alone
84+
deps = [
85+
":protobuf_build_script",
86+
],
87+
)

build.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
fn main() {
16+
let proto_files = vec!["examples/grpc_call/helloworld.proto"];
17+
18+
protoc_rust::Codegen::new()
19+
.out_dir("examples/grpc_call")
20+
.inputs(proto_files)
21+
.run()
22+
.expect("running protoc failed");
23+
}

examples/grpc_call/helloworld.proto

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2015 gRPC authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
17+
option go_package = "google.golang.org/grpc/examples/helloworld/helloworld";
18+
option java_multiple_files = true;
19+
option java_package = "io.grpc.examples.helloworld";
20+
option java_outer_classname = "HelloWorldProto";
21+
22+
package helloworld;
23+
24+
// The greeting service definition.
25+
service Greeter {
26+
// Sends a greeting
27+
rpc SayHello (HelloRequest) returns (HelloReply) {}
28+
}
29+
30+
// The request message containing the user's name.
31+
message HelloRequest {
32+
string name = 1;
33+
}
34+
35+
// The response message containing the greetings
36+
message HelloReply {
37+
string message = 1;
38+
}

0 commit comments

Comments
 (0)