Is there any tooling for checking whether a component conforms to a given world definition? It would be nice if the host could check this pre-instantiation for better error messaging.
wasmtime::component::Linker::instantiate_pre
should check imports, but not exports
I suppose you could build a dummy component that imports your world, link it to your target component, then import-check that
If this is specifically for the host embedding I think it'd be reasonable to add logic along these lines to the Host::instantiate_pre
method that's generated for each world. In addition to the import checking of instantiate_pre
it could additionally verify that all the exports are present and have the expected types.
I'll note though that the degree of type reflection required for that isn't currently implemented in Wasmtime, but I don't think there's any major blockers to doing so, it's largely a matter of minor design and mostly elbow grease (IIRC)
It looks like the Host::instantiate_pre
methods somewhat confusingly are for instantiating InstancePre
s, not creating them
err...@rylev is that what you're looking for? An explicit type-check when instantiating or without needing to instantiate?
I may have projected the feature I want onto your request :sweat_smile:
oh oops right
we could add a different method for doing the typecheck-without-instantiating part in any case, and I don't think that it otherwise exists today in Wasmtime
Correct, this would explicitly be pre-instantiation. There is generally a large amount of time for before instantiation that runtimes and wrapper tooling has to check that the binary in question will be able to run.
Do we need wasmtime to do this? Is this not something that can be checked statically and thus might be more appropriate in wasm-tools?
I assume the point was that wasmtime has to do all the type-checking work anyway as part of instantiation, so exposing ways to do it separately is useful. In the non-components API we've found it's useful to allow embedders to front-load that work and do it once, then skip the type-checking during instantiation after that. So a similar API for components would make sense. But having a standalone command-line type-checker sounds to me like something useful as well.
Do we need wasmtime to do this? Is this not something that can be checked statically and thus might be more appropriate in wasm-tools?
Currently, yes. The idea I think is given a wasmtime::component::Component
an embedder can test "does this have the signature I want". That can also be done at the wasmparser
level using today's APIs but adding type-reflection to components is always something I wanted to get to at some point (e.g. along the lines of the wasmtime::Module::{imports,exports}
methods which allow you to inspect, without instantiating, the types involved)
I do agree with Jamey though and a possible wasm-tools component implements foo.wit foo.wasm
could also work
(or something like that)
I would expect that in the fullness of time people would want to know ahead of time, meaning that although wasmtime should check, the more important systemic thing would be for people to check as part of understanding what is and is not expected to run properly.
Talked to @Brian about this. We're going to create an issue and maybe see if we can work on a tool.
We were thinking about possibly trying to do this at the wit level
Created an issue track: https://github.com/bytecodealliance/wasm-tools/issues/1011
Last updated: Nov 22 2024 at 16:03 UTC