diff --git a/Cargo.toml b/Cargo.toml index 67cedcc86..0a2388fd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/crates/rust/Cargo.toml b/crates/rust/Cargo.toml index 3a6ea5952..91cbbe1cc 100644 --- a/crates/rust/Cargo.toml +++ b/crates/rust/Cargo.toml @@ -25,6 +25,7 @@ clap = { workspace = true, optional = true } indexmap = { workspace = true } syn = { workspace = true } prettyplease = { workspace = true } +serde = { workspace = true, optional = true } [dev-dependencies] futures = { workspace = true } @@ -32,5 +33,4 @@ 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" diff --git a/crates/rust/src/lib.rs b/crates/rust/src/lib.rs index 1f7151b4f..15f5f701b 100644 --- a/crates/rust/src/lib.rs +++ b/crates/rust/src/lib.rs @@ -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), @@ -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, @@ -181,6 +191,11 @@ fn parse_async(s: &str) -> Result { #[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))] @@ -315,6 +330,7 @@ pub struct Opts { /// - import: or /// - export: #[cfg_attr(feature = "clap", arg(long = "async", value_parser = parse_async, default_value = "none"))] + #[cfg_attr(feature = "serde", serde(rename = "async"))] pub async_: AsyncConfig, } @@ -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. @@ -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, diff --git a/crates/test/Cargo.toml b/crates/test/Cargo.toml index 365139e16..afe8034d7 100644 --- a/crates/test/Cargo.toml +++ b/crates/test/Cargo.toml @@ -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"