I'm trying to update my template compiler project and its tests to the latest versions of wasmtime
and wasm-tools
. However, after resolving some WIT syntax and minor API changes, I'm getting stuck on the new export validation naming rules (as seen here).
(component
...
(type (;0;) (record))
(type (;1;) (func (param "params" 0) (result string)))
(func (;0;) (type 1) (canon lift (core func 1) string-encoding=utf8 (memory 0) (realloc 0)))
(export (;1;) "apply" (func 0))
)
Error: failed to parse WebAssembly module
Caused by:
func not valid to be used as export (at offset 0x40b)
From what I'm reading, I think I need to export the record type holding my parameters (in this case there are no params, it has no fields). However, when I add that logic and an additional export before the function export the problem doesn't go away.
(component
...
(type (;0;) (record))
(type (;1;) (func (param "params" 0) (result string)))
(func (;0;) (type 1) (canon lift (core func 1) string-encoding=utf8 (memory 0) (realloc 0)))
(export (;2;) "params" (type 0))
(export (;1;) "apply" (func 0))
)
Error: failed to parse WebAssembly module
Caused by:
func not valid to be used as export (at offset 0x416)
What does the component need to look like for this to work?
I've also tried splitting up the export sections to match the tests more closely but get an even more confusing error.
(component
...
(type (;0;) (record))
(export (;1;) "params" (type 0))
(type (;2;) (func (param "params" 0) (result string)))
(func (;0;) (type 1) (canon lift (core func 1) string-encoding=utf8 (memory 0) (realloc 0)))
(export (;1;) "apply" (func 0))
)
Error: failed to parse WebAssembly module
Caused by:
type index 1 is not a function type (at offset 0x40f)
I'm also don't understand why wasmprinter
is labeling the indices the way it does and why splitting sections up behaves so strangely.
it's subtle, but the fix here is to change (param "params" 0)
to (param "params" 1)
indices in comments like (;0;)
mean that the item is introducing and defining index 0, and those comments can in theory be replaced with $foo
for human-readability
indicies like (type 1)
are referring to the index 1
as for sections, at least for now in components the seconds are often interspersed and occur frequently, often with 1 element in them, which is why everything looks jumbled up
the text format preserves the order in the original binary
Do exports introduce new indices in their respective index spaces? If so, I think that's the concept/detail I was missing.
Thanks for your help! The upgrade was successful with the index change you suggested.
https://github.com/Kylebrown9/template-compiler/pull/2
Last updated: Nov 22 2024 at 16:03 UTC