Skip to content

Commit 105b903

Browse files
committed
feat: implement gRPC client support to allow outbound gRPC calls
Signed-off-by: Aditya <[email protected]>
1 parent 10b78e5 commit 105b903

File tree

32 files changed

+3384
-58
lines changed

32 files changed

+3384
-58
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ tests/output
55
# Keep Wasm files for testing
66
!tests/fixtures/*.wasm
77
!crates/wasmcloud/tests/fixtures/*.wasm
8+
!crates/wash-runtime/tests/fixtures/*.wasm
89

910
# Ignore IDE specific files
1011
.vscode

Cargo.lock

Lines changed: 15 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ uuid = { workspace = true }
5959
wasm-metadata = { workspace = true }
6060
wasm-pkg-client = { workspace = true }
6161
wasm-pkg-core = { workspace = true }
62-
wash-runtime = { workspace = true, features = ["washlet", "oci", "wasi-config", "wasi-logging"] }
62+
wash-runtime = { workspace = true, features = ["washlet", "oci", "wasi-config", "wasi-logging", "grpc"] }
6363
wasmtime = { workspace = true }
6464
wasmtime-wasi = { workspace = true }
6565
which = { workspace = true }

crates/wash-runtime/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ path = "src/lib.rs"
1313

1414
[features]
1515
default = ["wasi-config", "wasi-logging", "wasi-blobstore", "wasi-keyvalue", "washlet"]
16+
grpc = ["dep:once_cell"]
1617
oci = ["dep:oci-client", "dep:oci-wasm", "dep:docker_credential", "dep:sha2", "dep:wit-component"]
1718
washlet = ["oci"]
1819
wasi-config = []
@@ -73,6 +74,11 @@ oci-client = { workspace = true, optional = true, features = ["rustls-tls", "rus
7374
oci-wasm = { workspace = true, optional = true, features = ["rustls-tls"] }
7475
sha2 = { workspace = true, optional = true }
7576
wit-component = { workspace = true, optional = true }
77+
hyper-util = { version = "0.1.18", features = ["client-legacy", "http1", "http2", "tokio"] }
78+
http-body-util = "0.1.3"
79+
once_cell = { version = "1.19.0", optional = true }
80+
tower-service = "0.3.3"
81+
webpki-roots = "0.26"
7682

7783
[build-dependencies]
7884
anyhow = { workspace = true, default-features = true }

crates/wash-runtime/build.rs

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::env;
2-
use std::fs::{self};
2+
use std::fs;
33
use std::path::PathBuf;
44

55
fn workspace_dir() -> anyhow::Result<PathBuf> {
@@ -28,27 +28,45 @@ fn main() {
2828
let top_proto_dir = workspace_dir.join("proto");
2929
let proto_dir = top_proto_dir.join("wasmcloud/runtime/v2");
3030

31-
let proto_dir_files = fs::read_dir(proto_dir).expect("failed to list files in `proto_dir`");
32-
let proto_files: Vec<PathBuf> = proto_dir_files
33-
.into_iter()
34-
.map(|file| file.unwrap().path())
35-
.collect();
36-
37-
let descriptor_file = out_dir.join("runtime.bin");
38-
39-
tonic_prost_build::configure()
40-
.compile_well_known_types(true)
41-
.file_descriptor_set_path(&descriptor_file)
42-
.extern_path(".google.protobuf", "::pbjson_types")
43-
.compile_protos(&proto_files, &[top_proto_dir])
44-
.expect("failed to compile protos");
45-
46-
// Generate serde bindings for the Runtime API
47-
let descriptor_bytes = std::fs::read(descriptor_file).expect("failed to read descriptor file");
48-
49-
pbjson_build::Builder::new()
50-
.register_descriptors(&descriptor_bytes)
51-
.expect("failed to register descriptor")
52-
.build(&[".wasmcloud.runtime.v2"])
53-
.expect("failed to build final protos");
31+
// Compile Runtime API protos if directory exists
32+
if proto_dir.exists() {
33+
let proto_dir_files =
34+
fs::read_dir(&proto_dir).expect("failed to list files in `proto_dir`");
35+
let proto_files: Vec<PathBuf> = proto_dir_files
36+
.into_iter()
37+
.map(|file| file.expect("failed to read proto file").path())
38+
.collect();
39+
40+
let descriptor_file = out_dir.join("runtime.bin");
41+
42+
tonic_prost_build::configure()
43+
.compile_well_known_types(true)
44+
.file_descriptor_set_path(&descriptor_file)
45+
.extern_path(".google.protobuf", "::pbjson_types")
46+
.compile_protos(&proto_files, &[top_proto_dir])
47+
.expect("failed to compile Runtime API protos");
48+
49+
// Generate serde bindings for the Runtime API
50+
let descriptor_bytes =
51+
std::fs::read(&descriptor_file).expect("failed to read descriptor file");
52+
53+
pbjson_build::Builder::new()
54+
.register_descriptors(&descriptor_bytes)
55+
.expect("failed to register descriptor")
56+
.build(&[".wasmcloud.runtime.v2"])
57+
.expect("failed to build Runtime API protos");
58+
}
59+
60+
// Compile test proto files if they exist
61+
let test_proto_file = workspace_dir.join("tests/proto/helloworld.proto");
62+
if test_proto_file.exists() {
63+
println!("cargo:rerun-if-changed={}", test_proto_file.display());
64+
65+
tonic_prost_build::configure()
66+
.build_client(false)
67+
.build_server(true)
68+
.build_transport(true)
69+
.compile_protos(&[&test_proto_file], &[&workspace_dir.join("tests/proto")])
70+
.expect("failed to compile test protos");
71+
}
5472
}

0 commit comments

Comments
 (0)