* Add trampoline compilation support for lowered imports This commit adds support to the component model implementation for compiling trampolines suitable for calling host imports. Currently this is purely just the compilation side of things, modifying the wasmtime-cranelift crate and additionally filling out a new `VMComponentOffsets` type (similar to `VMOffsets`). The actual creation of a `VMComponentContext` is still not performed and will be a subsequent PR. Internally though some tests are actually possible with this where we at least assert that compilation of a component and creation of everything in-memory doesn't panic or trip any assertions, so some tests are added here for that as well. * Fix some test errors
72 lines
1.9 KiB
Rust
72 lines
1.9 KiB
Rust
use anyhow::Result;
|
|
use wasmtime::component::Component;
|
|
use wasmtime::{Config, Engine};
|
|
|
|
mod func;
|
|
mod import;
|
|
|
|
fn engine() -> Engine {
|
|
let mut config = Config::new();
|
|
config.wasm_component_model(true);
|
|
Engine::new(&config).unwrap()
|
|
}
|
|
|
|
#[test]
|
|
fn components_importing_modules() -> Result<()> {
|
|
let engine = engine();
|
|
|
|
// FIXME: these components should actually get instantiated in `*.wast`
|
|
// tests once supplying imports has actually been implemented.
|
|
|
|
Component::new(
|
|
&engine,
|
|
r#"
|
|
(component
|
|
(import "" (module))
|
|
)
|
|
"#,
|
|
)?;
|
|
|
|
Component::new(
|
|
&engine,
|
|
r#"
|
|
(component
|
|
(import "" (module $m1
|
|
(import "" "" (func))
|
|
(import "" "x" (global i32))
|
|
|
|
(export "a" (table 1 funcref))
|
|
(export "b" (memory 1))
|
|
(export "c" (func (result f32)))
|
|
(export "d" (global i64))
|
|
))
|
|
|
|
(module $m2
|
|
(func (export ""))
|
|
(global (export "x") i32 i32.const 0)
|
|
)
|
|
(instance $i2 (instantiate (module $m2)))
|
|
(instance $i1 (instantiate (module $m1) (with "" (instance $i2))))
|
|
|
|
(module $m3
|
|
(import "mod" "1" (memory 1))
|
|
(import "mod" "2" (table 1 funcref))
|
|
(import "mod" "3" (global i64))
|
|
(import "mod" "4" (func (result f32)))
|
|
)
|
|
|
|
(instance $i3 (instantiate (module $m3)
|
|
(with "mod" (instance
|
|
(export "1" (memory $i1 "b"))
|
|
(export "2" (table $i1 "a"))
|
|
(export "3" (global $i1 "d"))
|
|
(export "4" (func $i1 "c"))
|
|
))
|
|
))
|
|
)
|
|
"#,
|
|
)?;
|
|
|
|
Ok(())
|
|
}
|