From 9c1046283b11666d5ea36e1d7698f6368ee58a60 Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Wed, 26 Jun 2024 15:17:00 +0200 Subject: [PATCH] Add wasefire applet-rpc command (#517) --- crates/cli-tools/CHANGELOG.md | 2 +- crates/cli-tools/Cargo.lock | 175 ++++++++++++++++++++++- crates/cli-tools/Cargo.toml | 8 ++ crates/cli-tools/src/action.rs | 56 +++++++- crates/cli-tools/src/fs.rs | 14 +- crates/cli/CHANGELOG.md | 2 + crates/cli/Cargo.lock | 20 +++ crates/cli/Cargo.toml | 3 +- crates/cli/src/main.rs | 82 +++++++++-- crates/protocol-usb/CHANGELOG.md | 2 +- crates/protocol-usb/src/host.rs | 5 +- crates/protocol/CHANGELOG.md | 2 +- crates/protocol/crates/schema/Cargo.lock | 127 +++++++++++++++- crates/protocol/src/applet.rs | 2 +- crates/xtask/Cargo.lock | 128 +++++++++++++++++ 15 files changed, 600 insertions(+), 28 deletions(-) diff --git a/crates/cli-tools/CHANGELOG.md b/crates/cli-tools/CHANGELOG.md index 6a0f3ab3..fa523218 100644 --- a/crates/cli-tools/CHANGELOG.md +++ b/crates/cli-tools/CHANGELOG.md @@ -2,4 +2,4 @@ ## 0.1.0-git - + diff --git a/crates/cli-tools/Cargo.lock b/crates/cli-tools/Cargo.lock index 7063c259..5bd3b68c 100644 --- a/crates/cli-tools/Cargo.lock +++ b/crates/cli-tools/Cargo.lock @@ -46,6 +46,12 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cc" +version = "1.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac367972e516d45567c7eafc73d24e1c193dcf200a8d94e9db7b3d38b349572d" + [[package]] name = "clap" version = "4.5.4" @@ -75,7 +81,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -84,6 +90,17 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -102,6 +119,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "indexmap" version = "2.2.6" @@ -118,12 +141,62 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "libusb1-sys" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da050ade7ac4ff1ba5379af847a10a10a8e284181e060105bf8d86960ce9ce0f" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + [[package]] name = "memchr" version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +[[package]] +name = "num_enum" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + [[package]] name = "proc-macro2" version = "1.0.83" @@ -142,6 +215,16 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rusb" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab9f9ff05b63a786553a4c02943b74b34a988448671001e9a27e2f0565cc05a4" +dependencies = [ + "libc", + "libusb1-sys", +] + [[package]] name = "ryu" version = "1.0.18" @@ -174,7 +257,7 @@ checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -197,6 +280,17 @@ dependencies = [ "serde", ] +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.66" @@ -225,7 +319,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -268,6 +362,22 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "wasefire-board-api" +version = "0.7.0-git" +dependencies = [ + "derivative", + "wasefire-error", + "wasefire-logger", + "wasefire-store", +] + [[package]] name = "wasefire-cli-tools" version = "0.1.0-git" @@ -275,8 +385,67 @@ dependencies = [ "anyhow", "cargo_metadata", "clap", + "humantime", + "rusb", "serde", "toml", + "wasefire-protocol", + "wasefire-protocol-usb", +] + +[[package]] +name = "wasefire-error" +version = "0.1.1-git" +dependencies = [ + "num_enum", +] + +[[package]] +name = "wasefire-logger" +version = "0.1.5-git" +dependencies = [ + "log", +] + +[[package]] +name = "wasefire-protocol" +version = "0.1.0-git" +dependencies = [ + "wasefire-error", + "wasefire-wire", +] + +[[package]] +name = "wasefire-protocol-usb" +version = "0.1.0-git" +dependencies = [ + "anyhow", + "rusb", + "wasefire-board-api", + "wasefire-logger", + "wasefire-protocol", + "wasefire-wire", +] + +[[package]] +name = "wasefire-store" +version = "0.2.4-git" + +[[package]] +name = "wasefire-wire" +version = "0.1.0-git" +dependencies = [ + "wasefire-error", + "wasefire-wire-derive", +] + +[[package]] +name = "wasefire-wire-derive" +version = "0.1.0-git" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", ] [[package]] diff --git a/crates/cli-tools/Cargo.toml b/crates/cli-tools/Cargo.toml index 3f593ba7..d0045b2e 100644 --- a/crates/cli-tools/Cargo.toml +++ b/crates/cli-tools/Cargo.toml @@ -15,8 +15,16 @@ categories = ["command-line-utilities", "embedded", "wasm"] anyhow = { version = "1.0.86", default-features = false, features = ["std"] } cargo_metadata = { version = "0.18.1", default-features = false } clap = { version = "4.5.4", default-features = false, features = ["derive", "std"] } +humantime = { version = "2.1.0", default-features = false } +rusb = { version = "0.9.4", default-features = false } serde = { version = "1.0.202", default-features = false, features = ["derive"] } toml = { version = "0.8.13", default-features = false, features = ["display", "parse"] } +wasefire-protocol = { version = "0.1.0-git", path = "../protocol" } + +[dependencies.wasefire-protocol-usb] +version = "0.1.0-git" +path = "../protocol-usb" +features = ["host", "log"] [lints] clippy.unit-arg = "allow" diff --git a/crates/cli-tools/src/action.rs b/crates/cli-tools/src/action.rs index 776bb294..a482b3a9 100644 --- a/crates/cli-tools/src/action.rs +++ b/crates/cli-tools/src/action.rs @@ -15,13 +15,67 @@ use std::fmt::Display; use std::path::{Path, PathBuf}; use std::process::Command; +use std::time::Duration; -use anyhow::{ensure, Result}; +use anyhow::{bail, ensure, Result}; use cargo_metadata::{Metadata, MetadataCommand}; use clap::{ValueEnum, ValueHint}; +use rusb::UsbContext; +use wasefire_protocol::{applet, AppletRequest, AppletResponse}; +use wasefire_protocol_usb::Connection; use crate::{cmd, fs}; +/// Calls an RPC to an applet on a platform. +#[derive(clap::Args)] +pub struct AppletRpc { + /// Applet identifier in the platform. + applet: Option, + + /// Reads the request from this file instead of standard input. + #[arg(long, value_hint = ValueHint::FilePath)] + input: Option, + + /// Writes the response to this file instead of standard output. + #[arg(long, value_hint = ValueHint::AnyPath)] + output: Option, + + /// Timeout to send the request and try receiving the response. + #[arg(long, value_parser = humantime::parse_duration, default_value = "1s")] + timeout: Duration, + + /// Number of retries to receive a response. + #[arg(long, default_value = "3")] + retries: usize, +} + +impl AppletRpc { + pub fn run(self, connection: &Connection) -> Result<()> { + let AppletRpc { applet, input, output, timeout, retries } = self; + let applet_id = match applet { + Some(_) => bail!("applet identifiers are not supported yet"), + None => applet::AppletId, + }; + let input = match input { + Some(path) => fs::read(path)?, + None => fs::read_stdin()?, + }; + let request = applet::Request { applet_id, request: &input }; + connection.call::(request, timeout)?.get(); + for _ in 0 .. retries { + let response = connection.call::(applet_id, timeout)?; + if let Some(response) = response.get().response { + match output { + Some(path) => fs::write(path, response)?, + None => fs::write_stdout(response)?, + } + return Ok(()); + } + } + bail!("did not receive a response after {retries} retries"); + } +} + /// Creates a new Rust applet project. #[derive(clap::Args)] pub struct RustAppletNew { diff --git a/crates/cli-tools/src/fs.rs b/crates/cli-tools/src/fs.rs index 7c8a613f..44ef1489 100644 --- a/crates/cli-tools/src/fs.rs +++ b/crates/cli-tools/src/fs.rs @@ -15,7 +15,7 @@ //! Wrappers around `std::fs` with descriptive errors. use std::fs::Metadata; -use std::io::ErrorKind; +use std::io::{ErrorKind, Read, Write}; use std::path::{Component, Path, PathBuf}; use anyhow::{Context, Result}; @@ -113,6 +113,12 @@ pub fn read_toml(path: impl AsRef) -> Result { toml::from_str(&data).with_context(|| format!("parsing {name}")) } +pub fn read_stdin() -> Result> { + let mut data = Vec::new(); + std::io::stdin().read_to_end(&mut data).context("reading from stdin")?; + Ok(data) +} + pub fn remove_file(path: impl AsRef) -> Result<()> { let name = path.as_ref().display(); debug!("rm {name:?}"); @@ -142,6 +148,12 @@ pub fn write_toml(path: impl AsRef, contents: &T) -> Result< Ok(()) } +pub fn write_stdout(contents: impl AsRef<[u8]>) -> Result<()> { + let contents = contents.as_ref(); + std::io::stdout().write_all(contents).context("writing to stdout")?; + Ok(()) +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/cli/CHANGELOG.md b/crates/cli/CHANGELOG.md index 37e3be02..063129a4 100644 --- a/crates/cli/CHANGELOG.md +++ b/crates/cli/CHANGELOG.md @@ -4,6 +4,8 @@ ### Minor +- Implement `applet-rpc` command +- Add `--serial` and `WASEFIRE_SERIAL` to select the platform - Implement `platform-list` command - Support creating, building, and testing a Rust applet - Support generating a shell completion file diff --git a/crates/cli/Cargo.lock b/crates/cli/Cargo.lock index aa6de267..93a925b1 100644 --- a/crates/cli/Cargo.lock +++ b/crates/cli/Cargo.lock @@ -185,6 +185,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "indexmap" version = "2.2.6" @@ -225,6 +231,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + [[package]] name = "memchr" version = "2.7.2" @@ -458,6 +470,7 @@ dependencies = [ "clap", "clap_complete", "data-encoding", + "rusb", "wasefire-cli-tools", "wasefire-protocol", "wasefire-protocol-usb", @@ -470,8 +483,12 @@ dependencies = [ "anyhow", "cargo_metadata", "clap", + "humantime", + "rusb", "serde", "toml", + "wasefire-protocol", + "wasefire-protocol-usb", ] [[package]] @@ -484,6 +501,9 @@ dependencies = [ [[package]] name = "wasefire-logger" version = "0.1.5-git" +dependencies = [ + "log", +] [[package]] name = "wasefire-protocol" diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 92dbbaed..2edd0509 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -17,9 +17,10 @@ path = "src/main.rs" [dependencies] anyhow = { version = "1.0.86", default-features = false } -clap = { version = "4.5.4", default-features = false, features = ["default", "derive"] } +clap = { version = "4.5.4", default-features = false, features = ["default", "derive", "env"] } clap_complete = { version = "4.5.2", default-features = false } data-encoding = { version = "2.6.0", default-features = false, features = ["std"] } +rusb = { version = "0.9.4", default-features = false } wasefire-cli-tools = { version = "0.1.0-git", path = "../cli-tools" } wasefire-protocol = { version = "0.1.0-git", path = "../protocol", features = ["host"] } wasefire-protocol-usb = { version = "0.1.0-git", path = "../protocol-usb", features = ["host"] } diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index f306a66d..0a24387b 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -12,17 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![feature(try_find)] + use std::fs::File; use std::io::Write; use std::path::{Path, PathBuf}; +use std::sync::Mutex; use std::time::Duration; use anyhow::{bail, Result}; use clap::{CommandFactory, Parser, ValueHint}; use clap_complete::Shell; use data_encoding::HEXLOWER_PERMISSIVE as HEX; +use rusb::GlobalContext; use wasefire_cli_tools::{action, fs}; use wasefire_protocol::{self as service, platform}; +use wasefire_protocol_usb::{Candidate, Connection}; #[derive(Parser)] #[command(version, about)] @@ -35,7 +40,11 @@ struct Flags { } #[derive(clap::Args)] -struct Options {} +struct Options { + /// Serial of the platform to connect to. + #[arg(long, env = "WASEFIRE_SERIAL")] + serial: Option, +} #[derive(clap::Subcommand)] enum Action { @@ -51,6 +60,8 @@ enum Action { /// Uninstalls an applet from a platform. AppletUninstall, + AppletRpc(action::AppletRpc), + /// Lists the connected platforms. PlatformList, @@ -75,12 +86,6 @@ struct Completion { output: PathBuf, } -impl Options { - fn run(&self) -> Result<()> { - Ok(()) - } -} - impl Completion { fn run(&self) -> Result<()> { let shell = match self.shell.or_else(Shell::from_env) { @@ -102,13 +107,14 @@ impl Completion { fn main() -> Result<()> { let flags = Flags::parse(); - flags.options.run()?; + CONNECTION.lock().unwrap().set(flags.options.serial); let dir = std::env::current_dir()?; match flags.action { Action::AppletList => bail!("not implemented yet"), Action::AppletInstall => bail!("not implemented yet"), Action::AppletUpdate => bail!("not implemented yet"), Action::AppletUninstall => bail!("not implemented yet"), + Action::AppletRpc(x) => x.run(CONNECTION.lock().unwrap().get()?), Action::PlatformList => platform_list(), Action::PlatformUpdate => bail!("not implemented yet"), Action::RustAppletNew(x) => x.run(), @@ -118,8 +124,35 @@ fn main() -> Result<()> { } } +enum GlobalConnection { + Invalid, + Ready { serial: Option }, + Connected { connection: Connection }, +} + +impl GlobalConnection { + fn set(&mut self, serial: Option) { + match self { + GlobalConnection::Invalid => *self = GlobalConnection::Ready { serial }, + _ => unreachable!(), + } + } + + fn get(&mut self) -> Result<&Connection> { + if let GlobalConnection::Ready { serial } = self { + *self = GlobalConnection::Connected { connection: connect(serial.as_deref())? }; + } + match self { + GlobalConnection::Connected { connection } => Ok(connection), + _ => unreachable!(), + } + } +} + +static CONNECTION: Mutex = Mutex::new(GlobalConnection::Invalid); + fn platform_list() -> Result<()> { - let context = wasefire_protocol_usb::GlobalContext::default(); + let context = GlobalContext::default(); let candidates = wasefire_protocol_usb::list(&context)?; println!("There are {} connected platforms:", candidates.len()); for candidate in candidates { @@ -128,9 +161,38 @@ fn platform_list() -> Result<()> { let platform::Info { serial, version } = info.get(); let serial = HEX.encode(serial); let version = HEX.encode(version); - println!("- serial:{serial} version:{version}"); + println!("- serial={serial} version={version}"); } Ok(()) } +fn connect(serial: Option<&str>) -> Result> { + let context = GlobalContext::default(); + let mut candidates = wasefire_protocol_usb::list(&context)?; + let candidate = match (serial, candidates.len()) { + (None, 0) => bail!("no connected platforms"), + (None, 1) => candidates.pop().unwrap(), + (None, n) => { + eprintln!("Choose one of the {n} connected platforms using its --serial option:"); + for candidate in candidates { + eprintln!(" --serial={}", get_serial(&candidate)?); + } + bail!("more than one connected platform"); + } + (Some(serial), _) => { + match candidates.into_iter().try_find(|x| anyhow::Ok(get_serial(x)? == serial))? { + Some(x) => x, + None => bail!("no connected platform with serial={serial}"), + } + } + }; + Ok(candidate.connect()?) +} + +fn get_serial(candidate: &Candidate) -> Result { + let connection = candidate.clone().connect()?; + let info = connection.call::((), TIMEOUT)?; + Ok(HEX.encode(info.get().serial)) +} + const TIMEOUT: Duration = Duration::from_secs(1); diff --git a/crates/protocol-usb/CHANGELOG.md b/crates/protocol-usb/CHANGELOG.md index 57aca747..979be374 100644 --- a/crates/protocol-usb/CHANGELOG.md +++ b/crates/protocol-usb/CHANGELOG.md @@ -2,4 +2,4 @@ ## 0.1.0-git - + diff --git a/crates/protocol-usb/src/host.rs b/crates/protocol-usb/src/host.rs index 7ad90d6b..a9d46e81 100644 --- a/crates/protocol-usb/src/host.rs +++ b/crates/protocol-usb/src/host.rs @@ -19,7 +19,6 @@ use std::io::Write; use std::time::Duration; use anyhow::{anyhow, ensure, Context}; -pub use rusb::GlobalContext; use rusb::{Device, DeviceHandle, Error, TransferType, UsbContext}; use wasefire_logger as log; use wasefire_protocol::{Api, ApiResult, Request, Service}; @@ -31,7 +30,7 @@ use crate::common::{Decoder, Encoder}; /// /// If there are multiple supported device, asks the user to select one. /// -/// The context may be `GlobalContext::default()`. +/// The context may be `rusb::GlobalContext::default()`. pub fn choose_device(context: &T) -> anyhow::Result> { let mut candidates = list(context)?; let candidate = candidates.pop().ok_or_else(|| anyhow!("no device found"))?; @@ -57,7 +56,7 @@ pub fn choose_device(context: &T) -> anyhow::Result> /// Returns the list of supported devices. /// -/// The context may be `GlobalContext::default()`. +/// The context may be `rusb::GlobalContext::default()`. pub fn list(context: &T) -> anyhow::Result>> { let mut candidates = Vec::new(); for device in context.devices()?.iter() { diff --git a/crates/protocol/CHANGELOG.md b/crates/protocol/CHANGELOG.md index de05a2dc..6a0f3ab3 100644 --- a/crates/protocol/CHANGELOG.md +++ b/crates/protocol/CHANGELOG.md @@ -2,4 +2,4 @@ ## 0.1.0-git - + diff --git a/crates/protocol/crates/schema/Cargo.lock b/crates/protocol/crates/schema/Cargo.lock index 4c8170a0..4e0cb92a 100644 --- a/crates/protocol/crates/schema/Cargo.lock +++ b/crates/protocol/crates/schema/Cargo.lock @@ -46,6 +46,12 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cc" +version = "1.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac367972e516d45567c7eafc73d24e1c193dcf200a8d94e9db7b3d38b349572d" + [[package]] name = "clap" version = "4.5.4" @@ -75,7 +81,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -84,6 +90,17 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -102,6 +119,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "indexmap" version = "2.2.6" @@ -118,6 +141,30 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "libusb1-sys" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da050ade7ac4ff1ba5379af847a10a10a8e284181e060105bf8d86960ce9ce0f" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + [[package]] name = "memchr" version = "2.7.2" @@ -141,9 +188,15 @@ checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + [[package]] name = "proc-macro2" version = "1.0.84" @@ -162,6 +215,16 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rusb" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab9f9ff05b63a786553a4c02943b74b34a988448671001e9a27e2f0565cc05a4" +dependencies = [ + "libc", + "libusb1-sys", +] + [[package]] name = "ryu" version = "1.0.18" @@ -205,7 +268,7 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -228,6 +291,17 @@ dependencies = [ "serde", ] +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.66" @@ -256,7 +330,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -299,6 +373,22 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "wasefire-board-api" +version = "0.7.0-git" +dependencies = [ + "derivative", + "wasefire-error", + "wasefire-logger", + "wasefire-store", +] + [[package]] name = "wasefire-cli-tools" version = "0.1.0-git" @@ -306,8 +396,12 @@ dependencies = [ "anyhow", "cargo_metadata", "clap", + "humantime", + "rusb", "serde", "toml", + "wasefire-protocol", + "wasefire-protocol-usb", ] [[package]] @@ -317,6 +411,13 @@ dependencies = [ "num_enum", ] +[[package]] +name = "wasefire-logger" +version = "0.1.5-git" +dependencies = [ + "log", +] + [[package]] name = "wasefire-protocol" version = "0.1.0-git" @@ -325,6 +426,22 @@ dependencies = [ "wasefire-wire", ] +[[package]] +name = "wasefire-protocol-usb" +version = "0.1.0-git" +dependencies = [ + "anyhow", + "rusb", + "wasefire-board-api", + "wasefire-logger", + "wasefire-protocol", + "wasefire-wire", +] + +[[package]] +name = "wasefire-store" +version = "0.2.4-git" + [[package]] name = "wasefire-wire" version = "0.1.0-git" @@ -339,7 +456,7 @@ version = "0.1.0-git" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] diff --git a/crates/protocol/src/applet.rs b/crates/protocol/src/applet.rs index 13330d0d..b2f1ebe2 100644 --- a/crates/protocol/src/applet.rs +++ b/crates/protocol/src/applet.rs @@ -25,7 +25,7 @@ pub struct Response<'a> { pub response: Option<&'a [u8]>, } -#[derive(Debug, Wire)] +#[derive(Debug, Copy, Clone, Wire)] pub struct AppletId; #[derive(Debug, Wire)] diff --git a/crates/xtask/Cargo.lock b/crates/xtask/Cargo.lock index 6df750d5..b9d6c477 100644 --- a/crates/xtask/Cargo.lock +++ b/crates/xtask/Cargo.lock @@ -416,6 +416,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "digest" version = "0.10.7" @@ -821,6 +832,18 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "libusb1-sys" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da050ade7ac4ff1ba5379af847a10a10a8e284181e060105bf8d86960ce9ce0f" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -926,6 +949,26 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_enum" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "nusb" version = "0.1.9" @@ -1184,6 +1227,16 @@ dependencies = [ "serde", ] +[[package]] +name = "rusb" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab9f9ff05b63a786553a4c02943b74b34a988448671001e9a27e2f0565cc05a4" +dependencies = [ + "libc", + "libusb1-sys", +] + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -1609,12 +1662,28 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "wasefire-board-api" +version = "0.7.0-git" +dependencies = [ + "derivative", + "wasefire-error", + "wasefire-logger", + "wasefire-store", +] + [[package]] name = "wasefire-cli-tools" version = "0.1.0-git" @@ -1622,8 +1691,67 @@ dependencies = [ "anyhow", "cargo_metadata", "clap", + "humantime", + "rusb", "serde", "toml", + "wasefire-protocol", + "wasefire-protocol-usb", +] + +[[package]] +name = "wasefire-error" +version = "0.1.1-git" +dependencies = [ + "num_enum", +] + +[[package]] +name = "wasefire-logger" +version = "0.1.5-git" +dependencies = [ + "log", +] + +[[package]] +name = "wasefire-protocol" +version = "0.1.0-git" +dependencies = [ + "wasefire-error", + "wasefire-wire", +] + +[[package]] +name = "wasefire-protocol-usb" +version = "0.1.0-git" +dependencies = [ + "anyhow", + "rusb", + "wasefire-board-api", + "wasefire-logger", + "wasefire-protocol", + "wasefire-wire", +] + +[[package]] +name = "wasefire-store" +version = "0.2.4-git" + +[[package]] +name = "wasefire-wire" +version = "0.1.0-git" +dependencies = [ + "wasefire-error", + "wasefire-wire-derive", +] + +[[package]] +name = "wasefire-wire-derive" +version = "0.1.0-git" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", ] [[package]]