As far as I remember, there's no way to add new optional method to a WASI. Specifically, I'd like to update the interface and the host in a way that allows me to load and run old components and call new optional methods only when they exist on new components.
I vaguely remember that I used to follow a github issue but for the life of me, I cannot find it. Is this actually something on the roadmap or am I just hallucinating :woman_shrugging: ? :pray:
@Ignatz if you expose the new methods as a new interface, you can instantiate it like this:
let component =
Component::from_binary(&engine, &bytes)?;
let instance_pre = self
.linker
.instantiate_pre(&component)?;
let indicesv1 =
interfacev1::GuestIndices::new(&instance_pre).ok();
let indicesv2 = interfacev2::GuestIndices::new(&instance_pre).ok();
let mut store = Store::new(&engine, State::new());
let instance = instance_pre
.instantiate_async(&mut store)
.await?;
let guest_v1 = indicesv1.map(|indices| indices.load(&mut store, &instance))?;
let guest_v2 = indicesv2.map(|indices| indices.load(&mut store, &instance))?;
// do something with your Option<Guest>'s
That's very helpful :pray:. Do you happen to know if there's anything in flight for extending existing interfaces?
I guess if the interface is versioned you can use the same approach to see if you can instantiate v1 or v2, but haven't tried it. don't have anything to do with wasmtime or wasi development, so no idea whats on the roadmap
Appreciated. IIUC, by versioning you mean versioning them with different names, e.g. IFv2? Otherwise you may end up with host-binary linker issues, e.g. having multiple versions of the generated bindings
Wit packages have optional versioning built in, and wasmtime will use semver when resolving names https://component-model.bytecodealliance.org/design/wit.html#packages
So you can have a guest that imports methods from your package@0.1.0, and your host can add a
Method and call that version of the wit 0.1.1, and add the 0.1.1 bindings to the Linker. The guest imports of 0.1.0 will resolve to the implementations in your linkers 0.1.1
My problem is with guest exports. The host rejects guests that don't have a new method
Ah, yes, that’s a valid use case but wit and wasmtime don’t have first class support for that (yet. It’s a known thing that we would like to support one day…)
ack, that's my understanding as well. I felt I had seen a tracking bug in the past...
So for that case you need to use Instance.get_export yourself and then cast the func to the right types,
Yeah I’m on my phone and can’t find it easily but it’s somewhere
So for that case you need to use Instance.get_export yourself and then cast the func to the right types,
Basically not use bindgen, IIUC?
Yeah bindgen isn’t set up to help with this
Pat Hickey said:
Yeah I’m on my phone and can’t find it easily but it’s somewhere
No worries and thanks for the help. If you find a reference later, I'd appreciate it. I'm pretty happy that I didn't hallucinate and even more importantly that it is on the roadmap
Bindgen could probably find some way to support it before it’s formalized in wit, and also the overall systemic issue could move forward, it’s just a matter of someone motivated driving either/both.
I just explained how to do it, how does it not meet the requirements? the world just instantiates all the interfaces, instead of relying on the world, just instantiate the interfaces you care about manually, and handle when they aren't available
David Craven said:
I just explained how to do it, how does it not meet the requirements? the world just instantiates all the interfaces, instead of relying on the world, just instantiate the interfaces you care about manually, and handle when they aren't available
I guess your original example has two separate modules/bindings with interfacev1 & interfacev2. I would prefer not to managed multiple almost identical WIT definitions (since semantic versioning can't help here). Maybe I'm just misunderstanding
Last updated: Jul 29 2026 at 05:03 UTC