Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate with wit-bindgen; 集成wit-bindgen #843

Open
zhenjunMa opened this issue Nov 16, 2022 · 1 comment
Open

Integrate with wit-bindgen; 集成wit-bindgen #843

zhenjunMa opened this issue Nov 16, 2022 · 1 comment
Labels
area/community help wanted Extra attention is needed wasm WebAssembly technology

Comments

@zhenjunMa
Copy link
Contributor

zhenjunMa commented Nov 16, 2022

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

  1. define a wit file:
record person {
  name: string,
  age: u32,
}

test: func(who: person) -> string
  1. 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);
}
  1. add implementation in wasmtime
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

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
  2. https://github.com/fermyon/spin
  3. discussion:Update the api for wasm functions; 设计 FaaS 编程 API #611

中文

一、背景

WebAssembly 官方提供的 wit-bindgen 项目可以让 wasm 模块跟运行时之间更好的交互,避免开发各种数据转换逻辑,现在Layotto集成了wasmtime,因此想要集成wit-bindgen来提高用户开发wasm模块的体验。

二、做过的一些尝试

  1. 自定义一个wit文件:
record person {
  name: string,
  age: u32,
}

test: func(who: person) -> string
  1. 用户开发时使用
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. 运行时提供具体实现
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

这样可以实现test接口,但是如何把该实现注册到wasmtime,对用户提供服务还没有找到办法。

三、需要做什么

  1. 调研用wasmtime集成wit-bindgen的方法
  2. 调研用wasmtime-go集成wit-bindgen的方法

参考资料:

  1. https://github.com/bytecodealliance/wit-bindgen
  2. https://github.com/fermyon/spin
  3. 之前的讨论:Update the api for wasm functions; 设计 FaaS 编程 API #611
@zhenjunMa zhenjunMa added help wanted Extra attention is needed wasm WebAssembly technology area/community labels Nov 16, 2022
@zu1k
Copy link
Member

zu1k commented Nov 17, 2022

https://radu-matei.com/blog/wasm-components-host-implementations/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/community help wanted Extra attention is needed wasm WebAssembly technology
Projects
None yet
Development

No branches or pull requests

2 participants