0.3.0
Notable Changes
This release features support for elixir function that can be exported to WASM.
It also supports the latest wasmer v 1.0 🎉.
Wasmer 1.0 is a partial rewrite of the WASM engine we use that promises to be up to 9 times faster module compilation.
Added
- added the instances first memory into the callback context
imports = %{
env: %{
read_and_set_memory:
{:fn, [], [:i32],
fn context, a, b, c ->
memory = Map.get(context, :memory)
42 = Wasmex.Memory.get(memory, :uint8, 0, 0) # assert that the first byte in the memory was set to 42
Wasmex.Memory.set(memory, :uint8, 0, 0, 23)
0
end},
}
}
instance = start_supervised!({Wasmex, %{bytes: @import_test_bytes, imports: imports}})
Wasmex.Memory.set(memory, :uint8, 0, 0, 42)
# asserts that the byte at memory[0] was set to 42 and then sets it to 23
{:ok, _} = Wasmex.call_function(instance, :a_wasm_fn_that_calls_read_and_set_memory, [])
assert 23 == Wasmex.Memory.get(memory, :uint8, 0, 0)
- added support for function imports
imports = %{
env: %{
sum3: {:fn, [:i32, :i32, :i32], [:i32], fn (_context, a, b, c) -> a + b + c end},
}
}
instance = start_supervised!({Wasmex, %{bytes: @import_test_bytes, imports: imports}})
{:ok, [6]} = Wasmex.call_function(instance, "use_the_imported_sum_fn", [1, 2, 3])
Thanks to
- @bamorim for helping me plan and architect,
- @myobie for help in implementation, especially for implementing the function signature checks,
- @rylev for a second eye on our Rust code,
- the @wasmerio team for the recent addition of
DynFunc
which made this feature possible, and - @bitcrowd for sponsoring me to work on this feature
Changed
- Changed writing and reading strings from/to memory to be based on string length and not expect null-byte terminated strings.
This allows for a more flexible memory handling when writing arbitrary data or strings containing null bytes to/from memory.
Thanks @myobie for implementing this feature - Support writing non-string binaries to memory. Before we could only write valid UTF-8 strings to WASM memory.
Thanks again, @myobie, for implementing this feature - Updated the wasmer version, now supporting wasmer 1.0.
- Updated to elixir 1.11 and Erlang OTP 23.2. Older versions might work, but are not officially tested
Fixed
could not convert callback result param to expected return signature
error for a void callback.