Stream: general

Topic: importing and exporting the same interface


view this post on Zulip John VanEnk (Dec 08 2024 at 21:41):

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?

Repository for design and specification of the Component Model - WebAssembly/component-model

view this post on Zulip Dan Gohman (Dec 09 2024 at 00:57):

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.

view this post on Zulip Dan Gohman (Dec 09 2024 at 01:01):

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.

view this post on Zulip John VanEnk (Dec 09 2024 at 22:17):

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.

view this post on Zulip John VanEnk (Dec 09 2024 at 22:18):

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?

view this post on Zulip Dan Gohman (Dec 09 2024 at 22:36):

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.

WebAssembly Composition (WAC) tooling. Contribute to bytecodealliance/wac development by creating an account on GitHub.

view this post on Zulip John VanEnk (Dec 09 2024 at 23:11):

okay great! my mental model of how things work remains intact, and you've taught me something new. thank you.

view this post on Zulip Victor Adossi (Dec 10 2024 at 02:04):

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