Support parsing the text format in wasmtime crate (#813)
* Support parsing the text format in `wasmtime` crate This commit adds support to the `wasmtime::Module` type to parse the text format. This is often quite convenient to support in testing or tinkering with the runtime. Additionally the `wat` parser is pretty lightweight and easy to add to builds, so it's relatively easy for us to support as well! The exact manner that this is now supported comes with a few updates to the existing API: * A new optional feature of the `wasmtime` crate, `wat`, has been added. This is enabled by default. * The `Module::new` API now takes `impl AsRef<[u8]>` instead of just `&[u8]`, and when the `wat` feature is enabled it will attempt to interpret it either as a wasm binary or as the text format. Note that this check is quite cheap since you just check the first byte. * A `Module::from_file` API was added as a convenience to parse a file from disk, allowing error messages for `*.wat` files on disk to be a bit nicer. * APIs like `Module::new_unchecked` and `Module::validate` remain unchanged, they require the binary format to be called. The intention here is to make this as convenient as possible for new developers of the `wasmtime` crate. By changing the default behavior though this has ramifications such as, for example, supporting the text format implicitly through the C API now. * Handle review comments * Update more tests to avoid usage of `wat` crate * Go back to unchecked for now in wasm_module_new Looks like C# tests rely on this?
This commit is contained in:
@@ -107,8 +107,7 @@ mod tests {
|
||||
fn test_custom_signal_handler_single_instance() -> Result<()> {
|
||||
let engine = Engine::new(&Config::default());
|
||||
let store = Store::new(&engine);
|
||||
let data = wat::parse_str(WAT1)?;
|
||||
let module = Module::new(&store, &data)?;
|
||||
let module = Module::new(&store, WAT1)?;
|
||||
let instance = Instance::new(&module, &[])?;
|
||||
|
||||
let (base, length) = set_up_memory(&instance);
|
||||
@@ -166,8 +165,7 @@ mod tests {
|
||||
fn test_custom_signal_handler_multiple_instances() -> Result<()> {
|
||||
let engine = Engine::new(&Config::default());
|
||||
let store = Store::new(&engine);
|
||||
let data = wat::parse_str(WAT1)?;
|
||||
let module = Module::new(&store, &data)?;
|
||||
let module = Module::new(&store, WAT1)?;
|
||||
|
||||
// Set up multiple instances
|
||||
|
||||
@@ -261,8 +259,7 @@ mod tests {
|
||||
let store = Store::new(&engine);
|
||||
|
||||
// instance1 which defines 'read'
|
||||
let data1 = wat::parse_str(WAT1)?;
|
||||
let module1 = Module::new(&store, &data1)?;
|
||||
let module1 = Module::new(&store, WAT1)?;
|
||||
let instance1 = Instance::new(&module1, &[])?;
|
||||
let (base1, length1) = set_up_memory(&instance1);
|
||||
unsafe {
|
||||
@@ -277,8 +274,7 @@ mod tests {
|
||||
let instance1_read = instance1_exports[0].clone();
|
||||
|
||||
// instance2 wich calls 'instance1.read'
|
||||
let data2 = wat::parse_str(WAT2)?;
|
||||
let module2 = Module::new(&store, &data2)?;
|
||||
let module2 = Module::new(&store, WAT2)?;
|
||||
let instance2 = Instance::new(&module2, &[instance1_read])?;
|
||||
// since 'instance2.run' calls 'instance1.read' we need to set up the signal handler to handle
|
||||
// SIGSEGV originating from within the memory of instance1
|
||||
|
||||
Reference in New Issue
Block a user