i'm looking at the WIT docs on 'top level use
': https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md#top-level-use
a set of the examples shows a world importing and exporting the same interface:
package local:demo;
interface my-interface {
use wasi:http/types@1.0.0.{request, response};
}
world my-world {
import wasi:http/handler@1.0.0;
export wasi:http/handler@1.0.0;
}
what does this mean? in my mind, this says that the world uses the interface internally, but also re-exports the _same interface_ to any other worlds that import the world.
is this right?
Yes, exports the same interface, though it doesn't mean re-exporting the imports; it means components have their own implementations that they export. They can forward calls of their exports to their corresponding imports if they want to be a simple pass-through, but they can also have their own logic.
Components that import and export the same interface like this can be stacked, much like lego bricks, where the top of one brick fits into the bottom of the next.
ah! that's neat. are those things that would then need to be composed by the application? it doesn't seem like you can express that sort of transparent proxy stacking with wit.
i'm trying to think of how this would be done, but since, afaik, worlds are the set of all their imports and exports, and worlds including other worlds deduplicate common imports and exports seems to imply to me that a single compiled component can only have one import of the interface and one export of the interface.
everything else seems like it would have to be stitched together elsewhere?
That's right. WIT and worlds are just for describing types of components, and not for doing the actual linking of components. The tool and language for linking is wac, which is related to WIT, but adds features needed for describing linking.
okay great! my mental model of how things work remains intact, and you've taught me something new. thank you.
Hey John :wave: you might also enjoy/benefit from reading the component model book (any contributions/questions/notes on what is unclear would be greatly appreciated!!)
Last updated: Dec 23 2024 at 12:05 UTC