diff --git a/Cargo.lock b/Cargo.lock index 37ec76ad34..eb041f83ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -831,8 +831,18 @@ version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.14.4", + "darling_macro 0.14.4", +] + +[[package]] +name = "darling" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c99d16b88c92aef47e58dadd53e87b4bd234c29934947a6cec8b466300f99b" +dependencies = [ + "darling_core 0.20.0", + "darling_macro 0.20.0", ] [[package]] @@ -849,17 +859,42 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "darling_core" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ea05d2fcb27b53f7a98faddaf5f2914760330ab7703adfc9df13332b42189f9" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.15", +] + [[package]] name = "darling_macro" version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" dependencies = [ - "darling_core", + "darling_core 0.14.4", "quote", "syn 1.0.109", ] +[[package]] +name = "darling_macro" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bfb82b62b1b8a2a9808fb4caf844ede819a76cfc23b2827d7f94eefb49551eb" +dependencies = [ + "darling_core 0.20.0", + "quote", + "syn 2.0.15", +] + [[package]] name = "derivative" version = "2.2.0" @@ -1628,7 +1663,7 @@ dependencies = [ "subxt", "subxt-codegen", "subxt-metadata", - "syn 1.0.109", + "syn 2.0.15", "test-runtime", "tokio", "tracing", @@ -2692,7 +2727,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b38741b2f78e4391b94eac6b102af0f6ea2b0f7fe65adb55d7f4004f507854db" dependencies = [ - "darling", + "darling 0.14.4", "proc-macro-crate", "proc-macro2", "quote", @@ -2719,7 +2754,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd983cf0a9effd76138554ead18a6de542d1af175ac12fd5e91836c5c0268082" dependencies = [ - "darling", + "darling 0.14.4", "proc-macro-crate", "proc-macro2", "quote", @@ -3549,7 +3584,7 @@ dependencies = [ "serde_json", "subxt-codegen", "subxt-metadata", - "syn 1.0.109", + "syn 2.0.15", "tokio", ] @@ -3558,7 +3593,6 @@ name = "subxt-codegen" version = "0.28.0" dependencies = [ "bitvec", - "darling", "frame-metadata", "heck", "hex", @@ -3569,7 +3603,7 @@ dependencies = [ "quote", "scale-info", "subxt-metadata", - "syn 1.0.109", + "syn 2.0.15", "thiserror", "tokio", ] @@ -3593,10 +3627,10 @@ dependencies = [ name = "subxt-macro" version = "0.28.0" dependencies = [ - "darling", + "darling 0.20.0", "proc-macro-error", "subxt-codegen", - "syn 1.0.109", + "syn 2.0.15", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index c59ceaeea4..cf87f98ec1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ criterion = "0.4" codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false } color-eyre = "0.6.1" console_error_panic_hook = "0.1.7" -darling = "0.14.4" +darling = "0.20.0" derivative = "2.2.0" either = "1.8.1" frame-metadata = { version = "15.1.0", features = ["v14", "v15-unstable", "std"] } @@ -61,7 +61,7 @@ scale-decode = "0.5.0" scale-encode = "0.1.0" serde = { version = "1.0.159" } serde_json = { version = "1.0.96" } -syn = "1.0.109" +syn = { version = "2.0.15", features = ["full", "extra-traits"] } thiserror = "1.0.40" tokio = { version = "1.28", features = ["macros", "time", "rt-multi-thread"] } tracing = "0.1.34" diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index 6c776d30b0..3db79d4829 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -14,7 +14,6 @@ description = "Generate an API for interacting with a substrate node from FRAME [dependencies] codec = { package = "parity-scale-codec", workspace = true, features = ["derive"] } -darling = { workspace = true } frame-metadata = { workspace = true } heck = { workspace = true } proc-macro2 = { workspace = true } diff --git a/codegen/src/types/mod.rs b/codegen/src/types/mod.rs index caaa427df6..4dedb14fc3 100644 --- a/codegen/src/types/mod.rs +++ b/codegen/src/types/mod.rs @@ -11,7 +11,6 @@ mod type_def; mod type_def_params; mod type_path; -use darling::FromMeta; use proc_macro2::{Ident, Span, TokenStream}; use quote::{quote, ToTokens}; use scale_info::{form::PortableForm, PortableRegistry, Type, TypeDef}; @@ -353,7 +352,7 @@ impl ToTokens for CratePath { impl From<&str> for CratePath { fn from(crate_path: &str) -> Self { - Self(syn::Path::from_string(crate_path).unwrap_or_else(|err| { + Self(syn::parse_str(crate_path).unwrap_or_else(|err| { panic!("failed converting {crate_path:?} to `syn::Path`: {err:?}"); })) } diff --git a/examples/examples/custom_type_derives.rs b/examples/examples/custom_type_derives.rs index 9e7a22a1c7..b8cf6433c7 100644 --- a/examples/examples/custom_type_derives.rs +++ b/examples/examples/custom_type_derives.rs @@ -17,8 +17,8 @@ // mapping the type path to the derives which should be added for that type only. // Note that these derives will be in addition to those specified above in // `derive_for_all_types` - derive_for_type(type = "frame_support::PalletId", derive = "Eq, Ord, PartialOrd"), - derive_for_type(type = "sp_runtime::ModuleError", derive = "Eq, Hash"), + derive_for_type(path = "frame_support::PalletId", derive = "Eq, Ord, PartialOrd"), + derive_for_type(path = "sp_runtime::ModuleError", derive = "Eq, Hash"), )] pub mod polkadot {} diff --git a/macro/src/lib.rs b/macro/src/lib.rs index bb0ac0b7fb..f0621a1ec4 100644 --- a/macro/src/lib.rs +++ b/macro/src/lib.rs @@ -31,7 +31,7 @@ //! ```ignore //! #[subxt::subxt( //! runtime_metadata_path = "polkadot_metadata.scale", -//! substitute_type(type = "sp_arithmetic::per_things::Perbill", with = "sp_runtime::Perbill") +//! substitute_type(path = "sp_arithmetic::per_things::Perbill", with = "sp_runtime::Perbill") //! )] //! pub mod polkadot {} //! ``` @@ -67,8 +67,8 @@ //! #[subxt::subxt( //! runtime_metadata_path = "polkadot_metadata.scale", //! derive_for_all_types = "Eq, PartialEq", -//! derive_for_type(type = "frame_support::PalletId", derive = "Ord, PartialOrd"), -//! derive_for_type(type = "sp_runtime::ModuleError", derive = "Hash"), +//! derive_for_type(path = "frame_support::PalletId", derive = "Ord, PartialOrd"), +//! derive_for_type(path = "sp_runtime::ModuleError", derive = "Hash"), //! )] //! pub mod polkadot {} //! ``` @@ -113,7 +113,7 @@ extern crate proc_macro; use std::str::FromStr; -use darling::FromMeta; +use darling::{ast::NestedMeta, FromMeta}; use proc_macro::TokenStream; use proc_macro_error::{abort_call_site, proc_macro_error}; use subxt_codegen::{utils::Uri, CodegenError, DerivesRegistry, TypeSubstitutes}; @@ -158,29 +158,31 @@ struct RuntimeMetadataArgs { #[derive(Debug, FromMeta)] struct DeriveForType { - #[darling(rename = "type")] - ty: syn::TypePath, + path: syn::TypePath, derive: Punctuated, } #[derive(Debug, FromMeta)] struct AttributesForType { - #[darling(rename = "type")] - ty: syn::TypePath, + path: syn::TypePath, attributes: Punctuated, } #[derive(Debug, FromMeta)] struct SubstituteType { - #[darling(rename = "type")] - ty: syn::Path, + path: syn::Path, with: syn::Path, } #[proc_macro_attribute] #[proc_macro_error] pub fn subxt(args: TokenStream, input: TokenStream) -> TokenStream { - let attr_args = parse_macro_input!(args as syn::AttributeArgs); + let attr_args = match NestedMeta::parse_meta_list(args.into()) { + Ok(v) => v, + Err(e) => { + return TokenStream::from(darling::Error::from(e).write_errors()); + } + }; let item_mod = parse_macro_input!(input as syn::ItemMod); let args = match RuntimeMetadataArgs::from_list(&attr_args) { Ok(v) => v, @@ -205,11 +207,15 @@ pub fn subxt(args: TokenStream, input: TokenStream) -> TokenStream { ); for derives in &args.derive_for_type { - derives_registry.extend_for_type(derives.ty.clone(), derives.derive.iter().cloned(), vec![]) + derives_registry.extend_for_type( + derives.path.clone(), + derives.derive.iter().cloned(), + vec![], + ) } for attributes in &args.attributes_for_type { derives_registry.extend_for_type( - attributes.ty.clone(), + attributes.path.clone(), vec![], attributes.attributes.iter().map(|a| a.0.clone()), ) @@ -223,7 +229,7 @@ pub fn subxt(args: TokenStream, input: TokenStream) -> TokenStream { let substitute_args_res: Result<(), _> = args.substitute_type.into_iter().try_for_each(|sub| { sub.with .try_into() - .and_then(|with| type_substitutes.insert(sub.ty, with)) + .and_then(|with| type_substitutes.insert(sub.path, with)) }); if let Err(err) = substitute_args_res { diff --git a/testing/ui-tests/src/correct/generic_params.rs b/testing/ui-tests/src/correct/generic_params.rs index 00ae5b976f..30f024fe12 100644 --- a/testing/ui-tests/src/correct/generic_params.rs +++ b/testing/ui-tests/src/correct/generic_params.rs @@ -22,7 +22,7 @@ pub struct DoesntImplEncodeDecodeAsType(u16); #[subxt::subxt( runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale", substitute_type( - type = "sp_runtime::multiaddress::MultiAddress", + path = "sp_runtime::multiaddress::MultiAddress", // Discarding both params: with = "crate::CustomAddress" ) @@ -32,7 +32,7 @@ pub mod node_runtime {} #[subxt::subxt( runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale", substitute_type( - type = "sp_runtime::multiaddress::MultiAddress", + path = "sp_runtime::multiaddress::MultiAddress", // Discarding second param: with = "crate::Generic" ) @@ -42,7 +42,7 @@ pub mod node_runtime2 {} #[subxt::subxt( runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale", substitute_type( - type = "sp_runtime::multiaddress::MultiAddress", + path = "sp_runtime::multiaddress::MultiAddress", // Discarding first param: with = "crate::Generic" ) @@ -52,7 +52,7 @@ pub mod node_runtime3 {} #[subxt::subxt( runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale", substitute_type( - type = "sp_runtime::multiaddress::MultiAddress", + path = "sp_runtime::multiaddress::MultiAddress", // Swapping params: with = "crate::Second" ) @@ -62,7 +62,7 @@ pub mod node_runtime4 {} #[subxt::subxt( runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale", substitute_type( - type = "sp_runtime::multiaddress::MultiAddress", + path = "sp_runtime::multiaddress::MultiAddress", // Ignore input params and just use concrete types on output: with = "crate::Second>" ) @@ -72,7 +72,7 @@ pub mod node_runtime5 {} #[subxt::subxt( runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale", substitute_type( - type = "sp_runtime::multiaddress::MultiAddress", + path = "sp_runtime::multiaddress::MultiAddress", // We can put a static type in, too: with = "crate::Second" ) @@ -82,7 +82,7 @@ pub mod node_runtime6 {} #[subxt::subxt( runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale", substitute_type( - type = "sp_runtime::multiaddress::MultiAddress", + path = "sp_runtime::multiaddress::MultiAddress", // Check that things can be wrapped in our Static type: with = "::subxt::utils::Static" ) @@ -92,7 +92,7 @@ pub mod node_runtime7 {} #[subxt::subxt( runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale", substitute_type( - type = "sp_runtime::multiaddress::MultiAddress", + path = "sp_runtime::multiaddress::MultiAddress", // Recursive type param substitution should work too (swapping out nested A and B): with = "::subxt::utils::Static>" ) diff --git a/testing/ui-tests/src/incorrect/substitute_path_not_absolute.rs b/testing/ui-tests/src/incorrect/substitute_path_not_absolute.rs index 154b857c9d..470ea83a7b 100644 --- a/testing/ui-tests/src/incorrect/substitute_path_not_absolute.rs +++ b/testing/ui-tests/src/incorrect/substitute_path_not_absolute.rs @@ -1,7 +1,7 @@ #[subxt::subxt( runtime_metadata_path = "../../../../artifacts/polkadot_metadata_tiny.scale", substitute_type( - type = "sp_arithmetic::per_things::Perbill", + path = "sp_arithmetic::per_things::Perbill", with = "sp_runtime::Perbill" ) )]