generate wrpc-server based on wit-bindings and homogenize the wrpc-client and wasmtime-bindings
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Necesita aclaración
- Estado de actividad
- Tranquilo
- Stack tecnológico
- rust, wasm
Línea de trabajo
Comienza con los bloques de generación de client_bindings, server_bindings y host_bindings del ejemplo y con las definiciones de interfaces de ../wit. Compara las APIs de cliente y servidor de wrpc generadas con los bindings de wasmtime y, después, define el cambio mínimo en la macro o en la generación que pueda crear un servidor a partir de los bindings de WIT. Se considerará completado cuando haya menos boilerplate y una interfaz de bindings de cliente/servidor consistente, y el ejemplo siga admitiendo los modos local, client y server.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Did a quick experiment to build an isomorphic wasm component that could be used locally or run remotely on a cluster. As I understand wrpc uses the same interface description but has a completely different binary serialization, and because of that the API's between wit-bindgen and wrpc-bindgen are completely different. However if the below example could be made less boilerplatte heavy (by creating a macro that implements a wrpc server based on the wit bindings) it would be cool. I can also imagine extending it to frontend components which export their html as a string. This way the component could be run server side for indexing or client side with a webview or wrapped into a browser module with jco.
use anyhow::Result;
use clap::Parser;
use std::net::SocketAddr;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use wasi_hw_native::WasmCtx;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum Mode {
Local,
Client,
Server,
}
impl std::str::FromStr for Mode {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self> {
Ok(match s {
"local" => Mode::Local,
"client" => Mode::Client,
"server" => Mode::Server,
_ => anyhow::bail!("invalid mode {s}"),
})
}
}
#[derive(Parser)]
struct Opts {
#[arg(short, long, default_value = "local")]
mode: Mode,
#[arg(
short,
long,
default_value = "../target/wasm32-wasip2/release/wasi_hw.wasm"
)]
file: PathBuf,
#[arg(short, long, default_value = "127.0.0.1:8080")]
address: String,
}
mod client_bindings {
wit_bindgen_wrpc::generate!({
world: "hello-world-consumer",
path: "../wit",
});
}
mod server_bindings {
wit_bindgen_wrpc::generate!({
world: "hello-world-provider",
path: "../wit",
});
}
mod host_bindings {
wasmtime::component::bindgen!({
world: "hello-world-provider",
path: "../wit",
});
}
pub struct CustomWasmCtx {
ctx: WasmCtx,
}
impl CustomWasmCtx {
pub fn new(path: &Path) -> Result<Self> {
Ok(Self {
ctx: WasmCtx::new(path)?,
})
}
pub async fn local_hello_hello_world_call_hello_world(&self) -> Result<String> {
let (mut store, instance) = self.ctx.instantiate().await?;
let bindings = host_bindings::HelloWorldProvider::new(&mut store, &instance)?;
let result = store
.run_concurrent(async |accessor| {
bindings
.local_hello_hello_world()
.call_hello_world(accessor)
.await
})
.await??;
Ok(result)
}
}
#[derive(Clone)]
struct Server {
ctx: Arc<CustomWasmCtx>,
}
impl Server {
pub fn new(ctx: CustomWasmCtx) -> Self {
Self { ctx: Arc::new(ctx) }
}
}
impl server_bindings::exports::local::hello::hello_world::Handler<SocketAddr> for Server {
async fn hello_world(&self, _ctx: SocketAddr) -> anyhow::Result<String> {
self.ctx.local_hello_hello_world_call_hello_world().await
}
}
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt::init();
let opts = Opts::parse();
if opts.mode == Mode::Client {
let transport = wrpc_transport::tcp::Client::from(opts.address);
let result =
client_bindings::local::hello::hello_world::hello_world(&transport, ()).await?;
println!("result: {}", result);
return Ok(());
}
let ctx = CustomWasmCtx::new(&opts.file)?;
if opts.mode == Mode::Local {
let result = ctx.local_hello_hello_world_call_hello_world().await?;
println!("result: {}", result);
return Ok(());
}
let server = Server::new(ctx);
let transport = Arc::new(wrpc_transport::Server::default());
let accept = wasi_hw_native::tcp_server(&opts.address, transport.clone()).await?;
let invocation = server_bindings::serve(transport.as_ref(), server).await?;
wasi_hw_native::wrpc_server(accept, invocation).await?;
Ok(())
}
- Lenguaje dominante
- Rust
- Estrellas
- 336
- Forks
- 48
- Merge medio
- 10 h 39 min
- PR fusionados (30 d)
- 203
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de bytecodealliance/wrpc
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
bytecodealliance/wrpc#1785 ·
Los mantenedores suelen responder en 1 día
-
Support WebRTC transportAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
bytecodealliance/wrpc#1701 ·
Los mantenedores suelen responder en 1 día
-
add map supportAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
bytecodealliance/wrpc#1151 ·
Los mantenedores suelen responder en 1 día
-
[go] Allow user-defined LoggerAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 30/100
bytecodealliance/wrpc#531 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
wRPC protocol v0.1.0Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
bytecodealliance/wrpc#494 · 2 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
Todos los issues de bytecodealliance/wrpc
Issues similares
-
2 advisory ignore entries no longer match anything (`quick-xml` already patched in `Cargo.lock`)Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
longbridge/nsh#2758 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
antithesishq/bombadil#473 ·
Los mantenedores suelen responder en 2 días
-
bench/api.sh exec test fails with curl exit 52, and --ignore-failure still records the timingsAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
libracoder/kiri#669 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
nowledge-co/hawdb#1881 ·
Los mantenedores suelen responder en 1 día