wasm-tools
wasm-tools copied to clipboard
World::name is always "root"
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?
Most likely related to/caused by https://github.com/bytecodealliance/cargo-component/issues/144
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.