This commit adds lots of plumbing to get the type section from the module linking proposal plumbed all the way through to the `wasmtime` crate and the `wasmtime-c-api` crate. This isn't all that useful right now because Wasmtime doesn't support imported/exported modules/instances, but this is all necessary groundwork to getting that exported at some point. I've added some light tests but I suspect the bulk of the testing will come in a future commit. One major change in this commit is that `SignatureIndex` no longer follows type type index space in a wasm module. Instead a new `TypeIndex` type is used to track that. Function signatures, still indexed by `SignatureIndex`, are then packed together tightly.
55 lines
1.3 KiB
Rust
55 lines
1.3 KiB
Rust
use anyhow::Result;
|
|
use wasmtime::*;
|
|
|
|
fn engine() -> Engine {
|
|
let mut config = Config::new();
|
|
config.wasm_module_linking(true);
|
|
Engine::new(&config)
|
|
}
|
|
|
|
#[test]
|
|
fn compile() -> Result<()> {
|
|
let engine = engine();
|
|
Module::new(&engine, "(module (module))")?;
|
|
Module::new(&engine, "(module (module) (module))")?;
|
|
Module::new(&engine, "(module (module (module)))")?;
|
|
Module::new(
|
|
&engine,
|
|
"
|
|
(module
|
|
(func)
|
|
(module (func))
|
|
(module (func))
|
|
)
|
|
",
|
|
)?;
|
|
let m = Module::new(
|
|
&engine,
|
|
"
|
|
(module
|
|
(global i32 (i32.const 0))
|
|
(func)
|
|
(module (memory 1) (func))
|
|
(module (memory 2) (func))
|
|
(module (table 2 funcref) (func))
|
|
(module (global i64 (i64.const 0)) (func))
|
|
)
|
|
",
|
|
)?;
|
|
assert_eq!(m.imports().len(), 0);
|
|
assert_eq!(m.exports().len(), 0);
|
|
let bytes = m.serialize()?;
|
|
Module::deserialize(&engine, &bytes)?;
|
|
assert_eq!(m.imports().len(), 0);
|
|
assert_eq!(m.exports().len(), 0);
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn types() -> Result<()> {
|
|
let engine = engine();
|
|
Module::new(&engine, "(module (type (module)))")?;
|
|
Module::new(&engine, "(module (type (instance)))")?;
|
|
Ok(())
|
|
}
|