Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Prerelease] - Unreleased

### Added
- Added support for selecting a specific world from WIT files with multiple worlds using the `WIT_WORLD_NAME` environment variable (#202)

## [v0.12.0] - 2025-12

### Added
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,32 @@ 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).

### Selecting a specific world

If your WIT file contains multiple worlds, you can select which world
to use by setting the `WIT_WORLD_NAME` environment variable to the name
of the desired world. If not set, the last world in the file will be used.

For example, given a WIT file with multiple worlds:

```wit
package example:worlds;

world http-world {
export http-interface;
}

world queue-world {
export queue-interface;
}
```

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
```

### Debugging the macro

You can get more detailed error messages by expanding the Macro locally:
Expand Down
1 change: 1 addition & 0 deletions src/hyperlight_wasm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ fn build_wasm_runtime() -> PathBuf {

println!("cargo::rerun-if-changed={}", in_repo_dir.display());
println!("cargo::rerun-if-env-changed=WIT_WORLD");
println!("cargo::rerun-if-env-changed=WIT_WORLD_NAME");
// the PROFILE env var unfortunately only gives us 1 bit of "dev or release"
let cargo_profile = if profile == "debug" { "dev" } else { "release" };

Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_wasm_macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ proc-macro2 = { version = "1.0.106" }
syn = { version = "2.0.117" }
itertools = { version = "0.14.0" }
prettyplease = { version = "0.2.37" }
hyperlight-component-util = { version = "0.12.0" }
hyperlight-component-util = { git = "https://github.com/hyperlight-dev/hyperlight.git", branch = "main" }
7 changes: 6 additions & 1 deletion src/hyperlight_wasm_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ mod wasmguest;
/// into wasmtime) and registers wasmtime host functions with the
/// wasmtime linker for component imports (which are implemented by
/// calling to the Hyperlight host).
///
/// If the WIT file contains multiple worlds, set the `WIT_WORLD_NAME`
/// environment variable to select a specific world by name. If not set,
/// the last world in the file will be used.
#[proc_macro]
pub fn wasm_guest_bindgen(_: proc_macro::TokenStream) -> proc_macro::TokenStream {
let path = std::env::var_os("WIT_WORLD").unwrap();
util::read_wit_type_from_file(path, |kebab_name, ct| {
let world_name = std::env::var("WIT_WORLD_NAME").ok();
util::read_wit_type_from_file(path, world_name, |kebab_name, ct| {
let decls = emit::run_state(true, true, |s| {
// Emit type/trait definitions for all instances in the world
rtypes::emit_toplevel(s, &kebab_name, ct);
Expand Down
1 change: 1 addition & 0 deletions src/wasm_runtime/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fn main() {
cfg.compile("wasm_runtime");

println!("cargo::rerun-if-env-changed=WIT_WORLD");
println!("cargo::rerun-if-env-changed=WIT_WORLD_NAME");
println!("cargo::rustc-check-cfg=cfg(component)");
if env::var_os("WIT_WORLD").is_some() {
println!("cargo::rustc-cfg=component");
Expand Down
Loading