Skip to content

Commit

Permalink
Upgrade workspace (including syn v2)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Jul 9, 2024
1 parent 2497823 commit c41c53c
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 92 deletions.
6 changes: 3 additions & 3 deletions specta-datatype-from/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ categories = ["web-programming", "asynchronous"]
proc-macro = true

[dependencies]
proc-macro2 = "1.0.49"
quote = "1.0.23"
syn = { version = "1.0.107", features = ["full"] }
proc-macro2 = "1.0.86"
quote = "1.0.36"
syn = { version = "2.0.70", default-features = false, features = [] }
Inflector = { version = "0.11.4", default-features = false }
4 changes: 2 additions & 2 deletions specta-datatype-from/src/data_type_from/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod attr;

use quote::{quote, ToTokens};
use syn::{parse_macro_input, Data, DeriveInput, Fields};
use syn::{parse, Data, DeriveInput, Fields};

use attr::*;

Expand All @@ -14,7 +14,7 @@ pub fn derive(input: proc_macro::TokenStream) -> syn::Result<proc_macro::TokenSt
attrs,
generics,
..
} = &parse_macro_input::parse::<DeriveInput>(input)?;
} = &parse::<DeriveInput>(input)?;

let mut attrs = parse_attrs(attrs)?;
let container_attrs = ContainerAttr::from_attrs(&mut attrs)?;
Expand Down
4 changes: 2 additions & 2 deletions specta-datatype-from/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub fn parse_attrs(attrs: &[syn::Attribute]) -> syn::Result<Vec<Attribute>> {

for attr in attrs {
let ident = attr
.path
.path()
.segments
.last()
.expect("Attribute path must have at least one segment")
Expand Down Expand Up @@ -205,7 +205,7 @@ pub fn parse_attrs(attrs: &[syn::Attribute]) -> syn::Result<Vec<Attribute>> {
},
})
};
let attr = syn::parse::Parser::parse2(parser, attr.tokens.clone().into())?;
let attr = attr.parse_args_with(parser)?;
result.push(attr);
}

Expand Down
2 changes: 1 addition & 1 deletion specta-go/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ categories = ["web-programming", "asynchronous"]

[dependencies]
specta = { path = "../specta" }
thiserror = "1.0.60"
thiserror = "1.0.61"
6 changes: 3 additions & 3 deletions specta-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function = []
export = []

[dependencies]
proc-macro2 = "1.0.49"
quote = "1.0.23"
syn = { version = "1.0.107", features = ["full"] }
proc-macro2 = "1.0.86"
quote = "1.0.36"
syn = { version = "2.0.70", default-features = false, features = [] }
Inflector = { version = "0.11.4", default-features = false }
4 changes: 2 additions & 2 deletions specta-macros/src/specta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use std::str::FromStr;

use proc_macro2::TokenStream;
use quote::{quote, ToTokens};
use syn::{parse_macro_input, FnArg, ItemFn, Pat, Visibility};
use syn::{parse, FnArg, ItemFn, Pat, Visibility};

use crate::utils::{format_fn_wrapper, parse_attrs};

