Skip to content

Commit

Permalink
feat: finish interpreter (#595)
Browse files Browse the repository at this point in the history
# Description

Finish Ipld <=> Wit interpreter across all available Val/Types. 

fix: handle ints as floats in the interpreter (when given a float Wit
type).

Includes
  - skip notifications when there are no receivers
  - add logging in wasm/guest-fn test to web server 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 the
interpreter
  - newly generated test wasms (= cid updates)
  - move to location/module-path in logs (from updated tracing-logfmt)

## Closes

- Closes fission-codes/stack#155.
- Closes #61 and "finishes" our WIT <=> IPLD interpreter.
  • Loading branch information
Zeeshan Lakhani committed Mar 5, 2024
1 parent d0f969e commit 90c6246
Show file tree
Hide file tree
Showing 44 changed files with 3,727 additions and 2,891 deletions.
36 changes: 6 additions & 30 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://bafybeia32q3oy6u47x624rmsmgrrlpn7ulruissmz5z2ap6alv7goe7h3q",
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://bafybeia32q3oy6u47x624rmsmgrrlpn7ulruissmz5z2ap6alv7goe7h3q",
args: {
data: "{{needs.crop.output}}",
},
}),
WorkflowBuilder.blur({
name: "blur",
resource:
"ipfs://bafybeidpmgamv4i6jqrlwbnkrm3kzvvu7hj3jnoolcswub27mkda6p75la",
"ipfs://bafybeia32q3oy6u47x624rmsmgrrlpn7ulruissmz5z2ap6alv7goe7h3q",
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://bafybeia32q3oy6u47x624rmsmgrrlpn7ulruissmz5z2ap6alv7goe7h3q",
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://bafybeia32q3oy6u47x624rmsmgrrlpn7ulruissmz5z2ap6alv7goe7h3q",
args: {
data: "{{needs.crop.output}}",
},
}),
WorkflowBuilder.grayscale({
name: "grayscale",
resource:
"ipfs://bafybeidpmgamv4i6jqrlwbnkrm3kzvvu7hj3jnoolcswub27mkda6p75la",
"ipfs://bafybeia32q3oy6u47x624rmsmgrrlpn7ulruissmz5z2ap6alv7goe7h3q",
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.

46 changes: 20 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,34 @@ 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 use the [cargo-component][cargo-component] default [`wasm32-wasi`][wasm32-wasi] target:

```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 +70,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 +84,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/tree/main/crates/guest-rust
[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 90c6246

Please sign in to comment.