From 439f125e913027b013bbd48174656c91179baff3 Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Fri, 6 Sep 2024 11:07:23 +0200 Subject: [PATCH] Make all CLIs async using tokio (#601) Fixes #600 --- crates/cli-tools/CHANGELOG.md | 4 +- crates/cli-tools/Cargo.lock | 11 + crates/cli-tools/Cargo.toml | 5 + crates/cli-tools/src/action.rs | 66 +++--- crates/cli-tools/src/cmd.rs | 25 +-- crates/cli-tools/src/fs.rs | 111 +++++----- crates/cli-tools/src/lib.rs | 1 + crates/cli/CHANGELOG.md | 2 +- crates/cli/Cargo.lock | 11 + crates/cli/Cargo.toml | 2 +- crates/cli/src/main.rs | 12 +- crates/protocol-tokio/CHANGELOG.md | 2 +- crates/protocol-tokio/Cargo.toml | 2 +- crates/protocol/crates/schema/Cargo.lock | 79 +++++++ crates/protocol/crates/schema/Cargo.toml | 1 + crates/protocol/crates/schema/src/main.rs | 23 ++- crates/runner-host/Cargo.lock | 123 +++-------- crates/runner-host/Cargo.toml | 2 +- .../runner-host/crates/web-server/Cargo.lock | 118 ++--------- .../runner-host/crates/web-server/Cargo.toml | 2 +- crates/runner-host/src/main.rs | 4 +- crates/xtask/Cargo.lock | 20 +- crates/xtask/Cargo.toml | 2 +- crates/xtask/src/footprint.rs | 32 +-- crates/xtask/src/main.rs | 192 ++++++++++-------- crates/xtask/src/textreview.rs | 6 +- examples/rust/protocol/host/Cargo.toml | 2 +- 27 files changed, 424 insertions(+), 436 deletions(-) diff --git a/crates/cli-tools/CHANGELOG.md b/crates/cli-tools/CHANGELOG.md index 58069e6d..4e06dd9d 100644 --- a/crates/cli-tools/CHANGELOG.md +++ b/crates/cli-tools/CHANGELOG.md @@ -4,7 +4,7 @@ ### Major -- Change all actions requiring a connection to use async +- Change API to be async using tokio ### Minor @@ -18,4 +18,4 @@ ## 0.1.0 - + diff --git a/crates/cli-tools/Cargo.lock b/crates/cli-tools/Cargo.lock index 5eefc4af..02d3baf3 100644 --- a/crates/cli-tools/Cargo.lock +++ b/crates/cli-tools/Cargo.lock @@ -382,6 +382,15 @@ dependencies = [ "serde", ] +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + [[package]] name = "socket2" version = "0.5.7" @@ -434,6 +443,7 @@ dependencies = [ "libc", "mio", "pin-project-lite", + "signal-hook-registry", "socket2", "tokio-macros", "windows-sys", @@ -517,6 +527,7 @@ dependencies = [ "humantime", "rusb", "serde", + "tokio", "toml", "wasefire-protocol", "wasefire-protocol-tokio", diff --git a/crates/cli-tools/Cargo.toml b/crates/cli-tools/Cargo.toml index bbfb4d91..abfd27c5 100644 --- a/crates/cli-tools/Cargo.toml +++ b/crates/cli-tools/Cargo.toml @@ -23,6 +23,11 @@ toml = { version = "0.8.13", default-features = false, features = ["display", "p wasefire-protocol = { version = "0.1.1-git", path = "../protocol", features = ["host"] } wasefire-wire = { version = "0.1.1-git", path = "../wire" } +[dependencies.tokio] +version = "1.40.0" +default-features = false +features = ["fs", "io-std", "process", "rt"] + [dependencies.wasefire-protocol-tokio] version = "0.1.0-git" path = "../protocol-tokio" diff --git a/crates/cli-tools/src/action.rs b/crates/cli-tools/src/action.rs index 72ccf3d0..39e2a3d9 100644 --- a/crates/cli-tools/src/action.rs +++ b/crates/cli-tools/src/action.rs @@ -14,12 +14,12 @@ use std::fmt::Display; use std::path::{Path, PathBuf}; -use std::process::Command; use anyhow::{bail, ensure, Result}; use cargo_metadata::{Metadata, MetadataCommand}; use clap::{ValueEnum, ValueHint}; use rusb::GlobalContext; +use tokio::process::Command; use wasefire_protocol::{self as service, applet, Api, Connection, ConnectionExt}; use crate::{cmd, fs}; @@ -65,17 +65,17 @@ pub struct Rpc { } impl Rpc { - fn read(&self) -> Result> { + async fn read(&self) -> Result> { match &self.input { - Some(path) => fs::read(path), - None => fs::read_stdin(), + Some(path) => fs::read(path).await, + None => fs::read_stdin().await, } } - fn write(&self, response: &[u8]) -> Result<()> { + async fn write(&self, response: &[u8]) -> Result<()> { match &self.output { - Some(path) => fs::write(path, response), - None => fs::write_stdout(response), + Some(path) => fs::write(path, response).await, + None => fs::write_stdout(response).await, } } } @@ -101,12 +101,12 @@ impl AppletRpc { Some(_) => bail!("applet identifiers are not supported yet"), None => applet::AppletId, }; - let request = applet::Request { applet_id, request: &rpc.read()? }; + let request = applet::Request { applet_id, request: &rpc.read().await? }; connection.call::(request).await?.get(); for _ in 0 .. retries { let response = connection.call::(applet_id).await?; if let Some(response) = response.get().response { - return rpc.write(response); + return rpc.write(response).await; } } bail!("did not receive a response after {retries} retries"); @@ -168,7 +168,9 @@ pub struct PlatformRpc { impl PlatformRpc { pub async fn run(self, connection: &mut dyn Connection) -> Result<()> { let PlatformRpc { rpc } = self; - rpc.write(connection.call::(&rpc.read()?).await?.get()) + let request = rpc.read().await?; + let response = connection.call::(&request).await?; + rpc.write(response.get()).await } } @@ -185,25 +187,25 @@ pub struct RustAppletNew { } impl RustAppletNew { - pub fn run(&self) -> Result<()> { + pub async fn run(&self) -> Result<()> { let RustAppletNew { path, name } = self; let mut cargo = Command::new("cargo"); cargo.args(["new", "--lib"]).arg(path); if let Some(name) = name { cargo.arg(format!("--name={name}")); } - cmd::execute(&mut cargo)?; - cmd::execute(Command::new("cargo").args(["add", "wasefire"]).current_dir(path))?; + cmd::execute(&mut cargo).await?; + cmd::execute(Command::new("cargo").args(["add", "wasefire"]).current_dir(path)).await?; let mut cargo = Command::new("cargo"); cargo.args(["add", "wasefire-stub", "--optional"]); - cmd::execute(cargo.current_dir(path))?; + cmd::execute(cargo.current_dir(path)).await?; let mut sed = Command::new("sed"); sed.arg("-i"); sed.arg("s#^wasefire-stub\\( = .\"dep:wasefire-stub\"\\)#test\\1, \"wasefire/test\"#"); sed.arg("Cargo.toml"); - cmd::execute(sed.current_dir(path))?; - std::fs::remove_file(path.join("src/lib.rs"))?; - fs::write(path.join("src/lib.rs"), include_str!("data/lib.rs"))?; + cmd::execute(sed.current_dir(path)).await?; + tokio::fs::remove_file(path.join("src/lib.rs")).await?; + fs::write(path.join("src/lib.rs"), include_str!("data/lib.rs")).await?; Ok(()) } } @@ -241,10 +243,11 @@ pub struct RustAppletBuild { } impl RustAppletBuild { - pub fn run(&self, dir: impl AsRef) -> Result<()> { - let metadata = metadata(dir.as_ref())?; + pub async fn run(&self, dir: impl AsRef) -> Result<()> { + let metadata = metadata(dir.as_ref()).await?; let package = &metadata.packages[0]; - let target_dir = fs::try_relative(std::env::current_dir()?, &metadata.target_directory)?; + let target_dir = + fs::try_relative(std::env::current_dir()?, &metadata.target_directory).await?; let name = package.name.replace('-', "_"); let mut cargo = Command::new("cargo"); let mut rustflags = Vec::new(); @@ -284,7 +287,7 @@ impl RustAppletBuild { } cargo.env("RUSTFLAGS", rustflags.join(" ")); cargo.current_dir(dir); - cmd::execute(&mut cargo)?; + cmd::execute(&mut cargo).await?; let out_dir = match &self.output { Some(x) => x.clone(), None => "target/wasefire".into(), @@ -294,8 +297,8 @@ impl RustAppletBuild { Some(target) => (format!("{target}/{profile}/lib{name}.a"), "libapplet.a"), }; let applet = out_dir.join(dst); - if fs::copy_if_changed(target_dir.join(src), &applet)? && dst.ends_with(".wasm") { - optimize_wasm(&applet, self.opt_level)?; + if fs::copy_if_changed(target_dir.join(src), &applet).await? && dst.ends_with(".wasm") { + optimize_wasm(&applet, self.opt_level).await?; } Ok(()) } @@ -310,8 +313,8 @@ pub struct RustAppletTest { } impl RustAppletTest { - pub fn run(&self, dir: impl AsRef) -> Result<()> { - let metadata = metadata(dir.as_ref())?; + pub async fn run(&self, dir: impl AsRef) -> Result<()> { + let metadata = metadata(dir.as_ref()).await?; let package = &metadata.packages[0]; ensure!(package.features.contains_key("test"), "missing test feature"); let mut cargo = Command::new("cargo"); @@ -357,10 +360,10 @@ impl Display for OptLevel { } /// Strips and optimizes a WASM applet. -pub fn optimize_wasm(applet: impl AsRef, opt_level: Option) -> Result<()> { +pub async fn optimize_wasm(applet: impl AsRef, opt_level: Option) -> Result<()> { let mut strip = Command::new("wasm-strip"); strip.arg(applet.as_ref()); - cmd::execute(&mut strip)?; + cmd::execute(&mut strip).await?; let mut opt = Command::new("wasm-opt"); opt.args(["--enable-bulk-memory", "--enable-sign-ext", "--enable-mutable-globals"]); match opt_level { @@ -370,12 +373,15 @@ pub fn optimize_wasm(applet: impl AsRef, opt_level: Option) -> R opt.arg(applet.as_ref()); opt.arg("-o"); opt.arg(applet.as_ref()); - cmd::execute(&mut opt)?; + cmd::execute(&mut opt).await?; Ok(()) } -fn metadata(dir: impl Into) -> Result { - let metadata = MetadataCommand::new().current_dir(dir).no_deps().exec()?; +async fn metadata(dir: impl Into) -> Result { + let dir = dir.into(); + let metadata = + tokio::task::spawn_blocking(|| MetadataCommand::new().current_dir(dir).no_deps().exec()) + .await??; ensure!(metadata.packages.len() == 1, "not exactly one package"); Ok(metadata) } diff --git a/crates/cli-tools/src/cmd.rs b/crates/cli-tools/src/cmd.rs index 2e02dfc7..864eda1d 100644 --- a/crates/cli-tools/src/cmd.rs +++ b/crates/cli-tools/src/cmd.rs @@ -12,38 +12,39 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Helpers around `std::process::Command`. +//! Helpers around `tokio::process::Command`. use std::os::unix::process::CommandExt; -use std::process::{Command, Output}; +use std::process::Output; use anyhow::{ensure, Context, Result}; +use tokio::process::Command; /// Executes a command making sure it's successful. -pub fn execute(command: &mut Command) -> Result<()> { - debug!("{command:?}"); - let code = command.spawn()?.wait()?.code().context("no error code")?; +pub async fn execute(command: &mut Command) -> Result<()> { + debug!("{:?}", command.as_std()); + let code = command.spawn()?.wait().await?.code().context("no error code")?; ensure!(code == 0, "failed with code {code}"); Ok(()) } /// Replaces the current program with the command. pub fn replace(mut command: Command) -> ! { - debug!("{command:?}"); - panic!("{}", command.exec()); + debug!("{:?}", command.as_std()); + panic!("{}", command.as_std_mut().exec()); } /// Executes the command making sure it's successful and returns its output. -pub fn output(command: &mut Command) -> Result { - debug!("{command:?}"); - let output = command.output()?; +pub async fn output(command: &mut Command) -> Result { + debug!("{:?}", command.as_std()); + let output = command.output().await?; ensure!(output.status.success(), "failed with status {}", output.status); Ok(output) } /// Executes the command making sure it's successful and returns exactly one line. -pub fn output_line(command: &mut Command) -> Result { - let mut output = output(command)?; +pub async fn output_line(command: &mut Command) -> Result { + let mut output = output(command).await?; assert!(output.stderr.is_empty()); assert_eq!(output.stdout.pop(), Some(b'\n')); Ok(String::from_utf8(output.stdout)?) diff --git a/crates/cli-tools/src/fs.rs b/crates/cli-tools/src/fs.rs index b04d6072..9f1f205f 100644 --- a/crates/cli-tools/src/fs.rs +++ b/crates/cli-tools/src/fs.rs @@ -12,23 +12,24 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Wrappers around `std::fs` with descriptive errors. +//! Wrappers around `tokio::fs` with descriptive errors. use std::fs::Metadata; -use std::io::{ErrorKind, Read, Write}; +use std::io::ErrorKind; use std::path::{Component, Path, PathBuf}; use anyhow::{Context, Result}; use serde::de::DeserializeOwned; use serde::Serialize; +use tokio::io::{AsyncReadExt, AsyncWriteExt}; -pub fn canonicalize(path: impl AsRef) -> Result { +pub async fn canonicalize(path: impl AsRef) -> Result { let name = path.as_ref().display(); - std::fs::canonicalize(path.as_ref()).with_context(|| format!("canonicalizing {name}")) + tokio::fs::canonicalize(path.as_ref()).await.with_context(|| format!("canonicalizing {name}")) } -pub fn try_canonicalize(path: impl AsRef) -> Result { - match canonicalize(&path) { +pub async fn try_canonicalize(path: impl AsRef) -> Result { + match canonicalize(&path).await { Err(x) if x.downcast_ref::().unwrap().kind() == ErrorKind::NotFound => { // We could try to canonicalize the existing prefix. Ok(path.as_ref().to_path_buf()) @@ -37,9 +38,9 @@ pub fn try_canonicalize(path: impl AsRef) -> Result { } } -pub fn try_relative(base: impl AsRef, path: impl AsRef) -> Result { - let base = try_canonicalize(&base)?; - let path = try_canonicalize(&path)?; +pub async fn try_relative(base: impl AsRef, path: impl AsRef) -> Result { + let base = try_canonicalize(&base).await?; + let path = try_canonicalize(&path).await?; let mut base = base.components().peekable(); let mut path = path.components().peekable(); // Advance the common prefix. @@ -57,109 +58,111 @@ pub fn try_relative(base: impl AsRef, path: impl AsRef) -> Result, to: impl AsRef) -> Result { +pub async fn copy(from: impl AsRef, to: impl AsRef) -> Result { let src = from.as_ref().display(); let dst = to.as_ref().display(); - create_parent(to.as_ref())?; + create_parent(to.as_ref()).await?; debug!("cp {src:?} {dst:?}"); - std::fs::copy(from.as_ref(), to.as_ref()).with_context(|| format!("copying {src} to {dst}")) + tokio::fs::copy(from.as_ref(), to.as_ref()) + .await + .with_context(|| format!("copying {src} to {dst}")) } -pub fn copy_if_changed(src: impl AsRef, dst: impl AsRef) -> Result { +pub async fn copy_if_changed(src: impl AsRef, dst: impl AsRef) -> Result { let dst_orig = dst.as_ref().with_added_extension("orig"); - let mut changed = !exists(&dst) - || metadata(&dst)?.modified()? < metadata(&src)?.modified()? - || !exists(&dst_orig); + let mut changed = !exists(&dst).await + || metadata(&dst).await?.modified()? < metadata(&src).await?.modified()? + || !exists(&dst_orig).await; if !changed { - let src_data = std::fs::read(&src)?; - let dst_data = std::fs::read(&dst_orig)?; + let src_data = tokio::fs::read(&src).await?; + let dst_data = tokio::fs::read(&dst_orig).await?; changed = src_data != dst_data; } if changed { - copy(&src, dst)?; - std::fs::copy(src, dst_orig)?; + copy(&src, dst).await?; + tokio::fs::copy(src, dst_orig).await?; } Ok(changed) } -pub fn create_dir_all(path: impl AsRef) -> Result<()> { +pub async fn create_dir_all(path: impl AsRef) -> Result<()> { let name = path.as_ref().display(); - if exists(path.as_ref()) { + if exists(path.as_ref()).await { return Ok(()); } debug!("mkdir -p {name:?}"); - std::fs::create_dir_all(path.as_ref()).with_context(|| format!("creating {name}")) + tokio::fs::create_dir_all(path.as_ref()).await.with_context(|| format!("creating {name}")) } -pub fn create_parent(path: impl AsRef) -> Result<()> { +pub async fn create_parent(path: impl AsRef) -> Result<()> { if let Some(parent) = path.as_ref().parent() { if !parent.as_os_str().is_empty() { - create_dir_all(parent)?; + create_dir_all(parent).await?; } } Ok(()) } -pub fn exists(path: impl AsRef) -> bool { - path.as_ref().exists() +pub async fn exists(path: impl AsRef) -> bool { + tokio::fs::try_exists(path).await.ok() == Some(true) } -pub fn metadata(path: impl AsRef) -> Result { +pub async fn metadata(path: impl AsRef) -> Result { let name = path.as_ref().display(); - std::fs::metadata(path.as_ref()).with_context(|| format!("reading {name} metadata")) + tokio::fs::metadata(path.as_ref()).await.with_context(|| format!("reading {name} metadata")) } -pub fn read(path: impl AsRef) -> Result> { +pub async fn read(path: impl AsRef) -> Result> { let name = path.as_ref().display(); debug!("read < {name:?}"); - std::fs::read(path.as_ref()).with_context(|| format!("reading {name}")) + tokio::fs::read(path.as_ref()).await.with_context(|| format!("reading {name}")) } -pub fn read_toml(path: impl AsRef) -> Result { +pub async fn read_toml(path: impl AsRef) -> Result { let name = path.as_ref().display(); - let contents = read(path.as_ref())?; + let contents = read(path.as_ref()).await?; let data = String::from_utf8(contents).with_context(|| format!("reading {name}"))?; toml::from_str(&data).with_context(|| format!("parsing {name}")) } -pub fn read_stdin() -> Result> { +pub async fn read_stdin() -> Result> { let mut data = Vec::new(); - std::io::stdin().read_to_end(&mut data).context("reading from stdin")?; + tokio::io::stdin().read_to_end(&mut data).await.context("reading from stdin")?; Ok(data) } -pub fn remove_file(path: impl AsRef) -> Result<()> { +pub async fn remove_file(path: impl AsRef) -> Result<()> { let name = path.as_ref().display(); debug!("rm {name:?}"); - std::fs::remove_file(path.as_ref()).with_context(|| format!("removing {name}")) + tokio::fs::remove_file(path.as_ref()).await.with_context(|| format!("removing {name}")) } -pub fn touch(path: impl AsRef) -> Result<()> { - if exists(path.as_ref()) { +pub async fn touch(path: impl AsRef) -> Result<()> { + if exists(path.as_ref()).await { return Ok(()); } - write(path, "") + write(path, "").await } -pub fn write(path: impl AsRef, contents: impl AsRef<[u8]>) -> Result<()> { +pub async fn write(path: impl AsRef, contents: impl AsRef<[u8]>) -> Result<()> { let name = path.as_ref().display(); let contents = contents.as_ref(); - create_parent(path.as_ref())?; + create_parent(path.as_ref()).await?; debug!("write > {name:?}"); - std::fs::write(path.as_ref(), contents).with_context(|| format!("writing {name}"))?; + tokio::fs::write(path.as_ref(), contents).await.with_context(|| format!("writing {name}"))?; Ok(()) } -pub fn write_toml(path: impl AsRef, contents: &T) -> Result<()> { +pub async fn write_toml(path: impl AsRef, contents: &T) -> Result<()> { let name = path.as_ref().display(); let contents = toml::to_string(contents).with_context(|| format!("displaying {name}"))?; - write(path.as_ref(), contents)?; + write(path.as_ref(), contents).await?; Ok(()) } -pub fn write_stdout(contents: impl AsRef<[u8]>) -> Result<()> { +pub async fn write_stdout(contents: impl AsRef<[u8]>) -> Result<()> { let contents = contents.as_ref(); - std::io::stdout().write_all(contents).context("writing to stdout")?; + tokio::io::stdout().write_all(contents).await.context("writing to stdout")?; Ok(()) } @@ -167,14 +170,14 @@ pub fn write_stdout(contents: impl AsRef<[u8]>) -> Result<()> { mod tests { use super::*; - #[test] - fn try_relative_ok() { + #[tokio::test] + async fn try_relative_ok() { #[track_caller] - fn test(base: &str, path: &str, res: &str) { - assert_eq!(try_relative(base, path).ok(), Some(PathBuf::from(res))); + async fn test(base: &str, path: &str, res: &str) { + assert_eq!(try_relative(base, path).await.ok(), Some(PathBuf::from(res))); } - test("/foo/bar", "/foo", ".."); - test("/foo/bar", "/foo/baz/qux", "../baz/qux"); - test("/foo/bar", "/foo/bar/qux", "qux"); + test("/foo/bar", "/foo", "..").await; + test("/foo/bar", "/foo/baz/qux", "../baz/qux").await; + test("/foo/bar", "/foo/bar/qux", "qux").await; } } diff --git a/crates/cli-tools/src/lib.rs b/crates/cli-tools/src/lib.rs index deedc984..382ef9e7 100644 --- a/crates/cli-tools/src/lib.rs +++ b/crates/cli-tools/src/lib.rs @@ -16,6 +16,7 @@ //! //! This library is also used for the internal maintenance CLI of Wasefire called xtask. +#![feature(async_fn_track_caller)] #![feature(path_add_extension)] #![feature(try_find)] diff --git a/crates/cli/CHANGELOG.md b/crates/cli/CHANGELOG.md index 1896f65b..fc9bed14 100644 --- a/crates/cli/CHANGELOG.md +++ b/crates/cli/CHANGELOG.md @@ -36,4 +36,4 @@ ## 0.1.0 - + diff --git a/crates/cli/Cargo.lock b/crates/cli/Cargo.lock index 9e15f924..ffa0c1f1 100644 --- a/crates/cli/Cargo.lock +++ b/crates/cli/Cargo.lock @@ -508,6 +508,15 @@ dependencies = [ "serde", ] +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + [[package]] name = "smallvec" version = "1.13.2" @@ -573,6 +582,7 @@ dependencies = [ "mio", "parking_lot", "pin-project-lite", + "signal-hook-registry", "socket2", "tokio-macros", "windows-sys", @@ -673,6 +683,7 @@ dependencies = [ "humantime", "rusb", "serde", + "tokio", "toml", "wasefire-protocol", "wasefire-protocol-tokio", diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index d218b85c..cd914814 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -22,7 +22,7 @@ clap_complete = { version = "4.5.2", default-features = false } wasefire-cli-tools = { version = "0.2.0-git", path = "../cli-tools" } [dependencies.tokio] -version = "1.37.0" +version = "1.40.0" default-features = false features = ["macros", "parking_lot", "rt", "rt-multi-thread"] diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 4de71594..9aec185d 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -100,7 +100,7 @@ struct Completion { } impl Completion { - fn run(&self) -> Result<()> { + async fn run(&self) -> Result<()> { let shell = match self.shell.or_else(Shell::from_env) { Some(x) => x, None => bail!("failed to guess a shell"), @@ -110,7 +110,7 @@ impl Completion { let mut output: Box = if self.output == Path::new("-") { Box::new(std::io::stdout()) } else { - fs::create_parent(&self.output)?; + fs::create_parent(&self.output).await?; Box::new(File::create(&self.output)?) }; clap_complete::generate(shell, &mut cmd, name, &mut output); @@ -134,9 +134,9 @@ async fn main() -> Result<()> { action.run(&mut options.connect().await?).await } Action::PlatformRpc { options, action } => action.run(&mut options.connect().await?).await, - Action::RustAppletNew(x) => x.run(), - Action::RustAppletBuild(x) => x.run(dir), - Action::RustAppletTest(x) => x.run(dir), - Action::Completion(x) => x.run(), + Action::RustAppletNew(x) => x.run().await, + Action::RustAppletBuild(x) => x.run(dir).await, + Action::RustAppletTest(x) => x.run(dir).await, + Action::Completion(x) => x.run().await, } } diff --git a/crates/protocol-tokio/CHANGELOG.md b/crates/protocol-tokio/CHANGELOG.md index 7bcc0814..6faacf76 100644 --- a/crates/protocol-tokio/CHANGELOG.md +++ b/crates/protocol-tokio/CHANGELOG.md @@ -2,4 +2,4 @@ ## 0.1.0-git - + diff --git a/crates/protocol-tokio/Cargo.toml b/crates/protocol-tokio/Cargo.toml index a7972536..3f53e64b 100644 --- a/crates/protocol-tokio/Cargo.toml +++ b/crates/protocol-tokio/Cargo.toml @@ -20,7 +20,7 @@ wasefire-error = { version = "0.1.2-git", path = "../error", optional = true } wasefire-logger = { version = "0.1.5", path = "../logger" } [dependencies.tokio] -version = "1.37.0" +version = "1.40.0" default-features = false features = ["io-util", "macros", "net", "rt", "sync"] diff --git a/crates/protocol/crates/schema/Cargo.lock b/crates/protocol/crates/schema/Cargo.lock index 5649327b..c375be4a 100644 --- a/crates/protocol/crates/schema/Cargo.lock +++ b/crates/protocol/crates/schema/Cargo.lock @@ -29,6 +29,12 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + [[package]] name = "backtrace" version = "0.3.73" @@ -44,6 +50,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + [[package]] name = "bytes" version = "1.7.1" @@ -219,6 +231,16 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.21" @@ -281,6 +303,29 @@ dependencies = [ "memchr", ] +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + [[package]] name = "pin-project-lite" version = "0.2.14" @@ -311,6 +356,15 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "redox_syscall" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" +dependencies = [ + "bitflags", +] + [[package]] name = "rusb" version = "0.9.4" @@ -338,12 +392,19 @@ name = "schema" version = "0.1.0" dependencies = [ "anyhow", + "tokio", "wasefire-cli-tools", "wasefire-error", "wasefire-protocol", "wasefire-wire", ] +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "semver" version = "1.0.23" @@ -393,6 +454,21 @@ dependencies = [ "serde", ] +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + [[package]] name = "socket2" version = "0.5.7" @@ -444,7 +520,9 @@ dependencies = [ "bytes", "libc", "mio", + "parking_lot", "pin-project-lite", + "signal-hook-registry", "socket2", "tokio-macros", "windows-sys", @@ -528,6 +606,7 @@ dependencies = [ "humantime", "rusb", "serde", + "tokio", "toml", "wasefire-protocol", "wasefire-protocol-tokio", diff --git a/crates/protocol/crates/schema/Cargo.toml b/crates/protocol/crates/schema/Cargo.toml index 0a2bd8a1..5c6df86b 100644 --- a/crates/protocol/crates/schema/Cargo.toml +++ b/crates/protocol/crates/schema/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] anyhow = "1.0.86" +tokio = { version = "1.40.0", features = ["full"] } wasefire-cli-tools = { path = "../../../cli-tools" } wasefire-error = { path = "../../../error" } wasefire-protocol = { path = "../..", features = ["_descriptor"] } diff --git a/crates/protocol/crates/schema/src/main.rs b/crates/protocol/crates/schema/src/main.rs index 5573567a..d020b054 100644 --- a/crates/protocol/crates/schema/src/main.rs +++ b/crates/protocol/crates/schema/src/main.rs @@ -16,20 +16,21 @@ use std::collections::HashMap; use std::fmt::Write; -use std::process::Command; use anyhow::{bail, ensure, Context, Result}; +use tokio::process::Command; use wasefire_cli_tools::{cmd, fs}; use wasefire_error::Error; use wasefire_protocol::{Api, Descriptor, Request, Response, DESCRIPTORS, VERSION}; use wasefire_wire::schema::{View, ViewEnum, ViewFields}; use wasefire_wire::{Wire, Yoke}; -fn main() -> Result<()> { +#[tokio::main] +async fn main() -> Result<()> { let new = Schema::new(); - new.write().context("writing bin")?; - new.print().context("printing txt")?; - let old = Schema::old()?; + new.write().await.context("writing bin")?; + new.print().await.context("printing txt")?; + let old = Schema::old().await?; check(&old.get().result, &new.result).context("checking result")?; check(&old.get().request, &new.request).context("checking request")?; check(&old.get().response, &new.response).context("checking response")?; @@ -121,11 +122,11 @@ impl Schema<'static> { } } - fn old() -> Result>> { + async fn old() -> Result>> { let base = Self::base()?; let mut git = Command::new("git"); git.args(["show", &format!("{base}:./{SIDE}.bin")]); - let data = cmd::output(&mut git)?.stdout.into_boxed_slice(); + let data = cmd::output(&mut git).await?.stdout.into_boxed_slice(); Ok(wasefire_wire::decode_yoke(data)?) } @@ -145,11 +146,11 @@ impl Schema<'static> { }) } - fn write(&self) -> Result<()> { - fs::write(format!("{SIDE}.bin"), wasefire_wire::encode(self)?) + async fn write(&self) -> Result<()> { + fs::write(format!("{SIDE}.bin"), wasefire_wire::encode(self)?).await } - fn print(&self) -> Result<()> { + async fn print(&self) -> Result<()> { let mut output = String::new(); writeln!(&mut output, "result: {}", self.result)?; writeln!(&mut output, "version: {}", self.versions.version)?; @@ -170,7 +171,7 @@ impl Schema<'static> { } assert!(response.next().is_none()); assert!(descriptor.next().is_none()); - fs::write(format!("{SIDE}.txt"), &output) + fs::write(format!("{SIDE}.txt"), &output).await } } diff --git a/crates/runner-host/Cargo.lock b/crates/runner-host/Cargo.lock index f8de9fd6..70d7d526 100644 --- a/crates/runner-host/Cargo.lock +++ b/crates/runner-host/Cargo.lock @@ -97,7 +97,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" dependencies = [ - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -107,7 +107,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" dependencies = [ "anstyle", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -977,13 +977,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.11" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ + "hermit-abi", "libc", "wasi", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -1025,17 +1026,7 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5831952a9476f2fed74b77d74182fa5ddc4d21c72ec45a333b250e3ed0272804" dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", + "windows-sys", ] [[package]] @@ -1088,7 +1079,7 @@ dependencies = [ "bstr", "dbus", "normpath", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1135,7 +1126,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets 0.52.5", + "windows-targets", ] [[package]] @@ -1550,7 +1541,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1639,28 +1630,27 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.37.0" +version = "1.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] name = "tokio-macros" -version = "2.2.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", @@ -2000,6 +1990,7 @@ dependencies = [ "humantime", "rusb", "serde", + "tokio", "toml", "wasefire-protocol", "wasefire-protocol-tokio", @@ -2165,37 +2156,13 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] @@ -2204,46 +2171,28 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.5" @@ -2256,48 +2205,24 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "windows_x86_64_msvc" version = "0.52.5" diff --git a/crates/runner-host/Cargo.toml b/crates/runner-host/Cargo.toml index 91ca6040..a6b3a2ca 100644 --- a/crates/runner-host/Cargo.toml +++ b/crates/runner-host/Cargo.toml @@ -15,7 +15,7 @@ futures = "0.3.30" rand = "0.8.5" signal-hook = "0.3.17" signal-hook-tokio = { version = "0.3.1", features = ["futures-v0_3"] } -tokio = { version = "1.37.0", features = ["full"] } +tokio = { version = "1.40.0", features = ["full"] } usb-device = { version = "0.3.2", optional = true } usbd-serial = { version = "0.2.2", optional = true } usbip-device = { version = "0.2.0", optional = true } diff --git a/crates/runner-host/crates/web-server/Cargo.lock b/crates/runner-host/crates/web-server/Cargo.lock index 012b1e7c..b80ca4e0 100644 --- a/crates/runner-host/crates/web-server/Cargo.lock +++ b/crates/runner-host/crates/web-server/Cargo.lock @@ -472,13 +472,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.11" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ + "hermit-abi", "libc", "wasi", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -505,17 +506,7 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5831952a9476f2fed74b77d74182fa5ddc4d21c72ec45a333b250e3ed0272804" dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", + "windows-sys", ] [[package]] @@ -542,7 +533,7 @@ dependencies = [ "bstr", "dbus", "normpath", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -565,7 +556,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets 0.52.5", + "windows-targets", ] [[package]] @@ -790,7 +781,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -847,28 +838,27 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.37.0" +version = "1.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] name = "tokio-macros" -version = "2.2.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", @@ -1101,37 +1091,13 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] @@ -1140,46 +1106,28 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.5" @@ -1192,48 +1140,24 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "windows_x86_64_msvc" version = "0.52.5" diff --git a/crates/runner-host/crates/web-server/Cargo.toml b/crates/runner-host/crates/web-server/Cargo.toml index 86e6576a..00b617b8 100644 --- a/crates/runner-host/crates/web-server/Cargo.toml +++ b/crates/runner-host/crates/web-server/Cargo.toml @@ -11,7 +11,7 @@ anyhow = "1.0.86" futures-util = "0.3.30" opener = "0.7.1" serde_json = "1.0.117" -tokio = { version = "1.37.0", features = ["full", "rt-multi-thread", "sync"] } +tokio = { version = "1.40.0", features = ["full", "rt-multi-thread", "sync"] } warp = "0.3.7" wasefire-logger = { path = "../../../logger" } web-common = { path = "../web-common" } diff --git a/crates/runner-host/src/main.rs b/crates/runner-host/src/main.rs index e8a01a61..79c954be 100644 --- a/crates/runner-host/src/main.rs +++ b/crates/runner-host/src/main.rs @@ -104,9 +104,9 @@ async fn main() -> Result<()> { } } }); - let mut trunk = std::process::Command::new("../../scripts/wrapper.sh"); + let mut trunk = tokio::process::Command::new("../../scripts/wrapper.sh"); trunk.args(["trunk", "build", "--release", "crates/web-client/index.html"]); - wasefire_cli_tools::cmd::execute(&mut trunk)?; + wasefire_cli_tools::cmd::execute(&mut trunk).await?; let url = format!("{}:{}", flags.web_options.web_host, flags.web_options.web_port); web_server::Client::new(&url, sender).await? }; diff --git a/crates/xtask/Cargo.lock b/crates/xtask/Cargo.lock index a40578b5..56d894c4 100644 --- a/crates/xtask/Cargo.lock +++ b/crates/xtask/Cargo.lock @@ -840,12 +840,6 @@ dependencies = [ "serde", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "leb128" version = "0.2.5" @@ -1419,6 +1413,15 @@ dependencies = [ "digest", ] +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + [[package]] name = "slab" version = "0.4.9" @@ -1581,7 +1584,9 @@ dependencies = [ "bytes", "libc", "mio", + "parking_lot", "pin-project-lite", + "signal-hook-registry", "socket2", "tokio-macros", "windows-sys 0.52.0", @@ -1789,6 +1794,7 @@ dependencies = [ "humantime", "rusb", "serde", + "tokio", "toml", "wasefire-protocol", "wasefire-protocol-tokio", @@ -2062,12 +2068,12 @@ dependencies = [ "anyhow", "clap", "env_logger", - "lazy_static", "log", "probe-rs", "rustc-demangle", "serde", "stack-sizes", + "tokio", "wasefire-cli-tools", ] diff --git a/crates/xtask/Cargo.toml b/crates/xtask/Cargo.toml index ed3cf93f..dd62a8e5 100644 --- a/crates/xtask/Cargo.toml +++ b/crates/xtask/Cargo.toml @@ -10,12 +10,12 @@ edition = "2021" anyhow = "1.0.86" clap = { version = "4.5.4", features = ["derive"] } env_logger = "0.11.3" -lazy_static = "1.4.0" log = "0.4.21" probe-rs = "0.24.0" rustc-demangle = "0.1.24" serde = { version = "1.0.202", features = ["derive"] } stack-sizes = "0.5.0" +tokio = { version = "1.40.0", features = ["full"] } wasefire-cli-tools = { path = "../cli-tools" } [lints] diff --git a/crates/xtask/src/footprint.rs b/crates/xtask/src/footprint.rs index a07ab824..a8aed8b6 100644 --- a/crates/xtask/src/footprint.rs +++ b/crates/xtask/src/footprint.rs @@ -35,18 +35,18 @@ struct Row { value: HashMap, } -pub fn update_applet(config: &str, value: usize) -> Result<()> { - update("applet", config, value) +pub async fn update_applet(config: &str, value: usize) -> Result<()> { + update("applet", config, value).await } -pub fn update_runner(config: &str, value: usize) -> Result<()> { - update("runner", config, value) +pub async fn update_runner(config: &str, value: usize) -> Result<()> { + update("runner", config, value).await } -fn update(key: &str, config: &str, value: usize) -> Result<()> { +async fn update(key: &str, config: &str, value: usize) -> Result<()> { const PATH: &str = "footprint.toml"; - let mut footprint = match fs::exists(PATH) { - true => fs::read_toml(PATH)?, + let mut footprint = match fs::exists(PATH).await { + true => fs::read_toml(PATH).await?, false => Footprint::default(), }; let idx = match footprint.row.binary_search_by_key(&config, |x| &x.config) { @@ -61,14 +61,14 @@ fn update(key: &str, config: &str, value: usize) -> Result<()> { footprint.row[idx].value.insert(key.to_string(), value).is_none(), "{key} is already defined for {config:?}" ); - fs::write_toml(PATH, &footprint)?; + fs::write_toml(PATH, &footprint).await?; Ok(()) } -pub fn compare(output: &str) -> Result<()> { +pub async fn compare(output: &str) -> Result<()> { let mut output = OpenOptions::new().create(true).append(true).open(output)?; - let base = Footprint::read("footprint-push.toml"); - let head = Footprint::read("footprint-pull_request.toml"); + let base = Footprint::read("footprint-push.toml").await; + let head = Footprint::read("footprint-pull_request.toml").await; let configs: BTreeSet<&String> = base.keys().chain(head.keys()).collect(); writeln!(output, "### Footprint impact\n")?; writeln!(output, "| Config | Key | Base | Head | Diff | Ratio |")?; @@ -109,10 +109,10 @@ pub fn compare(output: &str) -> Result<()> { } /// Returns the sum of the .text and .data size. -pub fn rust_size(elf: &str) -> Result { - let mut size = wrap_command()?; +pub async fn rust_size(elf: &str) -> Result { + let mut size = wrap_command().await?; size.args(["rust-size", elf]); - let output = String::from_utf8(cmd::output(&mut size)?.stdout)?; + let output = String::from_utf8(cmd::output(&mut size).await?.stdout)?; let line = output.lines().nth(1).context("parsing rust-size output")?; let words = line.split_whitespace().take(2).map(|x| Ok(x.parse()?)).collect::>>()?; @@ -120,9 +120,9 @@ pub fn rust_size(elf: &str) -> Result { } impl Footprint { - fn read(path: &str) -> HashMap> { + async fn read(path: &str) -> HashMap> { let mut result = HashMap::new(); - let footprint = fs::read_toml(path).unwrap_or_else(|err| { + let footprint = fs::read_toml(path).await.unwrap_or_else(|err| { println!("::warning::{err}"); Footprint::default() }); diff --git a/crates/xtask/src/main.rs b/crates/xtask/src/main.rs index d18f3af8..8a0c6cef 100644 --- a/crates/xtask/src/main.rs +++ b/crates/xtask/src/main.rs @@ -16,14 +16,15 @@ use std::cmp::Reverse; use std::collections::BinaryHeap; -use std::process::Command; +use std::sync::{Arc, Mutex}; use anyhow::{bail, ensure, Context, Result}; use clap::Parser; -use lazy_static::lazy_static; use probe_rs::config::TargetSelector; use probe_rs::{flashing, Permissions, Session}; use rustc_demangle::demangle; +use tokio::process::Command; +use tokio::sync::OnceCell; use wasefire_cli_tools::{action, cmd, fs}; mod footprint; @@ -216,12 +217,12 @@ struct RunnerOptions { } impl Flags { - fn execute(self) -> Result<()> { + async fn execute(self) -> Result<()> { match self.command { - MainCommand::Applet(applet) => applet.execute(&self.options), - MainCommand::Runner(runner) => runner.execute(&self.options), - MainCommand::Footprint { output } => footprint::compare(&output), - MainCommand::Textreview => textreview::execute(), + MainCommand::Applet(applet) => applet.execute(&self.options).await, + MainCommand::Runner(runner) => runner.execute(&self.options).await, + MainCommand::Footprint { output } => footprint::compare(&output).await, + MainCommand::Textreview => textreview::execute().await, } } } @@ -233,43 +234,43 @@ impl MainOptions { } impl Applet { - fn execute(self, main: &MainOptions) -> Result<()> { - self.options.execute(main, &self.command)?; + async fn execute(self, main: &MainOptions) -> Result<()> { + self.options.execute(main, &self.command).await?; if let Some(command) = &self.command { - command.execute(main)?; + command.execute(main).await?; } Ok(()) } } impl AppletOptions { - fn execute(self, main: &MainOptions, command: &Option) -> Result<()> { + async fn execute(self, main: &MainOptions, command: &Option) -> Result<()> { if !main.is_native() { - ensure_command(&["wasm-strip"])?; - ensure_command(&["wasm-opt"])?; + ensure_command(&["wasm-strip"]).await?; + ensure_command(&["wasm-opt"]).await?; } match self.lang.as_str() { - "rust" => self.execute_rust(main, command), - "assemblyscript" => self.execute_assemblyscript(main), + "rust" => self.execute_rust(main, command).await, + "assemblyscript" => self.execute_assemblyscript(main).await, x => bail!("unsupported language {x}"), } } - fn execute_rust(self, main: &MainOptions, command: &Option) -> Result<()> { + async fn execute_rust(self, main: &MainOptions, command: &Option) -> Result<()> { let dir = if self.name.starts_with(['.', '/']) { self.name.clone() } else { format!("examples/{}/{}", self.lang, self.name) }; - ensure!(fs::exists(&dir), "{dir} does not exist"); + ensure!(fs::exists(&dir).await, "{dir} does not exist"); let native = match (main.native, &main.native_target, command) { (_, Some(target), command) => { if let Some(AppletCommand::Runner(x)) = command { - ensure!(target == x.target(), "--native-target must match runner"); + ensure!(target == x.target().await, "--native-target must match runner"); } Some(target.as_str()) } - (true, None, Some(AppletCommand::Runner(x))) => Some(x.target()), + (true, None, Some(AppletCommand::Runner(x))) => Some(x.target().await), (true, None, _) => bail!("--native requires runner"), (false, _, _) => None, }; @@ -284,27 +285,27 @@ impl AppletOptions { for features in &self.features { action.cargo.push(format!("--features={features}")); } - action.run(dir)?; + action.run(dir).await?; if !main.size && main.footprint.is_none() { return Ok(()); } let size = match native { - Some(_) => footprint::rust_size("target/wasefire/libapplet.a")?, - None => fs::metadata("target/wasefire/applet.wasm")?.len() as usize, + Some(_) => footprint::rust_size("target/wasefire/libapplet.a").await?, + None => fs::metadata("target/wasefire/applet.wasm").await?.len() as usize, }; if main.size { println!("Size: {size}"); } if let Some(key) = &main.footprint { - footprint::update_applet(key, size)?; + footprint::update_applet(key, size).await?; } Ok(()) } - fn execute_assemblyscript(&self, main: &MainOptions) -> Result<()> { + async fn execute_assemblyscript(&self, main: &MainOptions) -> Result<()> { ensure!(!main.is_native(), "native applets are not supported for assemblyscript"); let dir = format!("examples/{}", self.lang); - ensure_assemblyscript()?; + ensure_assemblyscript().await?; let mut asc = Command::new("./node_modules/.bin/asc"); asc.args(["-o", "../../target/wasefire/applet.wasm"]); match self.opt_level { @@ -320,29 +321,29 @@ impl AppletOptions { } asc.arg(format!("{}/main.ts", self.name)); asc.current_dir(dir); - cmd::execute(&mut asc)?; - action::optimize_wasm("target/wasefire/applet.wasm", self.opt_level)?; + cmd::execute(&mut asc).await?; + action::optimize_wasm("target/wasefire/applet.wasm", self.opt_level).await?; Ok(()) } } impl AppletCommand { - fn execute(&self, main: &MainOptions) -> Result<()> { + async fn execute(&self, main: &MainOptions) -> Result<()> { match self { - AppletCommand::Runner(runner) => runner.execute(main, 0, true), + AppletCommand::Runner(runner) => runner.execute(main, 0, true).await, } } } impl Runner { - fn execute(&self, main: &MainOptions) -> Result<()> { - self.options.execute(main, 0, false)?; + async fn execute(&self, main: &MainOptions) -> Result<()> { + self.options.execute(main, 0, false).await?; Ok(()) } } impl RunnerOptions { - fn execute(&self, main: &MainOptions, step: usize, run: bool) -> Result<()> { + async fn execute(&self, main: &MainOptions, step: usize, run: bool) -> Result<()> { let mut cargo = Command::new("cargo"); let mut rustflags = Vec::new(); let mut features = self.features.clone(); @@ -352,7 +353,7 @@ impl RunnerOptions { cargo.arg("build"); } cargo.arg("--release"); - cargo.arg(format!("--target={}", self.target())); + cargo.arg(format!("--target={}", self.target().await)); let (side, max_step) = match self.name.as_str() { "nordic" => (Some(step), 1), "host" => (None, 0), @@ -434,12 +435,12 @@ impl RunnerOptions { } cargo.current_dir(format!("crates/runner-{}", self.name)); if !main.native { - fs::touch("target/wasefire/applet.wasm")?; + fs::touch("target/wasefire/applet.wasm").await?; } if run && self.name == "host" { let path = "target/wasefire/storage.bin"; - if self.reset_storage && fs::exists(path) { - fs::remove_file(path)?; + if self.reset_storage && fs::exists(path).await { + fs::remove_file(path).await?; } cargo.arg("--"); if let Some(host) = &self.web_host { @@ -450,22 +451,22 @@ impl RunnerOptions { } cmd::replace(cargo); } else { - cmd::execute(&mut cargo)?; + cmd::execute(&mut cargo).await?; } if self.measure_bloat { - ensure_command(&["cargo", "bloat"])?; - let mut bloat = wrap_command()?; - bloat.arg(cargo.get_program()); - if let Some(dir) = cargo.get_current_dir() { + ensure_command(&["cargo", "bloat"]).await?; + let mut bloat = wrap_command().await?; + bloat.arg(cargo.as_std().get_program()); + if let Some(dir) = cargo.as_std().get_current_dir() { bloat.current_dir(dir); } - for (key, val) in cargo.get_envs() { + for (key, val) in cargo.as_std().get_envs() { match val { None => bloat.env_remove(key), Some(val) => bloat.env(key, val), }; } - for arg in cargo.get_args() { + for arg in cargo.as_std().get_args() { if arg == "build" { bloat.arg("bloat"); } else { @@ -473,20 +474,20 @@ impl RunnerOptions { } } bloat.args(["--crates", "--split-std"]); - cmd::execute(&mut bloat)?; + cmd::execute(&mut bloat).await?; } - let elf = self.board_target(); + let elf = self.board_target().await; if main.size { - let mut size = wrap_command()?; + let mut size = wrap_command().await?; size.arg("rust-size"); size.arg(&elf); - cmd::execute(&mut size)?; + cmd::execute(&mut size).await?; } if let Some(key) = &main.footprint { - footprint::update_runner(key, footprint::rust_size(&elf)?)?; + footprint::update_runner(key, footprint::rust_size(&elf).await?).await?; } if let Some(stack_sizes) = self.stack_sizes { - let elf = fs::read(&elf)?; + let elf = fs::read(&elf).await?; let symbols = stack_sizes::analyze_executable(&elf)?; assert!(symbols.have_32_bit_addresses); assert!(symbols.undefined.is_empty()); @@ -509,12 +510,12 @@ impl RunnerOptions { } } if self.bundle { - let mut objcopy = wrap_command()?; + let mut objcopy = wrap_command().await?; objcopy.args(["rust-objcopy", "-O", "binary", &elf]); objcopy.arg(format!("target/wasefire/platform{side}.bin")); - cmd::execute(&mut objcopy)?; + cmd::execute(&mut objcopy).await?; if step < max_step { - return self.execute(main, step + 1, run); + return Box::pin(self.execute(main, step + 1, run)).await; } return Ok(()); } @@ -526,35 +527,45 @@ impl RunnerOptions { "host" => unreachable!(), _ => unimplemented!(), }; - let mut session = lazy::Lazy::new(|| { + let session = Arc::new(Mutex::new(lazy::Lazy::new(|| { Ok(Session::auto_attach( TargetSelector::Unspecified(chip.to_string()), Permissions::default(), )?) - }); + }))); if self.reset_storage { println!("Erasing the persistent storage."); // Keep those values in sync with crates/runner-nordic/memory.x. - flashing::erase_sectors(session.get()?, None, 240, 16)?; + tokio::task::spawn_blocking({ + let session = session.clone(); + move || { + let mut session = session.lock().unwrap(); + anyhow::Ok(flashing::erase_sectors(session.get()?, None, 240, 16)?) + } + }) + .await??; } if self.name == "nordic" { let mut cargo = Command::new("cargo"); cargo.current_dir("crates/runner-nordic/crates/bootloader"); cargo.args(["build", "--release", "--target=thumbv7em-none-eabi"]); cargo.args(["-Zbuild-std=core", "-Zbuild-std-features=panic_immediate_abort"]); - cmd::execute(&mut cargo)?; - flashing::download_file( - session.get()?, - "target/thumbv7em-none-eabi/release/bootloader", - flashing::Format::Elf, - )?; + cmd::execute(&mut cargo).await?; + tokio::task::spawn_blocking(move || { + anyhow::Ok(flashing::download_file( + session.lock().unwrap().get()?, + "target/thumbv7em-none-eabi/release/bootloader", + flashing::Format::Elf, + )?) + }) + .await??; } if self.gdb { println!("Use the following 2 commands in different terminals:"); println!("JLinkGDBServer -device {chip} -if swd -speed 4000 -port 2331"); println!("gdb-multiarch -ex 'file {elf}' -ex 'target remote localhost:2331'"); } - let mut probe_rs = wrap_command()?; + let mut probe_rs = wrap_command().await?; probe_rs.args(["probe-rs", "run"]); probe_rs.arg(format!("--chip={chip}")); probe_rs.args(&self.probe_rs); @@ -563,21 +574,23 @@ impl RunnerOptions { cmd::replace(probe_rs); } - fn target(&self) -> &'static str { - lazy_static! { - // Each time we specify RUSTFLAGS, we want to specify --target. This is because if - // --target is not specified then RUSTFLAGS applies to all compiler invocations - // (including build scripts and proc macros). This leads to recompilation when RUSTFLAGS - // changes. See https://github.com/rust-lang/cargo/issues/8716. - static ref HOST_TARGET: String = { - let mut sh = Command::new("sh"); - sh.args(["-c", "rustc -vV | sed -n 's/^host: //p'"]); - cmd::output_line(&mut sh).unwrap() - }; - } + async fn target(&self) -> &'static str { + // Each time we specify RUSTFLAGS, we want to specify --target. This is because if --target + // is not specified then RUSTFLAGS applies to all compiler invocations (including build + // scripts and proc macros). This leads to recompilation when RUSTFLAGS changes. See + // https://github.com/rust-lang/cargo/issues/8716. + static HOST_TARGET: OnceCell = OnceCell::const_new(); match self.name.as_str() { "nordic" => "thumbv7em-none-eabi", - "host" => &HOST_TARGET, + "host" => { + HOST_TARGET + .get_or_init(|| async { + let mut sh = Command::new("sh"); + sh.args(["-c", "rustc -vV | sed -n 's/^host: //p'"]); + cmd::output_line(&mut sh).await.unwrap() + }) + .await + } _ => unimplemented!(), } } @@ -590,43 +603,44 @@ impl RunnerOptions { } } - fn board_target(&self) -> String { - format!("target/{}/release/runner-{}", self.target(), self.name) + async fn board_target(&self) -> String { + format!("target/{}/release/runner-{}", self.target().await, self.name) } } -fn ensure_command(cmd: &[&str]) -> Result<()> { +async fn ensure_command(cmd: &[&str]) -> Result<()> { let mut wrapper = Command::new("./scripts/wrapper.sh"); wrapper.args(cmd); wrapper.env("WASEFIRE_WRAPPER_EXEC", "n"); - cmd::execute(&mut wrapper) + cmd::execute(&mut wrapper).await } -fn wrap_command() -> Result { - Ok(Command::new(fs::canonicalize("./scripts/wrapper.sh")?)) +async fn wrap_command() -> Result { + Ok(Command::new(fs::canonicalize("./scripts/wrapper.sh").await?)) } -fn ensure_assemblyscript() -> Result<()> { +async fn ensure_assemblyscript() -> Result<()> { const ASC_VERSION: &str = "0.27.29"; // scripts/upgrade.sh relies on this name const BIN: &str = "examples/assemblyscript/node_modules/.bin/asc"; const JSON: &str = "examples/assemblyscript/node_modules/assemblyscript/package.json"; - if fs::exists(BIN) && fs::exists(JSON) { + if fs::exists(BIN).await && fs::exists(JSON).await { let mut sed = Command::new("sed"); sed.args(["-n", r#"s/^ "version": "\(.*\)",$/\1/p"#, JSON]); - if cmd::output_line(&mut sed)? == ASC_VERSION { + if cmd::output_line(&mut sed).await? == ASC_VERSION { return Ok(()); } } - ensure_command(&["npm"])?; - let mut npm = wrap_command()?; + ensure_command(&["npm"]).await?; + let mut npm = wrap_command().await?; npm.args(["npm", "install", "--no-save"]); npm.arg(format!("assemblyscript@{ASC_VERSION}")); npm.current_dir("examples/assemblyscript"); - cmd::execute(&mut npm) + cmd::execute(&mut npm).await } -fn main() -> Result<()> { +#[tokio::main] +async fn main() -> Result<()> { env_logger::init_from_env(env_logger::Env::new().default_filter_or("warn")); - Flags::parse().execute()?; + Flags::parse().execute().await?; Ok(()) } diff --git a/crates/xtask/src/textreview.rs b/crates/xtask/src/textreview.rs index a0bd0952..850a9ba7 100644 --- a/crates/xtask/src/textreview.rs +++ b/crates/xtask/src/textreview.rs @@ -13,13 +13,13 @@ // limitations under the License. use std::io::BufRead; -use std::process::Command; use anyhow::{ensure, Context, Result}; +use tokio::process::Command; use wasefire_cli_tools::cmd; -pub fn execute() -> Result<()> { - let paths = cmd::output(Command::new("git").args(["ls-files", ":(attr:textreview)"]))?; +pub async fn execute() -> Result<()> { + let paths = cmd::output(Command::new("git").args(["ls-files", ":(attr:textreview)"])).await?; let mut errors = Vec::new(); for path in paths.stdout.lines() { let path = path?; diff --git a/examples/rust/protocol/host/Cargo.toml b/examples/rust/protocol/host/Cargo.toml index 46d23aa8..416bbece 100644 --- a/examples/rust/protocol/host/Cargo.toml +++ b/examples/rust/protocol/host/Cargo.toml @@ -10,7 +10,7 @@ anyhow = "1.0.86" clap = { version = "4.5.4", features = ["derive"] } env_logger = "0.11.3" rusb = "0.9.4" -tokio = { version = "1.37.0", features = ["full"] } +tokio = { version = "1.40.0", features = ["full"] } wasefire-protocol = { path = "../../../../crates/protocol", features = ["host"] } wasefire-protocol-usb = { path = "../../../../crates/protocol-usb", features = ["host", "log"] } wasefire-wire = { path = "../../../../crates/wire" }