Skip to content

Commit

Permalink
feat(cli): add wasmtime-nats CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
rvolosatovs committed May 8, 2024
1 parent e705fcf commit 2c24bcb
Show file tree
Hide file tree
Showing 78 changed files with 5,014 additions and 88 deletions.
620 changes: 601 additions & 19 deletions Cargo.lock

Large diffs are not rendered by default.

63 changes: 44 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,37 @@ repository = "https://github.com/wrpc/wrpc"
members = ["crates/*", "examples/rust/*"]

[features]
default = ["nats", "wasmtime"]
default = ["bin", "nats", "wasmtime"]

nats = ["dep:async-nats", "dep:wrpc-transport-nats"]
bin = [
"dep:clap",
"dep:serde",
"dep:serde_json",
"dep:tokio",
"dep:url",
"dep:wit-bindgen-core",
"dep:wit-bindgen-wrpc-go",
"dep:wrpc-cli",
"dep:wrpc-wasmtime-nats-cli",
"tokio/rt-multi-thread",
"tokio/sync",
"wit-bindgen-wrpc-go/clap",
"wit-bindgen-wrpc-rust/clap",
]
nats = ["dep:async-nats", "dep:wrpc-transport-nats", "wrpc-cli/nats"]
wasmtime = ["dep:wrpc-runtime-wasmtime"]

[[bin]]
name = "wit-bindgen-wrpc"
required-features = ["bin"]

[[bin]]
name = "wrpc-keyvalue-nats"
required-features = ["nats"]
required-features = ["bin", "nats"]

[[bin]]
name = "wrpc-wasmtime-nats"
required-features = ["bin", "nats", "wasmtime"]

[dependencies]
anyhow = { workspace = true, features = ["std"] }
Expand All @@ -40,29 +63,24 @@ clap = { workspace = true, features = [
"std",
"suggestions",
"usage",
] }
serde = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread", "sync"] }
], optional = true }
serde = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }
tokio = { workspace = true, optional = true }
tracing = { workspace = true, features = ["attributes"] }
tracing-subscriber = { workspace = true, features = [
"ansi",
"env-filter",
"fmt",
"smallvec",
"tracing-log",
] }
url = { workspace = true }
wit-bindgen-core = { workspace = true }
url = { workspace = true, optional = true }
wit-bindgen-core = { workspace = true, optional = true }
wit-bindgen-wrpc = { workspace = true }
wit-bindgen-wrpc-go = { workspace = true, features = ["clap"] }
wit-bindgen-wrpc-rust = { workspace = true, features = ["clap"] }
wit-bindgen-wrpc-go = { workspace = true, optional = true }
wit-bindgen-wrpc-rust = { workspace = true, optional = true }
wrpc-cli = { workspace = true, optional = true }
wrpc-interface-blobstore = { workspace = true }
wrpc-interface-http = { workspace = true }
wrpc-runtime-wasmtime = { workspace = true, optional = true }
wrpc-transport = { workspace = true }
wrpc-transport-nats = { workspace = true, optional = true }
wrpc-types = { workspace = true }
wrpc-wasmtime-nats-cli = { workspace = true, optional = true }

