Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: finish interpreter #595

Merged
merged 6 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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.

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:
zeeshanlakhani marked this conversation as resolved.
Show resolved Hide resolved

```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
zeeshanlakhani marked this conversation as resolved.
Show resolved Hide resolved
[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
Loading