wasmex
wasmex copied to clipboard
Support interface imports
Currently top level function interfaces are supported, but importing interfaces does not work. Need to implement this
@superchris I was coding a bit on vacations and ended up implementing this :) (because I needed it for a project)
let me get the crappy version I have in shape and add tests :)
@superchris https://github.com/tessi/wasmex/pull/764 landed! it does a fair bit more than just allowing you to shadow existing WASI imports. (it extends the component type conversion quite a bit) - most notably:
- options are now
:noneor{:some, term()}instead of implicitly convertingniltoNonecases. This allows us to have a{:some, nil}which was not possible before - records allow for optional ok/error inner types. If there is no inner type, we return just
:ok/:errorinstead of the respective tuples - records do not auto-convers casing anymore. I got into quite some hairy debugging with missing fields (my field had a number like
foo-bar42which the kebab casing didn't like asfoo_bar42ended up being converted tofoo-bar-42. Long story short: I removed this magic and would say that we could implement an elixir-helper if we really want this behavior as an option - records now tell you about missing fields during type conversion instead of just crashing at runtime
- a ton of missing type conversions implemented
I would let CI have a look and probably merge soon'ish. If you want to discuss changes, we can always adapt before the next release :)
PR was merged, I'll let this issue open for you @superchris - when you had a chance to have a look (take your time! 🙏 ) and you're happy, feel free to close :)
I have an issue, I try to configure the logging interface.
Wasmex.Components.start_link(%{
path: wasm,
wasi: %Wasmex.Wasi.WasiP2Options{},
imports: %{
"wasi:logging/[email protected]" => %{
"log" => {:fn, fn severity, ctx, message -> IO.inspect({severity, ctx, message}) end}
}
}
})
I get this error:
{:error, "exported function `log` not found."}
Is there something I am missing?
ps: when i remove the imports I get ofcourse the correct error that it is not found:
{:error, "component imports instance `wasi:logging/[email protected]`, but a matching implementation was not found in the linker"}
extra context the logging interface looks like this:
package wasi:[email protected] {
interface logging {
enum level {
trace,
debug,
info,
warn,
error,
critical,
}
log: func(level: level, context: string, message: string);
}
}
Ignore my comment, I was looking at the wrong problem! It works like a charm!
require Logger
Wasmex.Components.start_link(%{
path: wasm,
wasi: %Wasmex.Wasi.WasiP2Options{},
imports: %{
"wasi:logging/[email protected]" => %{
"log" => {:fn, fn level, _context, message -> Logger.log(level, message) end}
}
}
})
closing this - the discussion about removing automatic field naming is continued in #852