Skip to content

Add memory64 support to the Wasmtime CLI and C API #3182

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

Merged
merged 1 commit into from
Aug 12, 2021
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
8 changes: 8 additions & 0 deletions crates/c-api/include/wasmtime/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ WASMTIME_CONFIG_PROP(void, wasm_multi_memory, bool)
*/
WASMTIME_CONFIG_PROP(void, wasm_module_linking, bool)

/**
* \brief Configures whether the WebAssembly memory64 proposal is
* enabled.
*
* This setting is `false` by default.
*/
WASMTIME_CONFIG_PROP(void, wasm_memory64, bool)

/**
* \brief Configures how JIT code will be compiled.
*
Expand Down
5 changes: 5 additions & 0 deletions crates/c-api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ pub extern "C" fn wasmtime_config_wasm_module_linking_set(c: &mut wasm_config_t,
c.config.wasm_module_linking(enable);
}

#[no_mangle]
pub extern "C" fn wasmtime_config_wasm_memory64_set(c: &mut wasm_config_t, enable: bool) {
c.config.wasm_memory64(enable);
}

#[no_mangle]
pub extern "C" fn wasmtime_config_strategy_set(
c: &mut wasm_config_t,
Expand Down
2 changes: 2 additions & 0 deletions docs/stability-wasm-proposals-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ vetted](./contributing-implementing-wasm-proposals.html).
| **[Threads and Atomics]** | **In progress.** | `--enable-threads` | [`wasm_threads`](https://docs.rs/wasmtime/*/wasmtime/struct.Config.html#method.wasm_threads) |
| **[Multi-Memory]** | **Yes.** | `--enable-multi-memory`| [`wasm_multi_memory`](https://docs.rs/wasmtime/*/wasmtime/struct.Config.html#method.wasm_multi_memory) |
| **[Module Linking]** | **Yes.** | `--enable-module-linking` | [`wasm_module_linking`](https://docs.rs/wasmtime/*/wasmtime/struct.Config.html#method.wasm_module_linking) |
| **[Memory64]** | **Yes.** | `--enable-memory64` | [`wasm_memory64`](https://docs.rs/wasmtime/*/wasmtime/struct.Config.html#method.wasm_memory64) |

[config]: https://docs.rs/wasmtime/*/wasmtime/struct.Config.html
[Multi-Value]: https://github.com/WebAssembly/spec/blob/master/proposals/multi-value/Overview.md
Expand All @@ -36,3 +37,4 @@ vetted](./contributing-implementing-wasm-proposals.html).
[Threads and Atomics]: https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md
[Multi-Memory]: https://github.com/WebAssembly/multi-memory/blob/master/proposals/multi-memory/Overview.md
[Module Linking]: https://github.com/WebAssembly/module-linking/blob/master/proposals/module-linking/Explainer.md
[Memory64]: https://github.com/WebAssembly/memory64/blob/master/proposals/memory64/Overview.md
10 changes: 6 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const SUPPORTED_WASM_FEATURES: &[(&str, &str)] = &[
("reference-types", "enables support for reference types"),
("simd", "enables support for proposed SIMD instructions"),
("threads", "enables support for WebAssembly threads"),
("memory64", "enables support for 64-bit memories"),
];

const SUPPORTED_WASI_MODULES: &[(&str, &str)] = &[
Expand Down Expand Up @@ -437,7 +438,7 @@ fn parse_wasm_features(features: &str) -> Result<wasmparser::WasmFeatures> {
deterministic_only: false,
multi_memory: all.unwrap_or(values["multi-memory"].unwrap_or(false)),
exceptions: false,
memory64: false,
memory64: all.unwrap_or(values["memory64"].unwrap_or(false)),
})
}

Expand Down Expand Up @@ -561,7 +562,7 @@ mod test {
assert!(!deterministic_only); // Not supported
assert!(multi_memory);
assert!(!exceptions); // Not supported
assert!(!memory64); // Not supported
assert!(memory64);

Ok(())
}
Expand Down Expand Up @@ -603,7 +604,7 @@ mod test {
fn test_multiple_features() -> Result<()> {
let options = CommonOptions::from_iter_safe(vec![
"foo",
"--wasm-features=-reference-types,simd,multi-memory",
"--wasm-features=-reference-types,simd,multi-memory,memory64",
])?;

let wasmparser::WasmFeatures {
Expand All @@ -630,7 +631,7 @@ mod test {
assert!(!deterministic_only); // Not supported
assert!(multi_memory);
assert!(!exceptions); // Not supported
assert!(!memory64); // Not supported
assert!(memory64);

Ok(())
}
Expand Down Expand Up @@ -675,6 +676,7 @@ mod test {
feature_test!(test_simd_feature, simd, "simd");
feature_test!(test_threads_feature, threads, "threads");
feature_test!(test_multi_memory_feature, multi_memory, "multi-memory");
feature_test!(test_memory64_feature, memory64, "memory64");

#[test]
fn test_default_modules() {
Expand Down