Skip to content

Commit

Permalink
chore: Update Wasmtime & Related Deps (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrishn7 authored Aug 27, 2024
1 parent b87ccd1 commit 43c94ff
Show file tree
Hide file tree
Showing 13 changed files with 485 additions and 408 deletions.
705 changes: 429 additions & 276 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resolver = "2"

[workspace.package]
edition = "2021"
rust-version = "1.73.0"
rust-version = "1.80.0"
authors = ["Rohan Krishnaswamy <[email protected]>"]
description = "Kiwi is a fast and extensible WebSocket gateway for real-time event sources"
repository = "https://github.com/rkrishn7/kiwi"
Expand Down
5 changes: 0 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build --release --locked --bin kiwi

# Install the necessary WASI adapter module for the Kiwi hook runtime
RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v18.0.2/wasi_snapshot_preview1.reactor.wasm \
-o wasi_snapshot_preview1.wasm

FROM debian:bookworm-slim
WORKDIR /app

Expand All @@ -36,6 +32,5 @@ RUN apt-get update && \
apt-get clean

COPY --from=builder /app/target/release/kiwi /usr/local/bin
COPY --from=builder /app/wasi_snapshot_preview1.wasm /etc/kiwi/wasi/wasi_snapshot_preview1.wasm

ENTRYPOINT ["/usr/local/bin/kiwi"]
6 changes: 1 addition & 5 deletions Dockerfile.ci
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.73.0-buster as builder
FROM rust:1.80-bookworm as builder
WORKDIR /app

# Install cmake (Required to build librdkafka)
Expand All @@ -10,8 +10,4 @@ COPY . .

RUN cargo build --release --locked --bin kiwi

# Install the necessary WASI adapter module for the Kiwi hook runtime
RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v18.0.2/wasi_snapshot_preview1.reactor.wasm \
-o /etc/kiwi/wasi/wasi_snapshot_preview1.wasm --create-dirs

ENTRYPOINT ["./.circleci/bin/entrypoint.sh"]
4 changes: 2 additions & 2 deletions examples/authenticate-http/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/authenticate-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "authenticate-http"
version = "0.0.0"
publish = false
edition = "2021"
rust-version = "1.73.0"
rust-version = "1.80.0"

[lib]
crate-type = ["cdylib"]
Expand Down
2 changes: 1 addition & 1 deletion examples/intercept-simple/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "intercept"
version = "0.0.0"
publish = false
edition = "2021"
rust-version = "1.73.0"
rust-version = "1.80.0"

[lib]
crate-type = ["cdylib"]
Expand Down
2 changes: 1 addition & 1 deletion src/kiwi-sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "kiwi-sdk"
version = "0.1.1"
rust-version = "1.71.1"
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion src/kiwi-sdk/macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "kiwi-macro"
version = "0.1.1"
rust-version = "1.71.1"
edition.workspace = true
license.workspace = true
rust-version.workspace = true
repository.workspace = true
description = "Macros for the Kiwi SDK"

Expand Down
7 changes: 4 additions & 3 deletions src/kiwi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ tokio = { version = "1", features = ["full"] }
tokio-stream = { version = "0.1.14", features = ["sync"] }
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
wasmtime = { version = "18.0.2", features = ["component-model", "async"] }
wasmtime-wasi = "18.0.2"
wasmtime-wasi-http = "18.0.2"
wasi-preview1-component-adapter-provider = "24.0.0"
wasmtime = { version = "24.0.0", features = ["component-model", "async"] }
wasmtime-wasi = "24.0.0"
wasmtime-wasi-http = "24.0.0"
wat = "1.0.85"
wit-component = "0.20.1"
ringbuf = "0.3.3"
Expand Down
31 changes: 7 additions & 24 deletions src/kiwi/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ impl Kafka {
pub struct Hooks {
pub intercept: Option<String>,
pub authenticate: Option<String>,
pub __adapter_path: Option<String>,
}

/// Server configuration
Expand Down Expand Up @@ -159,10 +158,8 @@ async fn watch_path_with_delay(

/// Recompiles the specified hook from its cached file path and adapter path
fn reload_hook<T: WasmHook>(hook: &Arc<ArcSwapOption<T>>) -> anyhow::Result<()> {
if let Some((module_path, adapter_path)) =
hook.load().as_ref().map(|h| (h.path(), h.adapter_path()))
{
hook.store(Some(Arc::new(T::from_file(module_path, adapter_path)?)));
if let Some(module_path) = hook.load().as_ref().map(|h| h.path()) {
hook.store(Some(Arc::new(T::from_file(module_path)?)));
tracing::info!("Recompiled hook at {:?}", module_path);
}

Expand All @@ -174,7 +171,6 @@ fn reload_hook<T: WasmHook>(hook: &Arc<ArcSwapOption<T>>) -> anyhow::Result<()>
fn reconcile_hook<T: WasmHook>(
hook: &Arc<ArcSwapOption<T>>,
module_path: Option<&String>,
adapter_path: Option<&String>,
) -> anyhow::Result<()> {
if let Some(path) = module_path {
if let Some(last_known_path) = hook.load().as_ref().map(|h| h.path()) {
Expand All @@ -186,12 +182,12 @@ fn reconcile_hook<T: WasmHook>(
// on the old path. While unlikely the path will be updated frequently, it is
// still something to clean up.
if last_known_path != updated_path {
hook.store(Some(Arc::new(T::from_file(path, adapter_path)?)));
hook.store(Some(Arc::new(T::from_file(path)?)));

tracing::info!("Recompiled hook at {:?}", path);
}
} else {
hook.store(Some(Arc::new(T::from_file(path, adapter_path)?)));
hook.store(Some(Arc::new(T::from_file(path)?)));

tracing::info!("Compiled hook at {:?}", path);
}
Expand Down Expand Up @@ -324,13 +320,8 @@ impl<A: WasmHook, B: KafkaSourceBuilder + CounterSourceBuilder, I: WasmHook>
let intercept_path = config.hooks.as_ref().and_then(|c| c.intercept.as_ref());
let authenticate_path = config.hooks.as_ref().and_then(|c| c.authenticate.as_ref());

let adapter_path = config
.hooks
.as_ref()
.and_then(|c| c.__adapter_path.as_ref());

reconcile_hook(&self.intercept, intercept_path, adapter_path)?;
reconcile_hook(&self.authenticate, authenticate_path, adapter_path)?;
reconcile_hook(&self.intercept, intercept_path)?;
reconcile_hook(&self.authenticate, authenticate_path)?;

Ok(())
}
Expand Down Expand Up @@ -615,20 +606,13 @@ mod tests {
struct TestWasmHook;

impl WasmHook for TestWasmHook {
fn from_file<P: AsRef<Path>>(
_path: P,
_adapter_path: Option<P>,
) -> Result<Self, anyhow::Error> {
fn from_file<P: AsRef<Path>>(_path: P) -> Result<Self, anyhow::Error> {
Ok(Self)
}

fn path(&self) -> &Path {
"test".as_ref()
}

fn adapter_path(&self) -> Option<&Path> {
None
}
}

struct TestSourceBuilder;
Expand Down Expand Up @@ -899,7 +883,6 @@ mod tests {
hooks: Some(Hooks {
intercept: Some("test".into()),
authenticate: Some("test".into()),
__adapter_path: None,
}),
server: Server {
address: "127.0.0.1:8000".into(),
Expand Down
8 changes: 4 additions & 4 deletions src/kiwi/src/hook/authenticate/wasm/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ wasmtime::component::bindgen!({
async: true,
tracing: true,
with: {
"wasi:io/error": wasmtime_wasi::preview2::bindings::io::error,
"wasi:io/streams": wasmtime_wasi::preview2::bindings::io::streams,
"wasi:io/poll": wasmtime_wasi::preview2::bindings::io::poll,
"wasi:clocks/monotonic-clock": wasmtime_wasi::preview2::bindings::clocks::monotonic_clock,
"wasi:io/error": wasmtime_wasi::bindings::io::error,
"wasi:io/streams": wasmtime_wasi::bindings::io::streams,
"wasi:io/poll": wasmtime_wasi::bindings::io::poll,
"wasi:clocks/monotonic-clock": wasmtime_wasi::bindings::clocks::monotonic_clock,
"wasi:http/types": wasmtime_wasi_http::bindings::http::types,
"wasi:http/outgoing-handler": wasmtime_wasi_http::bindings::http::outgoing_handler,
}
Expand Down
Loading

0 comments on commit 43c94ff

Please sign in to comment.