Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for wasmtime's underlying memory64 implementation #621

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions lib/wasmex/engine_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ defmodule Wasmex.EngineConfig do

defstruct consume_fuel: false,
cranelift_opt_level: :none,
wasm_backtrace_details: false
wasm_backtrace_details: false,
memory64: false

@type t :: %__MODULE__{
consume_fuel: boolean(),
cranelift_opt_level: :none | :speed | :speed_and_size,
wasm_backtrace_details: boolean()
wasm_backtrace_details: boolean(),
memory64: boolean()
}

@doc ~S"""
Expand All @@ -50,6 +52,21 @@ defmodule Wasmex.EngineConfig do
%__MODULE__{config | consume_fuel: consume_fuel}
end

@doc ~S"""
Configures whether the WebAssembly memory type is 64-bit.

## Example

iex> config = %Wasmex.EngineConfig{}
...> |> Wasmex.EngineConfig.memory64(true)
iex> config.memory64
true
"""
@spec memory64(t(), boolean()) :: t()
def memory64(%__MODULE__{} = config, memory64) do
%__MODULE__{config | memory64: memory64}
end

@doc """
Configures the Cranelift code generator optimization level.

Expand Down
2 changes: 2 additions & 0 deletions native/wasmex/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct ExEngineConfig {
consume_fuel: bool,
wasm_backtrace_details: bool,
cranelift_opt_level: rustler::Atom,
memory64: bool,
}

#[rustler::resource_impl()]
Expand Down Expand Up @@ -66,6 +67,7 @@ pub(crate) fn engine_config(engine_config: ExEngineConfig) -> Config {
config.consume_fuel(engine_config.consume_fuel);
config.wasm_backtrace_details(backtrace_details);
config.cranelift_opt_level(cranelift_opt_level);
config.wasm_memory64(engine_config.memory64);
config
}

Expand Down
8 changes: 8 additions & 0 deletions test/wasmex/engine_config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ defmodule Wasmex.EngineConfigTest do
assert %{wasm_backtrace_details: true} = EngineConfig.wasm_backtrace_details(config, true)
end
end

describe t(&EngineConfig.memory64/1) do
test "sets the memory64 option" do
config = %EngineConfig{}
assert %{memory64: false} = EngineConfig.memory64(config, false)
assert %{memory64: true} = EngineConfig.memory64(config, true)
end
end
end
1 change: 1 addition & 0 deletions test/wasmex/engine_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ defmodule Wasmex.EngineTest do
%EngineConfig{}
|> EngineConfig.consume_fuel(true)
|> EngineConfig.cranelift_opt_level(:speed)
|> EngineConfig.memory64(true)
|> Engine.new()
end
end
Expand Down