Skip to content

Commit a6cbcbf

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.
1 parent 9cefa7a commit a6cbcbf

6 files changed

Lines changed: 38 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
55

66
## [Prerelease] - Unreleased
77

8+
### Added
9+
- Added support for selecting a specific world from WIT files with multiple worlds using the `WIT_WORLD_NAME` environment variable (#202)
10+
811
## [v0.12.0] - 2025-12
912

1013
### 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
@@ -103,6 +103,7 @@ fn build_wasm_runtime() -> PathBuf {
103103

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

src/hyperlight_wasm_macro/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ proc-macro2 = { version = "1.0.106" }
1616
syn = { version = "2.0.117" }
1717
itertools = { version = "0.14.0" }
1818
prettyplease = { version = "0.2.37" }
19-
hyperlight-component-util = { version = "0.12.0" }
19+
hyperlight-component-util = { git = "https://github.com/hyperlight-dev/hyperlight.git", branch = "main" }

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, |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/wasm_runtime/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ fn main() {
6060
cfg.compile("wasm_runtime");
6161

6262
println!("cargo::rerun-if-env-changed=WIT_WORLD");
63+
println!("cargo::rerun-if-env-changed=WIT_WORLD_NAME");
6364
println!("cargo::rustc-check-cfg=cfg(component)");
6465
if env::var_os("WIT_WORLD").is_some() {
6566
println!("cargo::rustc-cfg=component");

0 commit comments

Comments
 (0)