Skip to content

Commit

Permalink
chore(rs-bindgen): sync with generation with upstream
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Volosatovs <[email protected]>
  • Loading branch information
rvolosatovs committed Aug 16, 2024
1 parent 14edb36 commit 1b93bf6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 59 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion crates/wit-bindgen-rust-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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.
"""
Expand Down
2 changes: 1 addition & 1 deletion crates/wit-bindgen-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
62 changes: 14 additions & 48 deletions crates/wit-bindgen-rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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 _};
Expand Down Expand Up @@ -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 `<key>=<value>[,<key>=<value>...]`; 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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<String, WithOption>,
/// Whether to generate interfaces not present in the `with` map
pub generate_by_default: bool,
}

impl WithGeneration {
fn iter(&self) -> impl Iterator<Item = (&String, &WithOption)> {
self.with.iter()
}

pub fn extend(&mut self, with: HashMap<String, WithOption>) {
self.with.extend(with);
}
}

impl FromStr for WithGeneration {
type Err = String;

fn from_str(s: &str) -> std::prelude::v1::Result<Self, Self::Err> {
let with = s
.trim()
.split(',')
.map(|s| {
let (k, v) = s.trim().split_once('=').ok_or_else(|| {
format!("expected string of form `<key>=<value>[,<key>=<value>...]`; 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::<Result<HashMap<_, _>, Self::Err>>()?;
Ok(WithGeneration {
with,
generate_by_default: false,
})
}
}

/// Options for with "with" remappings.
#[derive(Debug, Clone)]
pub enum WithOption {
Expand Down
2 changes: 1 addition & 1 deletion crates/wit-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wit-bindgen-wrpc"
version = "0.6.0"
version = "0.6.1"
description = """
Rust bindings generator for wRPC.
"""
Expand Down

0 comments on commit 1b93bf6

Please sign in to comment.