pub fn attribute(item: proc_macro::TokenStream) -> syn::Result<proc_macro::TokenStream> {
let crate_ref = quote!(specta);
let function = parse_macro_input::parse::<ItemFn>(item)?;
let function = parse::<ItemFn>(item)?;
let wrapper = format_fn_wrapper(&function.sig.ident);

// While using wasm_bindgen and Specta is rare, this should make the DX nicer.
Expand Down
6 changes: 3 additions & 3 deletions specta-macros/src/type/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use proc_macro2::{Span, TokenStream};
use quote::{format_ident, quote, ToTokens};
use syn::{
parse_quote, spanned::Spanned, ConstParam, Error, GenericArgument, GenericParam, Generics,
Ident, LifetimeDef, PathArguments, Type, TypeArray, TypeParam, TypePtr, TypeReference,
Ident, LifetimeParam, PathArguments, Type, TypeArray, TypeParam, TypePtr, TypeReference,
TypeSlice, WhereClause,
};

Expand All @@ -17,7 +17,7 @@ pub fn generics_with_ident_and_bounds_only(generics: &Generics) -> Option<TokenS
bounds,
..
}) => quote!(#ident #colon_token #bounds),
Lifetime(LifetimeDef {
Lifetime(LifetimeParam {
lifetime,
colon_token,
bounds,
Expand All @@ -42,7 +42,7 @@ pub fn generics_with_ident_only(generics: &Generics) -> Option<TokenStream> {

generics.params.iter().map(|param| match param {
Type(TypeParam { ident, .. }) | Const(ConstParam { ident, .. }) => quote!(#ident),
Lifetime(LifetimeDef { lifetime, .. }) => quote!(#lifetime),
Lifetime(LifetimeParam { lifetime, .. }) => quote!(#lifetime),
})
})
.map(|gs| quote!(<#(#gs),*>))
Expand Down
4 changes: 2 additions & 2 deletions specta-macros/src/type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use proc_macro2::TokenStream;
use quote::{format_ident, quote, ToTokens};
use r#enum::parse_enum;
use r#struct::parse_struct;
use syn::{parse_macro_input, Data, DeriveInput};
use syn::{parse, Data, DeriveInput};

use generics::impl_heading;

Expand All @@ -25,7 +25,7 @@ pub fn derive(input: proc_macro::TokenStream) -> syn::Result<proc_macro::TokenSt
data,
attrs,
..
} = &parse_macro_input::parse::<DeriveInput>(input)?;
} = &parse::<DeriveInput>(input)?;

// We pass all the attributes at the start and when decoding them pop them off the list.
// This means at the end we can check for any that weren't consumed and throw an error.
Expand Down
56 changes: 20 additions & 36 deletions specta-macros/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use proc_macro2::{Span, TokenStream};
use quote::quote;
use quote::{quote, ToTokens};
use syn::{
ext::IdentExt,
parenthesized,
parse::{Parse, ParseStream},
spanned::Spanned,
token::Paren,
Ident, Lit, Path, Result, Token,
Ident, Lit, Meta, Path, Result, Token,
};

#[derive(Clone)]
Expand Down Expand Up @@ -113,19 +112,9 @@ impl Attribute {
}
}

fn parse_attribute(input: ParseStream) -> Result<Vec<Attribute>> {
// (demo = "hello")
// ^ ^
let content_owned;
let content;
if input.peek(Paren) {
parenthesized!(content_owned in input);
content = &content_owned;
} else {
content = input;
}

fn parse_attribute(content: ParseStream) -> Result<Vec<Attribute>> {
let mut result = Vec::new();

while !content.is_empty() {
// (demo = "hello")
// ^^^^
Expand Down Expand Up @@ -167,7 +156,7 @@ pub fn parse_attrs(attrs: &[syn::Attribute]) -> syn::Result<Vec<Attribute>> {

for attr in attrs {
let ident = attr
.path
.path()
.segments
.last()
.expect("Attribute path must have at least one segment")
Expand All @@ -184,27 +173,22 @@ pub fn parse_attrs(attrs: &[syn::Attribute]) -> syn::Result<Vec<Attribute>> {
continue;
}

let parser = |input: ParseStream| {
Ok(Attribute {
result.append(&mut match &attr.meta {
Meta::Path(_) => vec![Attribute {
key: ident.clone(),
value: match false {
// `#[demo]`
_ if input.is_empty() => None,
// `#[demo = "todo"]`
_ if input.peek(Token![=]) => {
input.parse::<Token![=]>()?;
Some(AttributeValue::parse(input)?)
}
// `#[demo(...)]`
_ => Some(AttributeValue::Attribute {
span: ident.span(),
attr: parse_attribute(input)?,
}),
},
})
};
let attr = syn::parse::Parser::parse2(parser, attr.tokens.clone().into())?;
result.push(attr);
value: None,
}],
Meta::List(meta) => vec![Attribute {
key: ident.clone(),
value: Some(AttributeValue::Attribute {
span: ident.span(),
attr: syn::parse::Parser::parse2(parse_attribute, meta.tokens.clone())?,
}),
}],
Meta::NameValue(meta) => {
syn::parse::Parser::parse2(parse_attribute, meta.to_token_stream().clone())?
}
});
}

Ok(result)
Expand Down
2 changes: 1 addition & 1 deletion specta-openapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ categories = ["web-programming", "asynchronous"]

[dependencies]
specta = { path = "../specta" }
openapiv3 = { version = "1.0.2", default-features = false, features = [] }
openapiv3 = { version = "2.0.0", default-features = false, features = [] }
5 changes: 3 additions & 2 deletions specta-openapi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! [OpenAPI](https://www.openapis.org) language exporter.

use openapiv3::{
ArrayType, NumberType, ReferenceOr, Schema, SchemaData, SchemaKind, StringType, Type,
ArrayType, BooleanType, NumberType, ReferenceOr, Schema, SchemaData, SchemaKind, StringType,
Type,
};
use specta::{DataType, PrimitiveType};

Expand Down Expand Up @@ -78,7 +79,7 @@ pub fn to_openapi(typ: &DataType) -> ReferenceOr<Schema> {
}),
primitive_def!(bool) => ReferenceOr::Item(Schema {
schema_data,
schema_kind: SchemaKind::Type(Type::Boolean {}),
schema_kind: SchemaKind::Type(Type::Boolean(BooleanType::default())),
}),
// primitive_def!(Never) => "never".into(),
DataType::Nullable(def) => {
Expand Down
2 changes: 1 addition & 1 deletion specta-typescript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ function = ["specta/function"]
specta = { path = "../specta" }
# TODO: Don't depend on serde
specta-serde = { path = "../specta-serde" }
thiserror = "1.0.60"
thiserror = "1.0.61"
6 changes: 3 additions & 3 deletions specta-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ serde = []
[dependencies]
specta = { path = "../specta" }
specta-macros = { path = "../specta-macros" }
ctor = { version = "0.2.4", optional = true }
once_cell = "1.18.0"
serde = "1.0.203"
ctor = { version = "0.2.8", optional = true }
once_cell = "1.19.0"
serde = "1.0.204"
2 changes: 1 addition & 1 deletion specta-zod/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ specta = { path = "../specta" }
specta-typescript = { path = "../specta-typescript" }
# TODO: Don't depend on serde
specta-serde = { path = "../specta-serde" }
thiserror = "1.0.60"
thiserror = "1.0.61"

[dev-dependencies]
specta-util = { path = "../specta-util" }
56 changes: 29 additions & 27 deletions specta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,34 +78,36 @@ bevy_input = ["dep:bevy_input", "dep:bevy_ecs", "dep:glam"]
interop = ["dep:specta1"]

[dependencies]
specta-macros = { version = "=2.0.0-rc.13", path = "../specta-macros" }
serde = { version = "1.0.183", optional = true, default-features = false, features = ["derive"] }
serde_json = { version = "1.0.104", optional = true, default-features = false, features = ["std"] }
serde_yaml = { version = "0.9.25", optional = true, default-features = false, features = [] }
toml = { version = "0.7.6", optional = true, default-features = false }
ulid = { version = "1.1.0", optional = true, default-features = false, features = [] }
uuid = { version = "1.4.1", optional = true, default-features = false, features = [] }
chrono = { version = "0.4.26", optional = true, default-features = false, features = ["clock"] }
time = { version = "0.3.25", optional = true, default-features = false, features = [] }
bigdecimal = { version = "0.4.1", optional = true, default-features = false, features = [] }
rust_decimal = { version = "1.31.0", optional = true, default-features = false, features = [] }
indexmap = { version = "2.0.0", optional = true, default-features = false, features = ["std"] } # TODO: Don't require `std`
ipnetwork = { version = "0.20.0", optional = true, default-features = false, features = [] }
mac_address = { version = "1.1.5", optional = true, default-features = false, features = [] }
bit-vec = { version = "0.6.3", optional = true, default-features = false, features = [] }
bson = { version = "2.6.1", optional = true, default-features = false, features = [] }
uhlc = { version = "0.6.0", optional = true, default-features = false, features = [] }
bytesize = { version = "1.2.0", optional = true, default-features = false, features = [] }
glam = { version = "0.25", optional = true, default-features = false, features = ["std"] }
tokio = { version = "1.30", optional = true, default-features = false, features = ["sync"] }
url = { version = "2.4.0", optional = true, default-features = false }
either = { version = "1.9.0", optional = true, default-features = false }
bevy_ecs = { version = "0.13.2", optional = true, default-features = false }
bevy_input = { version = "0.13.2", optional = true, default-features = false }
thiserror = "1.0.44"
paste = "1.0.14"
specta-macros = { version = "=2.0.0-rc.13", optional = true, path = "../specta-macros" }
thiserror = "1.0.61"
paste = "1.0.15"

# TODO: To be deprecated
specta1 = { package = "specta", version = "1", optional = true, default-features = false }
serde = { version = "1.0.204", optional = true, default-features = false, features = ["derive"] }
serde_json = { version = "1.0.120", optional = true, default-features = false, features = ["std"] }
serde_yaml = { version = "0.9.34", optional = true, default-features = false, features = [] }
toml = { version = "0.8.14", optional = true, default-features = false }
ulid = { version = "1.1.2", optional = true, default-features = false, features = [] }
uuid = { version = "1.10.0", optional = true, default-features = false, features = [] }
chrono = { version = "0.4.38", optional = true, default-features = false, features = ["clock"] }
time = { version = "0.3.36", optional = true, default-features = false, features = [] }
bigdecimal = { version = "0.4.5", optional = true, default-features = false, features = [] }
rust_decimal = { version = "1.35.0", optional = true, default-features = false, features = [] }
indexmap = { version = "2.2.6", optional = true, default-features = false, features = ["std"] } # TODO: Don't require `std`
ipnetwork = { version = "0.20.0", optional = true, default-features = false, features = [] }
mac_address = { version = "1.1.7", optional = true, default-features = false, features = [] }
bit-vec = { version = "0.7.0", optional = true, default-features = false, features = [] }
bson = { version = "2.11.0", optional = true, default-features = false, features = [] }
uhlc = { version = "0.8.0", optional = true, default-features = false, features = [] }
bytesize = { version = "1.3.0", optional = true, default-features = false, features = [] }
glam = { version = "0.28", optional = true, default-features = false, features = ["std"] }
tokio = { version = "1.38", optional = true, default-features = false, features = ["sync"] }
url = { version = "2.5.2", optional = true, default-features = false }
either = { version = "1.13.0", optional = true, default-features = false }
bevy_ecs = { version = "0.14.0", optional = true, default-features = false }
bevy_input = { version = "0.14.0", optional = true, default-features = false }

[dev-dependencies]
doc-comment = "0.3.3"
serde = { version = "1.0.183", features = ["derive"] }
serde = { version = "1.0.204", features = ["derive"] }
6 changes: 3 additions & 3 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ specta-typescript = { path = "../specta-typescript", features = ["function"] }
specta-util = { path = "../specta-util", features = ["serde"] } # TODO: Remove `serde` feature
specta-datatype-from = { path = "../specta-datatype-from" }

serde = { version = "1.0.203", features = ["derive"] }
trybuild = "1.0.82"
wasm-bindgen = "0.2.89"
serde = { version = "1.0.204", features = ["derive"] }
trybuild = "1.0.97"
wasm-bindgen = "0.2.92"

0 comments on commit c41c53c

Please sign in to comment.