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
11 changes: 11 additions & 0 deletions .github/workflows/dep_rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ jobs:
with:
name: guest-modules
path: ./x64/${{ matrix.config }}

- name: Build Rust component model examples
run: |
# this must be build before the formatting and other jobs run
# because the component model example depends on the wasm component built here
just ensure-tools
just build-rust-component-examples ${{ matrix.config }}

- name: Fmt
run: just fmt-check
Expand Down Expand Up @@ -124,6 +131,10 @@ jobs:
# required for gh cli when downloading
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Test Component Model Examples
run: just examples-components ${{ matrix.config }} ${{ matrix.hypervisor == 'mshv3' && 'mshv3' || ''}}
working-directory: ./src/hyperlight_wasm

### Benchmarks ###

- name: Download benchmarks from "latest"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,4 @@ target/

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
src/component_sample/**/*.wasm
97 changes: 97 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = ["src/hyperlight_wasm", "src/examples_common", "src/hyperlight_wasm_aot" ]
exclude = [ "src/wasm_runtime", "src/rust_wasm_samples", "src/hyperlight_wasm_macro" ]
members = [ "src/hyperlight_wasm", "src/examples_common", "src/hyperlight_wasm_aot" ]
exclude = [ "src/wasm_runtime", "src/rust_wasm_samples", "src/hyperlight_wasm_macro", "src/component_sample" ]
resolver = "2"

[workspace.dependencies]
Expand Down
30 changes: 26 additions & 4 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ default-tag:= "latest"
build-wasm-examples-command := if os() == "windows" { "./src/hyperlight_wasm/scripts/build-wasm-examples.bat" } else { "./src/hyperlight_wasm/scripts/build-wasm-examples.sh" }
mkdir-arg := if os() == "windows" { "-Force" } else { "-p" }
latest-release:= if os() == "windows" {"$(git tag -l --sort=v:refname | select -last 2 | select -first 1)"} else {`git tag -l --sort=v:refname | tail -n 2 | head -n 1`}
wit-world := if os() == "windows" { "$env:WIT_WORLD=\"" + justfile_directory() + "\\src\\component_sample\\wit\\component-world.wasm" + "\";" } else { "WIT_WORLD=" + justfile_directory() + "/src/component_sample/wit/component-world.wasm" }

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

build-all target=default-target: (build target) (build-wasm-examples target) (build-rust-wasm-examples target) (build-wasm-runtime target)
ensure-tools:
cargo install --locked wasm-tools --version 1.235.0
cargo install cargo-component --locked --version 0.21.1

build-all target=default-target: (build target) (build-wasm-examples target) (build-rust-wasm-examples target) (build-wasm-runtime target) (build-rust-component-examples target)

build target=default-target features="": (build-wasm-runtime target) (fmt-check)
cargo build {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --verbose --profile={{ if target == "debug" {"dev"} else { target } }}
Expand All @@ -31,23 +36,37 @@ build-rust-wasm-examples target=default-target: (mkdir-redist target)
cargo run -p hyperlight-wasm-aot compile ./src/rust_wasm_samples/target/wasm32-unknown-unknown/{{ target }}/rust_wasm_samples.wasm ./x64/{{ target }}/rust_wasm_samples.aot
cp ./x64/{{ target }}/rust_wasm_samples.aot ./x64/{{ target }}/rust_wasm_samples.wasm

build-rust-component-examples target=default-target:
wasm-tools component wit ./src/component_sample/wit/example.wit -w -o ./src/component_sample/wit/component-world.wasm
# use cargo component so we don't get all the wasi imports https://github.com/bytecodealliance/cargo-component?tab=readme-ov-file#relationship-with-wasm32-wasip2
# we also explicitly target wasm32-unknown-unknown since cargo component might try to pull in wasi imports https://github.com/bytecodealliance/cargo-component/issues/290
rustup target add wasm32-unknown-unknown
cd ./src/component_sample && cargo component build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }}
cargo run -p hyperlight-wasm-aot compile --component ./src/component_sample/target/wasm32-unknown-unknown/{{ target }}/component_sample.wasm ./x64/{{ target }}/component_sample.aot
cp ./x64/{{ target }}/component_sample.aot ./x64/{{ target }}/component_sample.wasm

