diff --git a/Cargo.lock b/Cargo.lock index aa802a7..2de23dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -673,6 +673,13 @@ dependencies = [ "smallvec", ] +[[package]] +name = "runner" +version = "0.1.0" +dependencies = [ + "wasmtime", +] + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -1157,13 +1164,6 @@ version = "20.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca6585868f5c427c3e9d2a8c0c3354e6d7d4518a0d17723ab25a0c1eebf5d5b4" -[[package]] -name = "wasmtime-test" -version = "0.1.0" -dependencies = [ - "wasmtime", -] - [[package]] name = "wasmtime-types" version = "20.0.2" diff --git a/Cargo.toml b/Cargo.toml index fdd1335..6256c73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] - members = [ "component", "runner", ] +resolver = "2" \ No newline at end of file diff --git a/component/src/lib.rs b/component/src/lib.rs index e7ab24c..97b2b54 100644 --- a/component/src/lib.rs +++ b/component/src/lib.rs @@ -2,12 +2,13 @@ mod bindings; use bindings::{hello, Guest}; +use crate::bindings::RecordString; struct Component; impl Guest for Component { - fn greet() { - hello(); + fn greet(hello_string: RecordString) { + hello(&hello_string); } } diff --git a/component/wit/test.wit b/component/wit/test.wit index 2d27e52..6bbb02f 100644 --- a/component/wit/test.wit +++ b/component/wit/test.wit @@ -1,6 +1,10 @@ package my:project; world test { - import hello: func(); - export greet: func(); + record record-string { + hello-string: string, + } + + import hello: func(hello-string: record-string); + export greet: func(hello-string: record-string); } \ No newline at end of file diff --git a/runner/Cargo.toml b/runner/Cargo.toml index 415d4ab..b522dfd 100644 --- a/runner/Cargo.toml +++ b/runner/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "wasmtime-test" +name = "runner" version = "0.1.0" edition = "2021" diff --git a/runner/src/main.rs b/runner/src/main.rs index a0f9428..a1bb827 100644 --- a/runner/src/main.rs +++ b/runner/src/main.rs @@ -12,8 +12,8 @@ struct TestState { } impl TestImports for TestState { - fn hello(&mut self) -> std::result::Result<(), wasmtime::Error> { - println!("{}", self.name); + fn hello(&mut self, hello_string: RecordString) -> std::result::Result<(), wasmtime::Error> { + println!("{} - {}", self.name, hello_string.hello_string); Ok(()) } } @@ -22,7 +22,7 @@ fn main() -> wasmtime::Result<()> { let mut config = Config::new(); config.wasm_component_model(true); let engine = Engine::new(&config)?; - let component = Component::from_file(&engine, "target/wasm32-wasi/release/component.wasm")?; + let component = Component::from_file(&engine, "target/wasm32-wasip1/release/component.wasm")?; let mut linker = Linker::new(&engine); Test::add_to_linker(&mut linker, |state: &mut TestState| state)?; let mut store = Store::new( @@ -32,6 +32,6 @@ fn main() -> wasmtime::Result<()> { }, ); let (bindings, _) = Test::instantiate(&mut store, &component, &linker)?; - bindings.call_greet(&mut store)?; + bindings.call_greet(&mut store, &RecordString { hello_string: "Hello".to_owned() })?; Ok(()) } diff --git a/runner/wit/test.wit b/runner/wit/test.wit index 2d27e52..6bbb02f 100644 --- a/runner/wit/test.wit +++ b/runner/wit/test.wit @@ -1,6 +1,10 @@ package my:project; world test { - import hello: func(); - export greet: func(); + record record-string { + hello-string: string, + } + + import hello: func(hello-string: record-string); + export greet: func(hello-string: record-string); } \ No newline at end of file