Skip to content
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -479,5 +479,6 @@ target/

# Build-generated binaries
*.wasm
!src/hyperlight_wasm/examples/js-component/wit/hello-world.wasm
*.aot
*.o
12 changes: 11 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ latest-release:= if os() == "windows" {"$(git tag -l --sort=v:refname | select -
wit-world := if os() == "windows" { "$env:WIT_WORLD=\"" + justfile_directory() + "\\src\\tests\\rust_guests\\component_sample\\wit\\component-world.wasm" + "\";" } else { "WIT_WORLD=" + justfile_directory() + "/src/tests/rust_guests/component_sample/wit/component-world.wasm" }
wit-world-c := if os() == "windows" { "$env:WIT_WORLD=\"" + justfile_directory() + "\\src\\tests\\c_guests\\wasmsamples\\components\\runcomponent-world.wasm" + "\";" } else { "WIT_WORLD=" + justfile_directory() + "/src/tests/c_guests/wasmsamples/components/runcomponent-world.wasm" }
wit-world-name-greeter := if os() == "windows" { "$env:WIT_WORLD_NAME=\"greeter-world\";" } else { "WIT_WORLD_NAME=greeter-world" }
qjs-default-runtime := if os() == "windows" { "$env:COMPONENTIZE_QJS_OPT_SIZE=$null;" } else { "unset COMPONENTIZE_QJS_OPT_SIZE;" }
qjs-opt-size-runtime := if os() == "windows" { "$env:COMPONENTIZE_QJS_OPT_SIZE=\"1\";" } else { "export COMPONENTIZE_QJS_OPT_SIZE=1;" }

set windows-shell := ["pwsh.exe", "-NoLogo", "-Command"]

Expand Down Expand Up @@ -70,6 +72,7 @@ check target=default-target:
cd src/tests/rust_guests/rust_wasm_samples && cargo check --profile={{ if target == "debug" {"dev"} else { target } }}
cd src/tests/rust_guests/component_sample && cargo check --profile={{ if target == "debug" {"dev"} else { target } }}
cd src/tests/rust_guests/greeter_sample && cargo check --profile={{ if target == "debug" {"dev"} else { target } }}
cd src/hyperlight_wasm/examples/js-component && cargo check --locked --profile={{ if target == "debug" {"dev"} else { target } }}
cd src/hyperlight_wasm_runtime && cargo hyperlight check --profile={{ if target == "debug" {"dev"} else { target } }}
cd src/hyperlight_wasm_macro && cargo check --profile={{ if target == "debug" {"dev"} else { target } }}

Expand All @@ -78,6 +81,7 @@ fmt-check:
cd src/tests/rust_guests/rust_wasm_samples && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check
cd src/tests/rust_guests/component_sample && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check
cd src/tests/rust_guests/greeter_sample && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check
cd src/hyperlight_wasm/examples/js-component && cargo +nightly fmt -v --all -- --check
cd src/hyperlight_wasm_runtime && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check
cd src/hyperlight_wasm_macro && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check

Expand All @@ -87,6 +91,7 @@ fmt:
cd src/tests/rust_guests/rust_wasm_samples && cargo +nightly fmt -v --all
cd src/tests/rust_guests/component_sample && cargo +nightly fmt -v --all
cd src/tests/rust_guests/greeter_sample && cargo +nightly fmt -v --all
cd src/hyperlight_wasm/examples/js-component && cargo +nightly fmt -v --all
cd src/hyperlight_wasm_runtime && cargo +nightly fmt -v --all
cd src/hyperlight_wasm_macro && cargo +nightly fmt -v --all

Expand All @@ -95,6 +100,7 @@ clippy target=default-target: (check target)
cd src/tests/rust_guests/rust_wasm_samples && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
cd src/tests/rust_guests/component_sample && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
cd src/tests/rust_guests/greeter_sample && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
cd src/hyperlight_wasm/examples/js-component && cargo clippy --locked --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
# hyperlight_wasm_runtime has mutually exclusive wasmtime features, so we run clippy for each separately with all other features
cd src/hyperlight_wasm_runtime && cargo hyperlight clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --no-default-features --features wasmtime_latest,gdb,trace_guest,pulley -- -D warnings
cd src/hyperlight_wasm_runtime && cargo hyperlight clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --no-default-features --features wasmtime_lts,gdb,trace_guest -- -D warnings
Expand All @@ -118,7 +124,11 @@ examples-modules target=default-target features="": (build-wasm-examples target
cargo run {{ if features =="" {''} else {"--no-default-features -F function_call_metrics," + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example metrics
cargo run {{ if features =="" {"--no-default-features --features kvm,mshv3"} else {"--no-default-features -F function_call_metrics," + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example metrics

examples-ci target=default-target features="": (examples-modules target features) (examples-components target features) (examples-pulley target features)
examples-ci target=default-target features="": (examples-modules target features) (examples-components target features) (examples-pulley target features) (examples-js-component target features)

examples-js-component target=default-target features="":
{{ qjs-default-runtime }} cd src/hyperlight_wasm/examples/js-component && cargo run --locked {{ if features == "" {""} else {"--no-default-features -F " + features} }} --profile={{ if target == "debug" {"dev"} else { target } }}
{{ qjs-opt-size-runtime }} cd src/hyperlight_wasm/examples/js-component && cargo run --locked {{ if features == "" {""} else {"--no-default-features -F " + features} }} --profile={{ if target == "debug" {"dev"} else { target } }}

examples-components target=default-target features="": (build-rust-component-examples target features)
{{ wit-world }} cargo run {{ if features =="" {''} else {"--no-default-features -F kvm -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example component_example
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,16 @@ cargo run --example helloworld

Hyperlight-Wasm has experimental support for running WebAssembly
Component Model components, rather than core wasm modules. In this
mode, set the `WIT_WORLD` environment variable to point to
a binary encoding of a component type (e.g. the result of running
mode, set the `WIT_WORLD` environment variable to point to a text `.wit` file
or a binary encoding of a component type (e.g. the result of running
`wasm-tools component wit -w -o /path/to/output.wasm
/path/to/input.wit`), which will ensure that the resultant library
includes a guest binary that is specialised to load components with
that type. Then, use `hyperlight_component_macro::host_bindgen!()` to
generate bindings from the same component type in the host. For a
complete (albeit small) example of this, see [this
that type. For text WIT, use
`hyperlight_component_macro::host_bindgen!({ wit: "path/to/input.wit" })`
to generate bindings from the same world in the host.
`hyperlight_component_macro::host_bindgen!()` still uses `WIT_WORLD`
for binary-encoded input. For a complete (albeit small) example of this, see [this
example](https://aka.ms/hyperlight-wasm-sockets-sample).

### Selecting a specific world
Expand All @@ -121,7 +123,7 @@ world queue-world {
To generate bindings for `http-world` instead of the default `queue-world`:

```
WIT_WORLD=/path/to/output.wasm WIT_WORLD_NAME=http-world cargo build -p hyperlight-wasm
WIT_WORLD=/path/to/input.wit WIT_WORLD_NAME=http-world cargo build -p hyperlight-wasm
```

### Debugging the macro
Expand All @@ -130,7 +132,7 @@ You can get more detailed error messages by expanding the Macro locally:

```
cargo clean -p hyperlight-wasm
WIT_WORLD=</path/to/output.wasm> HYPERLIGHT_COMPONENT_MACRO_DEBUG=/tmp/guest.rs cargo build -p hyperlight-wasm
WIT_WORLD=/path/to/input.wit HYPERLIGHT_COMPONENT_MACRO_DEBUG=/tmp/guest.rs cargo build -p hyperlight-wasm
HYPERLIGHT_COMPONENT_MACRO_DEBUG=/tmp/host.rs cargo build
```

Expand Down
3 changes: 3 additions & 0 deletions src/hyperlight_wasm/examples/js-component/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[env]
WIT_WORLD = { value = "wit/hello.wit", relative = true }
WIT_WORLD_NAME = "hello"
Loading
Loading