Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 122 additions & 1 deletion Cargo.lock

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

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
members = [
"components/debug",
"components/recorder"
, "crates/trace"]
, "crates/dialog", "crates/trace"]
[workspace.dependencies]
wit-bindgen = { version = "0.52.0", default-features = false, features = ["bitflags", "std", "macros"] }
serde = { version = "1.0.226", features = ["derive"] }
serde_json = "1.0.145"
wasm-wave = { git = "https://github.com/chenyan2002/wasm-tools.git", branch = "extend-wave", version = "0.239.0", default-features = false }

[package]
name = "proxy-component"
Expand All @@ -28,7 +29,9 @@ wit-component = "0.245.0"

wasmtime = { version = "42.0.0", features = ["wave"], optional = true }
wasmtime-wasi = { version = "42.0.0", optional = true }
dialog = { path = "crates/dialog", optional = true }
ctrlc = "3.5.2"

[features]
run = ["wasmtime", "wasmtime-wasi"]
#default = ["run"]
run = ["wasmtime", "wasmtime-wasi", "dialog"]
default = ["run"]
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all build-components build-cli test test-record test-fuzz run-fuzz run-record run-viceroy
.PHONY: all build-components build-cli test test-record test-fuzz test-dialog run-fuzz run-record run-dialog run-viceroy

all: build-components build-cli
build-cli:
Expand All @@ -9,10 +9,14 @@ build-components:
cp target/wasm32-wasip2/release/debug.wasm assets/debug.wasm
cp target/wasm32-wasip2/release/recorder.wasm assets/recorder.wasm

test: test-fuzz test-record
test: test-fuzz test-record test-dialog

test-fuzz:
RUSTFLAGS="" $(MAKE) run-fuzz WASM=tests/calculator.wasm
$(MAKE) run-fuzz WASM=tests/calculator.wasm
# build-only test
target/release/proxy-component instrument -m fuzz tests/rust.wasm
target/release/proxy-component instrument -m fuzz tests/go.wasm
target/release/proxy-component instrument -m fuzz tests/python.wasm

test-record:
$(MAKE) run-record WASM=tests/go.wasm
Expand All @@ -21,6 +25,15 @@ test-record:
# test the same trace with a different wasm replay
target/release/proxy-component instrument -m replay tests/rust.debug.wasm
wasmtime --invoke 'start()' composed.wasm < trace.out
# build-only test
target/release/proxy-component instrument -m record tests/calculator.wasm
target/release/proxy-component instrument -m replay tests/calculator.wasm

test-dialog:
rm tests/composed.wasm || true
for wasm in tests/*.wasm; do \
$(MAKE) run-dialog WASM=$$wasm; \
done

run-fuzz:
target/release/proxy-component instrument -m fuzz $(WASM)
Expand All @@ -35,6 +48,11 @@ run-record:
target/release/proxy-component instrument -m replay --use-host-recorder $(WASM)
target/release/proxy-component run composed.wasm --invoke 'start()' --trace trace.out

run-dialog:
target/release/proxy-component instrument -m dialog $(WASM)
# build-only
# target/release/proxy-component run composed.wasm --invoke 'start()'

run-viceroy:
viceroy composed.wasm > trace.out & echo $$! > viceroy.pid
until nc -z localhost 7676; do \
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ $ wasmtime --invoke 'start()' composed.wasm
Fuzzing the import return and export input based on the WIT type. This mode requires a [Debug component](components/debug/) to get random numbers and logging. The `composed.wasm` can be run in
a standalone `wasmtime` without any special host functions.

### Dialog

```
$ proxy-component instrument -m dialog <component.wasm>
$ proxy-component run composed.wasm --invoke 'start()'
```

Provide an interactive terminal for users to mock import and export calls.
[![asciicast](https://asciinema.org/a/BeVtK4cwsTsqmDo6.svg)](https://asciinema.org/a/BeVtK4cwsTsqmDo6)

This mode requires raw access to terminal, which can only be implemented on the host side for now.
So the composed binary can only be run with `proxy-component run`, instead of a regular `wasmtime`.

### Generate

Given a `bindings.rs` file generated from `wit-bindgen`. This command can generate code to implement
Expand Down
25 changes: 25 additions & 0 deletions assets/util.wit
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@ interface debug {
get-random: func() -> list<u8>;
}

interface dialog {
print: func(dep:u32, x:string);
read-raw-string: func(dep: u32, prompt: string) -> string;
read-num: func(dep: u32, prompt: string) -> u32;
read-select: func(dep: u32, prompt: string, items: list<string>) -> u32;
read-multi-select: func(dep: u32, prompt: string, items: list<string>) -> list<u32>;
read-bool: func(dep: u32) -> string;
read-string: func(dep: u32) -> string;
read-u8: func(dep: u32) -> string;
read-u16: func(dep: u32) -> string;
read-u32: func(dep: u32) -> string;
read-u64: func(dep: u32) -> string;
read-s8: func(dep: u32) -> string;
read-s16: func(dep: u32) -> string;
read-s32: func(dep: u32) -> string;
read-s64: func(dep: u32) -> string;
read-f32: func(dep: u32) -> string;
read-f64: func(dep: u32) -> string;
read-char: func(dep: u32) -> string;
}

world crate-debug {
export debug;
}

world host-dialog {
import dialog;
}
9 changes: 9 additions & 0 deletions crates/dialog/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "dialog"
version = "0.1.0"
edition = "2024"

[dependencies]
console = "0.16.2"
dialoguer = { version = "0.12.0", default-features = false }
wasm-wave.workspace = true
Loading