The wit-bindgen project officially provided by WebAssembly can enable better interaction between the wasm module and the runtime, avoiding the development of various data conversion logics, and now Layotto integrates wasmtime, so we want to integrate wit-bindgen to improve the user's ability to develop wasm modules experience.
2. What I have tried
define a wit file:
record person {
name: string,
age: u32,
}
test: func(who: person) -> string
2. develop user module
use hello::*;
wit_bindgen_rust::import!("wit/hello.wit");
fn main() {
let p = Person{name:"gj", age: 18};
let result = test(p);
print!("result: {}", result);
}
In this way, the test function can be implemented, but how to register this implementation with wasmtime and provide services to users has not yet been found.
# 3. what need to do
1. Learn how to integrate wit-bindgen with wasmtime
2. Learn how to integrate wit-bindgen with wasmtime-go
References:
1. https://github.com/bytecodealliance/wit-bindgen
5. https://github.com/fermyon/spin
6. discussion:#611
### 中文
# 一、背景
WebAssembly 官方提供的 wit-bindgen 项目可以让 wasm 模块跟运行时之间更好的交互,避免开发各种数据转换逻辑,现在Layotto集成了wasmtime,因此想要集成wit-bindgen来提高用户开发wasm模块的体验。
# 二、做过的一些尝试
1. 自定义一个wit文件:
record person {
name: string,
age: u32,
}
test: func(who: person) -> string
2. 用户开发时使用
use hello::*;
wit_bindgen_rust::import!("wit/hello.wit");
fn main() {
let p = Person{name:"gj", age: 18};
let result = test(p);
print!("result: {}", result);
}
1. Background
The wit-bindgen project officially provided by WebAssembly can enable better interaction between the wasm module and the runtime, avoiding the development of various data conversion logics, and now Layotto integrates wasmtime, so we want to integrate wit-bindgen to improve the user's ability to develop wasm modules experience.
2. What I have tried
test: func(who: person) -> string
use hello::*;
wit_bindgen_rust::import!("wit/hello.wit");
fn main() { let p = Person{name:"gj", age: 18}; let result = test(p); print!("result: {}", result); }
use hello::*;
wit_bindgen_rust::export!("/Users/gujin/workspace/rust/hello-wasmtime/wit/hello.wit");
struct Hello {}
impl hello::Hello for Hello { fn test(p: Person) -> String { return p.name; } }
//register to wasmtime
record person { name: string, age: u32, }
test: func(who: person) -> string
use hello::*;
wit_bindgen_rust::import!("wit/hello.wit");
fn main() { let p = Person{name:"gj", age: 18}; let result = test(p); print!("result: {}", result); }
use hello::*;
wit_bindgen_rust::export!("/Users/gujin/workspace/rust/hello-wasmtime/wit/hello.wit");
struct Hello {}
impl hello::Hello for Hello { fn test(p: Person) -> String { return p.name; } }
//把实现注册到wasmtime