From 1b93bf6c74abcaff1dbc1e6ab821db2873713d17 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 16 Aug 2024 15:32:13 +0200 Subject: [PATCH] chore(rs-bindgen): sync `with` generation with upstream Signed-off-by: Roman Volosatovs --- Cargo.lock | 8 +-- Cargo.toml | 8 +-- crates/wit-bindgen-rust-macro/Cargo.toml | 2 +- crates/wit-bindgen-rust/Cargo.toml | 2 +- crates/wit-bindgen-rust/src/lib.rs | 62 ++++++------------------ crates/wit-bindgen/Cargo.toml | 2 +- 6 files changed, 25 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ea767ae3..f12833b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3571,7 +3571,7 @@ dependencies = [ [[package]] name = "wit-bindgen-wrpc" -version = "0.6.0" +version = "0.6.1" dependencies = [ "anyhow", "bitflags 2.6.0", @@ -3599,7 +3599,7 @@ dependencies = [ [[package]] name = "wit-bindgen-wrpc-rust" -version = "0.6.0" +version = "0.6.1" dependencies = [ "anyhow", "clap", @@ -3617,7 +3617,7 @@ dependencies = [ [[package]] name = "wit-bindgen-wrpc-rust-macro" -version = "0.6.0" +version = "0.6.1" dependencies = [ "anyhow", "prettyplease", @@ -3685,7 +3685,7 @@ dependencies = [ [[package]] name = "wrpc" -version = "0.6.0" +version = "0.6.1" dependencies = [ "anyhow", "async-nats-wrpc", diff --git a/Cargo.toml b/Cargo.toml index f3e271f5..2468f66f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] description = "WebAssembly component-native RPC framework based on WIT" name = "wrpc" -version = "0.6.0" +version = "0.6.1" authors.workspace = true categories.workspace = true @@ -130,10 +130,10 @@ wasmtime = { version = "23", default-features = false } wasmtime-wasi = { version = "23", default-features = false } wit-bindgen = { version = "0.30", default-features = false } wit-bindgen-core = { version = "0.30", default-features = false } -wit-bindgen-wrpc = { version = "0.6", default-features = false, path = "./crates/wit-bindgen" } +wit-bindgen-wrpc = { version = "0.6.1", default-features = false, path = "./crates/wit-bindgen" } wit-bindgen-wrpc-go = { version = "0.4", default-features = false, path = "./crates/wit-bindgen-go" } -wit-bindgen-wrpc-rust = { version = "0.6", default-features = false, path = "./crates/wit-bindgen-rust" } -wit-bindgen-wrpc-rust-macro = { version = "0.6", default-features = false, path = "./crates/wit-bindgen-rust-macro" } +wit-bindgen-wrpc-rust = { version = "0.6.1", default-features = false, path = "./crates/wit-bindgen-rust" } +wit-bindgen-wrpc-rust-macro = { version = "0.6.1", default-features = false, path = "./crates/wit-bindgen-rust-macro" } wit-component = { version = "0.215", default-features = false } wit-parser = { version = "0.215", default-features = false } wrpc-cli = { version = "0.2.1", path = "./crates/cli", default-features = false } diff --git a/crates/wit-bindgen-rust-macro/Cargo.toml b/crates/wit-bindgen-rust-macro/Cargo.toml index 8046a7ba..0be4f70f 100644 --- a/crates/wit-bindgen-rust-macro/Cargo.toml +++ b/crates/wit-bindgen-rust-macro/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wit-bindgen-wrpc-rust-macro" -version = "0.6.0" +version = "0.6.1" description = """ Procedural macro paired with the `wit-bindgen-wrpc` crate. """ diff --git a/crates/wit-bindgen-rust/Cargo.toml b/crates/wit-bindgen-rust/Cargo.toml index 96641fe6..4b0ab714 100644 --- a/crates/wit-bindgen-rust/Cargo.toml +++ b/crates/wit-bindgen-rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wit-bindgen-wrpc-rust" -version = "0.6.0" +version = "0.6.1" description = """ Rust bindings generator for wRPC, typically used through the `wit-bindgen-wrpc` crate's `generate!` macro. diff --git a/crates/wit-bindgen-rust/src/lib.rs b/crates/wit-bindgen-rust/src/lib.rs index 67c149f4..ed6fafe7 100644 --- a/crates/wit-bindgen-rust/src/lib.rs +++ b/crates/wit-bindgen-rust/src/lib.rs @@ -1,6 +1,5 @@ use crate::interface::InterfaceGenerator; use anyhow::{bail, Result}; -use core::str::FromStr; use heck::{ToSnakeCase, ToUpperCamelCase}; use std::collections::{BTreeMap, HashMap, HashSet}; use std::fmt::{self, Write as _}; @@ -76,6 +75,18 @@ enum InterfaceGeneration { Generate, } +#[cfg(feature = "clap")] +fn parse_with(s: &str) -> Result<(String, WithOption), String> { + let (k, v) = s.split_once('=').ok_or_else(|| { + format!("expected string of form `=[,=...]`; got `{s}`") + })?; + let v = match v { + "generate" => WithOption::Generate, + other => WithOption::Path(other.to_string()), + }; + Ok((k.to_string(), v)) +} + #[derive(Default, Debug, Clone)] #[cfg_attr(feature = "clap", derive(clap::Args))] pub struct Opts { @@ -105,8 +116,8 @@ pub struct Opts { /// Argument must be of the form `k=v` and this option can be passed /// multiple times or one option can be comma separated, for example /// `k1=v1,k2=v2`. - #[cfg_attr(feature = "clap", arg(long, value_parser = clap::value_parser!(WithGeneration), value_delimiter = ','))] - pub with: WithGeneration, + #[cfg_attr(feature = "clap", arg(long, value_parser = parse_with, value_delimiter = ','))] + pub with: Vec<(String, WithOption)>, /// Indicates that all interfaces not specified in `with` should be /// generated. @@ -664,51 +675,6 @@ enum Identifier<'a> { Interface(InterfaceId, &'a WorldKey), } -/// Configuration for how interfaces are generated. -#[derive(Debug, Clone, Default)] -pub struct WithGeneration { - /// How interface should be generated - with: HashMap, - /// Whether to generate interfaces not present in the `with` map - pub generate_by_default: bool, -} - -impl WithGeneration { - fn iter(&self) -> impl Iterator { - self.with.iter() - } - - pub fn extend(&mut self, with: HashMap) { - self.with.extend(with); - } -} - -impl FromStr for WithGeneration { - type Err = String; - - fn from_str(s: &str) -> std::prelude::v1::Result { - let with = s - .trim() - .split(',') - .map(|s| { - let (k, v) = s.trim().split_once('=').ok_or_else(|| { - format!("expected string of form `=[,=...]`; got `{s}`") - })?; - let k = k.trim().to_string(); - let v = match v.trim() { - "generate" => WithOption::Generate, - v => WithOption::Path(v.to_string()), - }; - Ok((k, v)) - }) - .collect::, Self::Err>>()?; - Ok(WithGeneration { - with, - generate_by_default: false, - }) - } -} - /// Options for with "with" remappings. #[derive(Debug, Clone)] pub enum WithOption { diff --git a/crates/wit-bindgen/Cargo.toml b/crates/wit-bindgen/Cargo.toml index 7df81a9d..1df4c1f7 100644 --- a/crates/wit-bindgen/Cargo.toml +++ b/crates/wit-bindgen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wit-bindgen-wrpc" -version = "0.6.0" +version = "0.6.1" description = """ Rust bindings generator for wRPC. """