Skip to content

Commit 2dc90f4

Browse files
committed
feat: add world selection for multi-world WIT files
Support WIT_WORLD_NAME env var in hyperlight-wasm-macro to select a specific world from WIT files containing multiple worlds. Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
1 parent ba1932a commit 2dc90f4

5 files changed

Lines changed: 38 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66
## [Prerelease] - Unreleased
77

88
### Changed
9+
910
- **BREAKING CHANGE:** Removed `SandboxBuilder::with_function_definition_size`. Host function definitions are now pushed to the guest at runtime load time instead of using a separate memory region. (#388)
1011

12+
### Added
13+
- Added support for selecting a specific world from WIT files with multiple worlds using the `WIT_WORLD_NAME` environment variable (#202)
14+
1115
## [v0.12.0] - 2025-12
1216

1317
### Added

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,32 @@ generate bindings from the same component type in the host. For a
9898
complete (albeit small) example of this, see [this
9999
example](https://aka.ms/hyperlight-wasm-sockets-sample).
100100

101+
### Selecting a specific world
102+
103+
If your WIT file contains multiple worlds, you can select which world
104+
to use by setting the `WIT_WORLD_NAME` environment variable to the name
105+
of the desired world. If not set, the last world in the file will be used.
106+
107+
For example, given a WIT file with multiple worlds:
108+
109+
```wit
110+
package example:worlds;
111+
112+
world http-world {
113+
export http-interface;
114+
}
115+
116+
world queue-world {
117+
export queue-interface;
118+
}
119+
```
120+
121+
To generate bindings for `http-world` instead of the default `queue-world`:
122+
123+
```
124+
WIT_WORLD=/path/to/output.wasm WIT_WORLD_NAME=http-world cargo build -p hyperlight-wasm
125+
```
126+
101127
### Debugging the macro
102128

103129
You can get more detailed error messages by expanding the Macro locally:

src/hyperlight_wasm/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ fn build_wasm_runtime() -> PathBuf {
126126

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

src/hyperlight_wasm_macro/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@ mod wasmguest;
2626
/// into wasmtime) and registers wasmtime host functions with the
2727
/// wasmtime linker for component imports (which are implemented by
2828
/// calling to the Hyperlight host).
29+
///
30+
/// If the WIT file contains multiple worlds, set the `WIT_WORLD_NAME`
31+
/// environment variable to select a specific world by name. If not set,
32+
/// the last world in the file will be used.
2933
#[proc_macro]
3034
pub fn wasm_guest_bindgen(_: proc_macro::TokenStream) -> proc_macro::TokenStream {
3135
let path = std::env::var_os("WIT_WORLD").unwrap();
32-
util::read_wit_type_from_file(path, None, |kebab_name, ct| {
36+
let world_name = std::env::var("WIT_WORLD_NAME").ok();
37+
util::read_wit_type_from_file(path, world_name, |kebab_name, ct| {
3338
let decls = emit::run_state(true, true, |s| {
3439
// Emit type/trait definitions for all instances in the world
3540
rtypes::emit_toplevel(s, &kebab_name, ct);

src/hyperlight_wasm_runtime/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ fn main() {
6565
cfg.compile("wasmtime-hyperlight-platform");
6666

6767
println!("cargo::rerun-if-env-changed=WIT_WORLD");
68+
println!("cargo::rerun-if-env-changed=WIT_WORLD_NAME");
6869
println!("cargo::rustc-check-cfg=cfg(component)");
6970
if env::var_os("WIT_WORLD").is_some() {
7071
println!("cargo::rustc-cfg=component");

0 commit comments

Comments
 (0)