Skip to content

Commit

Permalink
feat: finish interpreter
Browse files Browse the repository at this point in the history
Closes #61.

Includes
    - skip notification when there are no receivers
    - add logging in wasm/guest-fn test to webserver integration test
    - update homestar-function(s) to use cargo-component 0.9 and update for breaking changes
    - readme updates around cargo-component
    - const recursion/grow-only defaults for stacker
    - remove most pattern matching guards and move to nested matches in interpreter
    - newly generated test wasms (= cid updates)
  • Loading branch information
zeeshanlakhani committed Mar 4, 2024
1 parent 1e6c7d0 commit 3e35e5a
Show file tree
Hide file tree
Showing 41 changed files with 3,689 additions and 2,838 deletions.
14 changes: 6 additions & 8 deletions Cargo.lock

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

Binary file modified examples/websocket-relay/example_test.wasm
Binary file not shown.
12 changes: 6 additions & 6 deletions examples/websocket-relay/relay-app/src/lib/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export const workflowOnePromised = WorkflowBuilder.workflow({
WorkflowBuilder.crop({
name: "crop",
resource:
"ipfs://bafybeidpmgamv4i6jqrlwbnkrm3kzvvu7hj3jnoolcswub27mkda6p75la",
"ipfs://bafybeidwnpwd3jygfocbto5z6iyxexgeumt7vq7eyk652c6v3tzaifwfhe",
args: {
data: "{{ cid:bafybeiejevluvtoevgk66plh5t6xiy3ikyuuxg3vgofuvpeckb6eadresm }}",
x: 150,
Expand All @@ -268,15 +268,15 @@ export const workflowOnePromised = WorkflowBuilder.workflow({
WorkflowBuilder.rotate90({
name: "rotate90",
resource:
"ipfs://bafybeidpmgamv4i6jqrlwbnkrm3kzvvu7hj3jnoolcswub27mkda6p75la",
"ipfs://bafybeidwnpwd3jygfocbto5z6iyxexgeumt7vq7eyk652c6v3tzaifwfhe",
args: {
data: "{{needs.crop.output}}",
},
}),
WorkflowBuilder.blur({
name: "blur",
resource:
"ipfs://bafybeidpmgamv4i6jqrlwbnkrm3kzvvu7hj3jnoolcswub27mkda6p75la",
"ipfs://bafybeidwnpwd3jygfocbto5z6iyxexgeumt7vq7eyk652c6v3tzaifwfhe",
args: {
data: "{{needs.rotate90.output}}",
sigma: 20.2,
Expand All @@ -293,7 +293,7 @@ export const workflowTwoPromised = WorkflowBuilder.workflow({
WorkflowBuilder.crop({
name: "crop",
resource:
"ipfs://bafybeidpmgamv4i6jqrlwbnkrm3kzvvu7hj3jnoolcswub27mkda6p75la",
"ipfs://bafybeidwnpwd3jygfocbto5z6iyxexgeumt7vq7eyk652c6v3tzaifwfhe",
args: {
data: "{{ cid:bafybeiejevluvtoevgk66plh5t6xiy3ikyuuxg3vgofuvpeckb6eadresm }}",
x: 150,
Expand All @@ -305,15 +305,15 @@ export const workflowTwoPromised = WorkflowBuilder.workflow({
WorkflowBuilder.rotate90({
name: "rotate90",
resource:
"ipfs://bafybeidpmgamv4i6jqrlwbnkrm3kzvvu7hj3jnoolcswub27mkda6p75la",
"ipfs://bafybeidwnpwd3jygfocbto5z6iyxexgeumt7vq7eyk652c6v3tzaifwfhe",
args: {
data: "{{needs.crop.output}}",
},
}),
WorkflowBuilder.grayscale({
name: "grayscale",
resource:
"ipfs://bafybeidpmgamv4i6jqrlwbnkrm3kzvvu7hj3jnoolcswub27mkda6p75la",
"ipfs://bafybeidwnpwd3jygfocbto5z6iyxexgeumt7vq7eyk652c6v3tzaifwfhe",
args: {
data: "{{needs.rotate90.output}}",
},
Expand Down
36 changes: 18 additions & 18 deletions flake.lock

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

47 changes: 21 additions & 26 deletions homestar-functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ building Wasm components in order to run and test them on the latest

We use the components compiled from this crate as fixtures for our
execution-and-[IPLD][ipld]-focused [homestar-wasm crate](../homestar-wasm). We
currently rely on the [WIT format][wit-mvp] IDL to describe exports, for example:
currently rely on the [WIT format][wit-mvp] IDL to describe exports, for
example:

```wit
default world homestar {
Expand All @@ -33,39 +34,35 @@ default world homestar {
}
```


We then implement these functions in [lib.rs](./src/lib.rs) using
[wit-bindgen][wit-bindgen], a guest language bindings generator for
[WIT][wit-mvp] and the [Component Model][component-model].
[wit-bindgen][wit-bindgen]/[wit-bindgen-rt][wit-bindgen-rt], a guest language
bindings generator for [WIT][wit-mvp] and the
[Component Model][component-model].

## Build

Once functions are implemented, we can build the component in release-mode,
targetting [`wasm32-unknown-unknown`][wasm32], :
Once functions are implemented, we can use [cargo-component][cargo-component] to
generate the necessary bindings and build the component in release-mode,
targeting [`wasm32-unknown-unknown`][wasm32-unknown]:

```console
# from this directory:
cd test && cargo build --target wasm32-unknown-unknown --profile release-wasm-fn
cd test && cargo component build --target wasm32-unknown-unknown --profile release-wasm-fn

# or from the top-level workspace:
cargo build -p homestar-functions-test --target wasm32-unknown-unknown --profile release-wasm-fn
cargo component build -p homestar-functions-test --target wasm32-unknown-unknown --profile release-wasm-fn
```

Guest Wasm modules will be generated in the top-level `homestar` directory:
`./target/wasm32-unknown-unknown/release-wasm-fn/homestar_functions_test.wasm`.

Sadly, this module is **not yet** an actual `component`. But, we can leverage
the [wasm-tools][wasm-tools] tooling ([wit-component][wit-component] in
particular) to convert the core Wasm binary to a Wasm component and place
it in a different directory:
We can also build for [`wasm32-wasi`][wasm32-wasi] targets, which
[cargo-component][cargo-component] defaults to:

```console
wasm-tools component new /
../target/wasm32-unknown-unknown/release-wasm-fn/homestar_functions_test.wasm -o ../homestar-wasm/fixtures/
``` console
cargo component build -p homestar-functions-test --profile release-wasm-fn
```

*Of note*, [homestar-wasm's](../homestar-wasm) execution model will do
[this conversion at runtime][conversion-code]!
Guest Wasm modules will be generated in the top-level `homestar` directory:
`./target/wasm32-unknown-unknown/release-wasm-fn/homestar_functions_test.wasm`
or `./target/wasm32-wasi/release-wasm-fn/homestar_functions_test.wasm`.

### Other Helpful Repos

Expand All @@ -74,10 +71,6 @@ wasm-tools component new /
abstract distributed application capabilities, such as key-value, messaging,
http-server/client and more.

### Coming soon

* [WASI][wasi] examples

## License

This project is licensed under the [Apache License 2.0](./LICENSE), or
Expand All @@ -92,15 +85,17 @@ conditions.


[apache]: https://www.apache.org/licenses/LICENSE-2.0
[cargo-component]: https://github.com/bytecodealliance/cargo-component
[component-model]: https://github.com/WebAssembly/component-model
[conversion-code]: https://github.com/ipvm-wg/homestar/blob/main/homestar-wasm/src/wasmtime/world.rs#L277
[ipld]: https://ipld.io/
[kv-demo]: https://github.com/Mossaka/keyvalue-component-model-demo
[spiderlightning]: https://github.com/deislabs/spiderlightning
[wasi]: https://github.com/WebAssembly/WASI
[wasm32]: https://rustwasm.github.io/docs/wasm-pack/prerequisites/non-rustup-setups.html#manually-add-wasm32-unknown-unknown
[wasm32-unknown]: https://rustwasm.github.io/docs/wasm-pack/prerequisites/non-rustup-setups.html#manually-add-wasm32-unknown-unknown
[wasm32-wasi]: https://wasmbyexample.dev/examples/wasi-hello-world/wasi-hello-world.rust.en-us
[wasmtime]: https://github.com/bytecodealliance/wasmtime
[wasm-tools]: https://github.com/bytecodealliance/wasm-tools
[wit-bindgen]: https://github.com/bytecodealliance/wit-bindgen
[wit-bindgen-rt]: https://github.com/bytecodealliance/wit-bindgen-rt
[wit-component]: https://crates.io/crates/wit-component
[wit-mvp]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md
4 changes: 1 addition & 3 deletions homestar-functions/add/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ edition = { workspace = true }
rust-version = { workspace = true }

[dependencies]
wit-bindgen = { version = "0.18.0", default-features = false, features = [
"realloc",
] }
wit-bindgen-rt = "0.20.0"

[lib]
crate-type = ["cdylib"]
Expand Down
Loading

0 comments on commit 3e35e5a

Please sign in to comment.