[dev-dependencies]
anyhow = { workspace = true }
Expand All @@ -75,6 +93,7 @@ hyper = { workspace = true, features = ["server"] }
hyper-util = { workspace = true, features = ["server-auto", "tokio"] }
reqwest = { workspace = true }
tokio = { workspace = true, features = ["process"] }
wrpc-cli = { workspace = true }
wrpc-interface-http = { workspace = true, features = [
"http",
"http-body",
Expand Down Expand Up @@ -113,19 +132,25 @@ tower = { version = "0.4", default-features = false }
tracing = { version = "0.1", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false }
url = { version = "2", default-features = false }
wasmcloud-component-adapters = { version = "0.9", default-features = false }
wasmparser = { version = "0.207", default-features = false }
wasmtime = { version = "20", default-features = false }
wasmtime-wasi = { version = "20", default-features = false }
wasmtime-wasi-http = { version = "20", default-features = false }
webpki-roots = { version = "0.26", default-features = false }
wit-bindgen = { version = "0.24", default-features = false }
wit-bindgen-core = { version = "0.24", default-features = false }
wit-bindgen-wrpc = { version = "0.3.6", default-features = false, path = "./crates/wit-bindgen" }
wit-bindgen-wrpc-go = { version = "0.1.0", default-features = false, path = "./crates/wit-bindgen-go" }
wit-bindgen-wrpc-rust = { version = "0.3.3", default-features = false, path = "./crates/wit-bindgen-rust" }
wit-bindgen-wrpc-rust-macro = { version = "0.3.4", default-features = false, path = "./crates/wit-bindgen-rust-macro" }
wit-parser = { version = "0.202", default-features = false }
wit-component = { version = "0.207", default-features = false }
wit-parser = { version = "0.207", default-features = false }
wrpc-cli = { version = "*", path = "./crates/cli", default-features = false }
wrpc-interface-blobstore = { version = "0.16", path = "./crates/interface-blobstore", default-features = false }
wrpc-interface-http = { version = "0.22", path = "./crates/interface-http", default-features = false }
wrpc-runtime-wasmtime = { version = "0.16", path = "./crates/runtime-wasmtime", default-features = false }
wrpc-transport = { version = "0.24.2", path = "./crates/transport", default-features = false }
wrpc-transport-nats = { version = "0.21", path = "./crates/transport-nats", default-features = false }
wrpc-types = { version = "0.6", path = "./crates/types", default-features = false }
wrpc-wasmtime-nats-cli = { version = "*", path = "./crates/wasmtime-nats-cli", default-features = false }
28 changes: 28 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "wrpc-cli"
version = "0.1.0"
description = "wRPC CLI"
publish = false

authors.workspace = true
categories.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true

[features]
default = ["nats"]
nats = ["dep:async-nats", "dep:tokio", "tokio/sync", "dep:url"]

[dependencies]
anyhow = { workspace = true }
async-nats = { workspace = true, optional = true }
tokio = { workspace = true, optional = true }
tracing-subscriber = { workspace = true, features = [
"ansi",
"env-filter",
"fmt",
"smallvec",
"tracing-log",
] }
url = { workspace = true, optional = true }
3 changes: 3 additions & 0 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#[cfg(feature = "nats")]
pub mod nats;
pub mod tracing;
34 changes: 34 additions & 0 deletions crates/cli/src/nats.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use anyhow::Context as _;
use tokio::sync::mpsc;
use url::Url;

pub const DEFAULT_URL: &str = "nats://127.0.0.1:4222";

/// Connect to NATS.io server and ensure that the connection is fully established before
/// returning the resulting [`async_nats::Client`]
pub async fn connect(url: Url) -> anyhow::Result<async_nats::Client> {
let (conn_tx, mut conn_rx) = mpsc::channel(1);
let client = async_nats::connect_with_options(
String::from(url),
async_nats::ConnectOptions::new()
.retry_on_initial_connect()
.event_callback(move |event| {
let conn_tx = conn_tx.clone();
async move {
if let async_nats::Event::Connected = event {
conn_tx
.send(())
.await
.expect("failed to send NATS.io server connection notification");
}
}
}),
)
.await
.context("failed to connect to NATS.io server")?;
conn_rx
.recv()
.await
.context("failed to await NATS.io server connection to be established")?;
Ok(client)
}
14 changes: 14 additions & 0 deletions crates/cli/src/tracing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use tracing_subscriber::layer::SubscriberExt as _;
use tracing_subscriber::util::SubscriberInitExt as _;

pub fn env_filter() -> tracing_subscriber::EnvFilter {
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info"))
}

pub fn init() {
tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer().compact().without_time())
.with(env_filter())
.init();
}
67 changes: 67 additions & 0 deletions crates/wasmtime-nats-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[package]
name = "wrpc-wasmtime-nats-cli"
version = "0.1.0"
description = "wRPC Wasmtime NATS CLI"
publish = false

authors.workspace = true
categories.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true

[dependencies]
anyhow = { workspace = true }
async-nats = { workspace = true }
clap = { workspace = true, features = [
"color",
"derive",
"error-context",
"help",
"std",
"suggestions",
"usage",
] }
futures = { workspace = true }
hyper = { workspace = true, features = ["server"] }
hyper-util = { workspace = true, features = ["server-auto", "tokio"] }
reqwest = { workspace = true }
tokio = { workspace = true, features = ["fs"] }
tracing = { workspace = true, features = ["attributes"] }
tracing-subscriber = { workspace = true, features = [
"ansi",
"env-filter",
"fmt",
] }
url = { workspace = true }
wasmcloud-component-adapters = { workspace = true }
wasmparser = { workspace = true }
wasmtime = { workspace = true, features = [
"addr2line",
"async",
"cache",
"coredump",
"cranelift",
"demangle",
"gc",
"parallel-compilation",
"runtime",
"threads",
"wat",
] }
wasmtime-wasi = { workspace = true }
wasmtime-wasi-http = { workspace = true }
wit-bindgen-wrpc = { workspace = true }
wit-component = { workspace = true }
wit-parser = { workspace = true }
wrpc-cli = { workspace = true, features = ["nats"] }
wrpc-transport = { workspace = true }
wrpc-transport-nats = { workspace = true }
wrpc-types = { workspace = true }
wrpc-interface-http = { workspace = true, features = [
"http",
"http-body",
"hyper",
"wasmtime-wasi-http",
] }
wrpc-runtime-wasmtime = { workspace = true }
Loading

0 comments on commit 2c24bcb

Please sign in to comment.