check target=default-target:
cargo check --profile={{ if target == "debug" {"dev"} else { target } }}
cd src/rust_wasm_samples && cargo check --profile={{ if target == "debug" {"dev"} else { target } }}
cd src/component_sample && cargo check --profile={{ if target == "debug" {"dev"} else { target } }}
cd src/wasm_runtime && cargo check --profile={{ if target == "debug" {"dev"} else { target } }}

fmt-check:
rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check
cd src/rust_wasm_samples && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check
cd src/component_sample && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check
cd src/wasm_runtime && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check
fmt:
fmt:
rustup toolchain install nightly -c rustfmt
cargo +nightly fmt --all
cd src/rust_wasm_samples && cargo +nightly fmt
cd src/wasm_runtime && cargo +nightly fmt
cd src/rust_wasm_samples && cargo +nightly fmt -v --all
cd src/component_sample && cargo +nightly fmt -v --all
cd src/wasm_runtime && cargo +nightly fmt -v --all

clippy target=default-target: (check target)
cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
cd src/rust_wasm_samples && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
cd src/component_sample && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
cd src/wasm_runtime && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings

# TESTING
Expand All @@ -71,6 +90,9 @@ examples-ci target=default-target features="": (build-rust-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,mshv2"} else {"--no-default-features -F function_call_metrics," + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example metrics

examples-components target=default-target features="": (build-rust-component-examples target)
{{ wit-world }} cargo run {{ if features =="" {''} else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example component_example

# warning, compares to and then OVERWRITES the given baseline
bench-ci baseline target=default-target features="":
cd src/hyperlight_wasm && cargo bench --profile={{ if target == "debug" {"dev"} else { target } }} {{ if features =="" {''} else { "--features " + features } }} -- --verbose --save-baseline {{baseline}}
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Make sure the following are installed:
1. [pwsh](https://github.com/PowerShell/PowerShell)
1. [git](https://gitforwindows.org/)
1. [GitHub CLI](https://github.com/cli/cli#installation)
1. [wasm-tools](https://github.com/bytecodealliance/wasm-tools?tab=readme-ov-file#installation)
1. [cargo component](https://github.com/bytecodealliance/cargo-component?tab=readme-ov-file#installation)

Ensure that Windows Hypervisor Platform is enabled:

Expand All @@ -38,6 +40,8 @@ Make sure the following are installed:
1. [Rust](https://www.rust-lang.org/tools/install) `curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh`
1. [just](https://github.com/casey/just). is used as a command runner `cargo install just`. Do not install `just` through a package manager as it may install an older incompatible version, make sure to use at least version 1.5.0 if not installed through cargo.
1. [GitHub CLI](https://github.com/cli/cli#installation)
1. [wasm-tools](https://github.com/bytecodealliance/wasm-tools?tab=readme-ov-file#installation)
1. [cargo component](https://github.com/bytecodealliance/cargo-component?tab=readme-ov-file#installation)

Ensure that KVM is enabled: On an Azure VM using a size that supports nested virtualisation:

Expand Down Expand Up @@ -94,6 +98,17 @@ generate bindings from the same component type in the host. For a
complete (albeit small) example of this, see [this
example](https://aka.ms/hyperlight-wasm-sockets-sample).

### Debugging the macro

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
HYPERLIGHT_COMPONENT_MACRO_DEBUG=/tmp/host.rs cargo build
```


## Code of Conduct

This project has adopted the [Microsoft Open Source Code of
Expand Down
25 changes: 25 additions & 0 deletions src/component_sample/Cargo.lock

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

20 changes: 20 additions & 0 deletions src/component_sample/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "component_sample"
version = "0.1.0"
edition = "2024"

[dependencies]
wit-bindgen-rt = { version = "0.41.0", features = ["bitflags"] }

[lib]
crate-type = ["cdylib"]

[package.metadata.component]
package = "component-sample:example"

[package.metadata.component.target]
path = "wit/example.wit"
world = "example"

[package.metadata.component.target.dependencies]

Loading
Loading