Stream: wasmtime

Topic: Optional imports in component model


view this post on Zulip mainrs (Jul 14 2025 at 16:35):

Hey! I use WASM as a plugin system. I have a plugin A that provides information. It's existence during runtime is not guaranteed, though. Is it possible to implement "optional" imports using the component model? I.e., have a plugin B check if A is available and if it is, call its functions?

AFAIK, there is no official specification for this feature, but there is interest. In the meantime, can I somehow hook into wasmtime to provide a stub implementation that simply returns no data at all when plugin B tries to invooke functions of A ?

view this post on Zulip Lann Martin (Jul 14 2025 at 17:23):

You are correct that there is no explicit support for optional imports yet.

view this post on Zulip Lann Martin (Jul 14 2025 at 17:28):

There are a few options here depending on your exact requirements. Wasmtime can inspect component exports so you might be able to provide some interface that lets one plugin query the interfaces of other plugins via the host.

view this post on Zulip Lann Martin (Jul 14 2025 at 17:30):

Wasmtime can also inspect imports so you could inject stub implementations for missing plugins.

view this post on Zulip Lann Martin (Jul 14 2025 at 17:31):

There is also this feature, though it's a pretty big hammer: https://docs.rs/wasmtime/latest/wasmtime/component/struct.Linker.html#method.define_unknown_imports_as_traps


Last updated: Dec 06 2025 at 06:05 UTC