Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement serde::Deserialize for wit-bindgen-rust::Opts #1244

Merged
merged 4 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ anyhow = "1.0.72"
bitflags = "2.3.3"
heck = { version = "0.5" }
pulldown-cmark = { version = "0.9", default-features = false }
serde = { version = "1.0.218", features = ["derive"] }
clap = { version = "4.3.19", features = ["derive"] }
indexmap = "2.0.0"
prettyplease = "0.2.20"
Expand Down
2 changes: 1 addition & 1 deletion crates/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ clap = { workspace = true, optional = true }
indexmap = { workspace = true }
syn = { workspace = true }
prettyplease = { workspace = true }
serde = { workspace = true, optional = true }

[dev-dependencies]
futures = { workspace = true }
wit-bindgen = { path = '../guest-rust', features = ['async'] }
wit-bindgen-rt = { path = '../guest-rust/rt' }
test-helpers = { path = '../test-helpers' }
# For use with the custom attributes test
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
26 changes: 26 additions & 0 deletions crates/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ enum RuntimeItem {
}

#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize),
serde(rename_all = "kebab-case")
)]
pub enum ExportKey {
World,
Name(String),
Expand All @@ -134,6 +139,11 @@ fn parse_with(s: &str) -> Result<(String, WithOption), String> {
}

#[derive(Default, Debug, Clone)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize),
serde(rename_all = "kebab-case")
)]
pub enum AsyncConfig {
#[default]
None,
Expand Down Expand Up @@ -181,6 +191,11 @@ fn parse_async(s: &str) -> Result<AsyncConfig, String> {

#[derive(Default, Debug, Clone)]
#[cfg_attr(feature = "clap", derive(clap::Parser))]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize),
serde(rename_all = "kebab-case")
)]
pub struct Opts {
/// Whether or not a formatter is executed to format generated code.
#[cfg_attr(feature = "clap", arg(long))]
Expand Down Expand Up @@ -315,6 +330,7 @@ pub struct Opts {
/// - import:<name> or
/// - export:<name>
#[cfg_attr(feature = "clap", arg(long = "async", value_parser = parse_async, default_value = "none"))]
#[cfg_attr(feature = "serde", serde(rename = "async"))]
pub async_: AsyncConfig,
}

Expand Down Expand Up @@ -1445,6 +1461,11 @@ fn group_by_resource<'a>(
}

#[derive(Default, Debug, Clone, Copy)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize),
serde(rename_all = "kebab-case")
)]
pub enum Ownership {
/// Generated types will be composed entirely of owning fields, regardless
/// of whether they are used as parameters to imports or not.
Expand Down Expand Up @@ -1499,6 +1520,11 @@ impl fmt::Display for Ownership {

/// Options for with "with" remappings.
#[derive(Debug, Clone)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize),
serde(rename_all = "kebab-case")
)]
pub enum WithOption {
Path(String),
Generate,
Expand Down
2 changes: 1 addition & 1 deletion crates/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ heck = { workspace = true }
log = "0.4.26"
rayon = "1.10.0"
regex = "1.11.1"
serde = { version = "1.0.218", features = ["derive"] }
serde = { workspace = true }
toml = "0.8.20"
wasi-preview1-component-adapter-provider = "30.0.2"
wac-parser = "0.6.1"
Expand Down