wasm-tools icon indicating copy to clipboard operation
wasm-tools copied to clipboard

World::name is always "root"

Open JMLX42 opened this issue 1 year ago • 2 comments
trafficstars

Hello,

I am following this tutorial:

https://component-model.bytecodealliance.org/language-support/rust.html

Here is my WIT file:

package example:component;

world example {
    // A function to add two 32bit signed integers.
    export add: func(x: s32, y: s32) -> s32;
}

Yet, World::name is apparently set to "root" anyway.

Here is the code that loads/decode the WASM component's WIT:

    // Load the WASM module
    let module = fs::read(&args.file).expect("Failed to load module");
    let wit = wit_component::decode(&module).expect("Failed to decode WIT component");
    // Find the exported functions
    let functions = wit.resolve().worlds.iter().flat_map(|(_id, world)| {
        world.exports.iter().filter_map(|(_, item)| match item {
            WorldItem::Function(func) => Some((&world.name, func)),
            _ => None,
        })
    });

Am I doing something wrong?

JMLX42 avatar Dec 06 '23 14:12 JMLX42

Most likely related to/caused by https://github.com/bytecodealliance/cargo-component/issues/144

JMLX42 avatar Jan 26 '24 15:01 JMLX42

While this is a duplicate of that issue, neither is caused by cargo-component; this is simply the naming convention that wit_component::decode chooses for the name of the world that represents a decoded component, as currently there is nothing in a component that identifies the world it targeted.

The world a component targets at build time and the "world" of the component itself should have structural equivalence, but the name isn't particularly important.

peterhuene avatar Jan 26 '24 18:01 peterhuene