https://github.com/hyperlight-dev/hyperlight-wasm-calculator-example
https://github.com/hyperlight-dev/hyperlight-wasm-calculator-example
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hyperlight-dev/hyperlight-wasm-calculator-example
- Owner: hyperlight-dev
- License: apache-2.0
- Created: 2025-04-22T20:23:02.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-05T20:28:49.000Z (about 1 year ago)
- Last Synced: 2025-07-07T06:50:39.466Z (12 months ago)
- Language: Rust
- Size: 49.8 KB
- Stars: 2
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `hyperlight-wasm` calculator example
THis is an example of a hyperlight-wasm application that runs a wasm component inside a hyperlight-sandbox that implements a calculator (similar to the component model example [here](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/tutorial)).
The [calculator](./wit/calculator.wit) itself is comprised of three wasm components:
- `calculator` - the main component that implements the calculator interface (written in Rust)
- `adder` - a component that implements the addition operation (written in Rust)
- `subtractor` - a component that implements the subtraction operation (written in Javascript)
- Additionally there is a `multiply` operator that is implemented as a hyperlight host function.
The [example](./example/) program loads the composed calculator/wasm component into a hyperlight-sandbox along with a wasm runtime and invokes functions as hyperlight-guest calls.
## Requirements
To build and run this example, you need the following tools installed on your system:
- [Rust toolchain](https://www.rust-lang.org/tools/install) including `x86_unknown-none` target
- https://www.rust-lang.org/tools/install
- [Node.js](https://nodejs.org/en/download) (to build the [subtractor](./components/subtractor/) wasm component)
- [wasm-tools](https://github.com/bytecodealliance/wasm-tools?tab=readme-ov-file#installation)
- [wac](https://github.com/bytecodealliance/wac?tab=readme-ov-file#installation)
- [cargo component](https://github.com/bytecodealliance/cargo-component?tab=readme-ov-file#installation)
- hyperlight-wasm-aot
- cargo install hyperlight-wasm-aot
- [Just](https://github.com/casey/just?tab=readme-ov-file#installation)
## Running the example
- Build the guest component
```bash
just build-component
```
- Run the example program
```bash
just run-example
```