Stream: wit-bindgen

Topic: Instantiating imported resources without a constructor


view this post on Zulip Maxim Schuwalow (Jan 15 2025 at 16:42):

Hi

I'm trying to crate a wrapper around an existing interface which takes a resource (which doesn't declare a constructor) as an input. Is there a way to create a component which takes different inputs, creates and instance of that resource and calls the existing interface?

Specifically I'm stuck on the fact that the generated bindings don't seem to include any way to instantiate the resource.

view this post on Zulip Dan Gohman (Jan 15 2025 at 19:20):

To be usable, the inner interface either needs a constructor or some other function that returns a handle.

view this post on Zulip Maxim Schuwalow (Jan 15 2025 at 19:26):

In this case I want to wrap the wasi:http/incoming-handler, so I cannot modify it in any way.

So there is not workaround to make this work and that interface just cannot be used from plain wasm?

view this post on Zulip Dan Gohman (Jan 15 2025 at 19:39):

Ah, that's a good question. I don't know the answer.

view this post on Zulip Joel Dice (Jan 15 2025 at 19:50):

I think this is an artifact of the asymmetric API of wasi:http@0.2.0, where the underlying assumption is that the only party who should be creating instances of incoming-request is the one who is exporting that resource -- normally the host, but possibly a component.

What you're trying to do is trivial in the 0.3.0-draft since there's only one request resource, which has a constructor that any component can call. And in general WASIp3 will make virtualizing interfaces which involve I/O practical, which isn't really the case for WASIp2, unfortunately. I've tried several times to virtualize wasi:http@0.2.x and failed, which is one of the reasons I'm so keen to get WASIp3 released.

Contribute to WebAssembly/wasi-http development by creating an account on GitHub.

Last updated: Jan 24 2025 at 00:11 UTC