From f26c19df4eb133506402861cbfb44d0b628cd4d5 Mon Sep 17 00:00:00 2001 From: csh <458761603@qq.com> Date: Tue, 23 Apr 2024 01:34:05 +0800 Subject: [PATCH 1/2] Update Cargo.toml Signed-off-by: csh <458761603@qq.com> --- .cargo/config.toml | 3 +++ Cargo.toml | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..c20090b --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,3 @@ +[build] +target = "wasm32-wasi" +rustflags = ["--cfg", "wasmedge", "--cfg", "tokio_unstable"] diff --git a/Cargo.toml b/Cargo.toml index c377595..049edb5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,11 +3,18 @@ name = "order_demo_service" version = "0.1.0" edition = "2021" +[patch.crates-io] +tokio = { git = "https://github.com/second-state/wasi_tokio.git", branch = "v1.36.x" } +socket2 = { git = "https://github.com/second-state/socket2.git", branch = "v0.5.x" } +hyper = { git = "https://github.com/second-state/wasi_hyper.git", branch = "v0.14.x" } + [dependencies] anyhow = "1.0" serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } url = "2.3" -mysql_async_wasi = "=0.31.5" -hyper_wasi = { version = "0.15", features = ["full"] } -tokio_wasi = { version = "1", features = ["io-util", "fs", "net", "time", "rt", "macros"] } \ No newline at end of file + +mysql_async = { version = "0.34", default-features=false, features = [ "default-rustls" ], git="https://github.com/blackbeam/mysql_async.git" } +zstd-sys = "=2.0.9" +hyper = { version = "0.14", features = ["full"] } +tokio = { version = "1", features = ["io-util", "fs", "net", "time", "rt", "macros"] } From c22bfe3c24e4ef7d1ab831833016a75fd65cbce3 Mon Sep 17 00:00:00 2001 From: csh <458761603@qq.com> Date: Mon, 29 Apr 2024 16:36:27 +0800 Subject: [PATCH 2/2] Fix Server::bind error Signed-off-by: csh <458761603@qq.com> --- src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 309a329..db6e16d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -225,6 +225,7 @@ async fn main() -> Result<(), Box> { let pool = Pool::new(builder.pool_opts(pool_opts)); let addr = SocketAddr::from(([0, 0, 0, 0], 8080)); + let tcp_listener = tokio::net::TcpListener::bind(addr).await.unwrap(); let make_svc = make_service_fn(|_| { let pool = pool.clone(); async move { @@ -234,7 +235,7 @@ async fn main() -> Result<(), Box> { })) } }); - let server = Server::bind(&addr).serve(make_svc); + let server = Server::from_tcp(tcp_listener.into_std().unwrap()).unwrap().serve(make_svc); if let Err(e) = server.await { eprintln!("server error: {}", e); }