Skip to content

Conversation

@vshailesh
Copy link
Contributor

@vshailesh vshailesh commented Nov 10, 2025

fixes: #651

  • adds support to select a specific world from a WIT file if multiple worlds are specified.

host_bindgen and guest_bindgen accepts two type of inputs now

  1. old way - currently being used everywhere - directly giving path of the wasm compiled file.
  2. path and world_name as input to choose a specific world name if you want that.
  3. removed race condition issue in the hyperlight_component_util/util.rs

@ludfjig ludfjig added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Nov 10, 2025
@vshailesh vshailesh force-pushed the host_bindgen_macro branch 3 times, most recently from 44804b7 to 2136234 Compare November 20, 2025 19:55
@vshailesh
Copy link
Contributor Author

@ludfjig

Copy link
Contributor

@ludfjig ludfjig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice! Some minor nits. Also I assigned copilot to see if it has any suggestions

@vshailesh
Copy link
Contributor Author

  • output generated on local testing
    pub mod r#wit {
        pub mod r#first_import {
            #[derive(Debug)]
            pub struct RecFirstExport {
                pub r#key: alloc::string::String,
                pub r#value: alloc::string::String,
            }
        }
        pub trait FirstImport {}
        pub trait FirstworldExports<I: FirstworldImports + ::core::marker::Send> {}
        pub trait FirstworldImports {
            type FirstImport: super::super::r#twoworlds::r#wit::FirstImport;
            fn r#first_import(
                &mut self,
            ) -> impl ::core::borrow::BorrowMut<Self::FirstImport>;
        }
        pub trait Firstworld {
            type Exports<
                I: FirstworldImports + ::core::marker::Send,
            >: FirstworldExports<I>;
            fn instantiate<I: FirstworldImports + ::core::marker::Send + 'static>(
                self,
                imports: I,
            ) -> Self::Exports<I>;
        }
    }
}
pub(crate) struct FirstworldResources<I: r#twoworlds::r#wit::FirstworldImports> {
    resource0: (),
    _phantomI: ::core::marker::PhantomData<I>,
}
impl<I: r#twoworlds::r#wit::FirstworldImports> FirstworldResources<I> {
    fn new() -> Self {
        FirstworldResources {
            resource0: (),
            _phantomI: ::core::marker::PhantomData,
        }
    }
}
pub struct FirstworldSandbox<
    T: r#twoworlds::r#wit::FirstworldImports,
    S: ::hyperlight_host::sandbox::Callable,
> {
    pub(crate) sb: S,
    pub(crate) rt: ::std::sync::Arc<::std::sync::Mutex<FirstworldResources<T>>>,
}
pub(crate) fn register_host_functions<
    I: r#twoworlds::r#wit::FirstworldImports + ::std::marker::Send + 'static,
    S: ::hyperlight_host::func::Registerable,
>(sb: &mut S, i: I) -> ::std::sync::Arc<::std::sync::Mutex<FirstworldResources<I>>> {
    let rts = ::std::sync::Arc::new(::std::sync::Mutex::new(FirstworldResources::new()));
    let imports = ::std::sync::Arc::new(::std::sync::Mutex::new(i));
    rts
}
impl<
    I: r#twoworlds::r#wit::FirstworldImports + ::std::marker::Send,
    S: ::hyperlight_host::sandbox::Callable,
> r#twoworlds::r#wit::FirstworldExports<I> for FirstworldSandbox<I, S> {}
impl r#twoworlds::r#wit::Firstworld
for ::hyperlight_host::sandbox::UninitializedSandbox {
    type Exports<I: r#twoworlds::r#wit::FirstworldImports + ::std::marker::Send> = FirstworldSandbox<
        I,
        ::hyperlight_host::sandbox::initialized_multi_use::MultiUseSandbox,
    >;
    fn instantiate<
        I: r#twoworlds::r#wit::FirstworldImports + ::std::marker::Send + 'static,
    >(mut self, i: I) -> Self::Exports<I> {
        let rts = register_host_functions(&mut self, i);
        let sb = self.evolve().unwrap();
        FirstworldSandbox { sb, rt: rts }
    }
}

@vshailesh vshailesh force-pushed the host_bindgen_macro branch 5 times, most recently from 0dad0d8 to 4d789a7 Compare November 21, 2025 23:28
@ludfjig ludfjig assigned Copilot and unassigned Copilot Nov 22, 2025
@vshailesh vshailesh force-pushed the host_bindgen_macro branch 2 times, most recently from 7c27985 to 7d7917a Compare November 22, 2025 08:45
@vshailesh vshailesh changed the title Closes #651 : Added new function proc_macro host_bingden2 Closes #651 : Modify host_bindgen proc_macro to support selecting specific world Nov 22, 2025
Copy link
Contributor

@ludfjig ludfjig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this! Looks good to me, but will defer to @syntactically to have a look as well

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements the ability to select a specific world from a WIT file that contains multiple worlds, addressing issue #651. Previously, the host_bindgen and guest_bindgen macros would automatically select the last exported world. Now users can explicitly specify which world to use via a new structured syntax.

Key Changes:

  • Extended host_bindgen and guest_bindgen proc macros to accept structured input with {path: "...", world_name: "..."} syntax
  • Modified component parsing logic to select a world by name when specified, falling back to the last world for backward compatibility
  • Added test case demonstrating world selection with a new two-world WIT file

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 17 comments.

Show a summary per file
File Description
src/tests/rust_guests/witguest/two_worlds.wit Adds a new WIT file defining two worlds (firstworld and secondworld) for testing world selection functionality
src/hyperlight_host/tests/wit_test.rs Adds test module demonstrating the new world selection syntax using firstworld from the two-world WIT file
src/hyperlight_component_util/src/util.rs Updates read_wit_type_from_file to accept an optional world_name parameter and pass it to component parsing
src/hyperlight_component_util/src/component.rs Implements world selection logic in read_component_single_exported_type to find worlds by name when specified
src/hyperlight_component_macro/src/lib.rs Adds BindgenInputParams struct with custom parser to support both legacy path-only syntax and new structured syntax with path and world_name
Justfile Adds build command for the new two_worlds.wit test file to generate twoworlds.wasm

@vshailesh vshailesh force-pushed the host_bindgen_macro branch 4 times, most recently from f8d97ef to 4d789a7 Compare December 7, 2025 21:08
@vshailesh vshailesh changed the title Closes #651 : Modify host_bindgen proc_macro to support selecting specific world [DO NOT MERGE UNTIL NEXT 10 DEC 2025 CALL] Closes #651 : Modify host_bindgen proc_macro to support selecting specific world Dec 9, 2025
@vshailesh vshailesh force-pushed the host_bindgen_macro branch 2 times, most recently from e45cedd to af04846 Compare December 10, 2025 14:48
@vshailesh vshailesh changed the title [DO NOT MERGE UNTIL NEXT 10 DEC 2025 CALL] Closes #651 : Modify host_bindgen proc_macro to support selecting specific world Closes #651 : Modify host_bindgen proc_macro to support selecting specific world Dec 10, 2025
Copy link
Contributor

@jsturtevant jsturtevant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, Just a couple minor questions but the structure looks right!

- adds support to select a specific world from a WIT file if
  multiple worlds are specified.

Signed-off-by: Shailesh Vashishth <[email protected]>
@jsturtevant jsturtevant merged commit 7250968 into hyperlight-dev:main Dec 11, 2025
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement For PRs adding features, improving functionality, docs, tests, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support selecting a world for host_bindgen

3 participants