diff --git a/frame/babe/Cargo.toml b/frame/babe/Cargo.toml index 4a643335f6874..019c07ea2beac 100644 --- a/frame/babe/Cargo.toml +++ b/frame/babe/Cargo.toml @@ -15,20 +15,20 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } log = { version = "0.4.17", default-features = false } -scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } +scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde"] } frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../benchmarking" } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } pallet-authorship = { version = "4.0.0-dev", default-features = false, path = "../authorship" } pallet-session = { version = "4.0.0-dev", default-features = false, path = "../session" } pallet-timestamp = { version = "4.0.0-dev", default-features = false, path = "../timestamp" } -sp-application-crypto = { version = "23.0.0", default-features = false, path = "../../primitives/application-crypto" } -sp-consensus-babe = { version = "0.10.0-dev", default-features = false, path = "../../primitives/consensus/babe" } -sp-core = { version = "21.0.0", default-features = false, path = "../../primitives/core" } +sp-application-crypto = { version = "23.0.0", default-features = false, path = "../../primitives/application-crypto", features = ["serde"] } +sp-consensus-babe = { version = "0.10.0-dev", default-features = false, path = "../../primitives/consensus/babe", features = ["serde"] } +sp-core = { version = "21.0.0", default-features = false, path = "../../primitives/core", features = ["serde"] } sp-io = { version = "23.0.0", default-features = false, path = "../../primitives/io" } -sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime" } +sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime", features = ["serde"] } sp-session = { version = "4.0.0-dev", default-features = false, path = "../../primitives/session" } -sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } +sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking", features = ["serde"] } sp-std = { version = "8.0.0", default-features = false, path = "../../primitives/std" } [dev-dependencies] diff --git a/frame/beefy/Cargo.toml b/frame/beefy/Cargo.toml index 51345675fc496..980f1e80e19cb 100644 --- a/frame/beefy/Cargo.toml +++ b/frame/beefy/Cargo.toml @@ -10,16 +10,16 @@ homepage = "https://substrate.io" [dependencies] codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } -scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } +scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde"] } serde = { version = "1.0.163", optional = true } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } pallet-authorship = { version = "4.0.0-dev", default-features = false, path = "../authorship" } pallet-session = { version = "4.0.0-dev", default-features = false, path = "../session" } -sp-consensus-beefy = { version = "4.0.0-dev", default-features = false, path = "../../primitives/consensus/beefy" } -sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime" } +sp-consensus-beefy = { version = "4.0.0-dev", default-features = false, path = "../../primitives/consensus/beefy", features = ["serde"] } +sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime", features = ["serde"] } sp-session = { version = "4.0.0-dev", default-features = false, path = "../../primitives/session" } -sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } +sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking", features = ["serde"] } sp-std = { version = "8.0.0", default-features = false, path = "../../primitives/std" } [dev-dependencies] @@ -42,7 +42,7 @@ std = [ "pallet-authorship/std", "pallet-session/std", "scale-info/std", - "serde", + "serde/std", "sp-consensus-beefy/std", "sp-runtime/std", "sp-session/std", diff --git a/frame/grandpa/Cargo.toml b/frame/grandpa/Cargo.toml index ea618290eb7f7..00ca327c1188b 100644 --- a/frame/grandpa/Cargo.toml +++ b/frame/grandpa/Cargo.toml @@ -15,19 +15,19 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } log = { version = "0.4.17", default-features = false } -scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } +scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde"] } frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../benchmarking" } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } pallet-authorship = { version = "4.0.0-dev", default-features = false, path = "../authorship" } pallet-session = { version = "4.0.0-dev", default-features = false, path = "../session" } -sp-application-crypto = { version = "23.0.0", default-features = false, path = "../../primitives/application-crypto" } -sp-core = { version = "21.0.0", default-features = false, path = "../../primitives/core" } -sp-consensus-grandpa = { version = "4.0.0-dev", default-features = false, path = "../../primitives/consensus/grandpa" } +sp-application-crypto = { version = "23.0.0", default-features = false, path = "../../primitives/application-crypto", features = ["serde"] } +sp-consensus-grandpa = { version = "4.0.0-dev", default-features = false, path = "../../primitives/consensus/grandpa", features = ["serde"] } +sp-core = { version = "21.0.0", default-features = false, path = "../../primitives/core", features = ["serde"] } sp-io = { version = "23.0.0", default-features = false, path = "../../primitives/io" } -sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime" } +sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime", features = ["serde"] } sp-session = { version = "4.0.0-dev", default-features = false, path = "../../primitives/session" } -sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } +sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking", features = ["serde"] } sp-std = { version = "8.0.0", default-features = false, path = "../../primitives/std" } [dev-dependencies] diff --git a/frame/im-online/Cargo.toml b/frame/im-online/Cargo.toml index fd7d7e535effd..3128b00c1dbae 100644 --- a/frame/im-online/Cargo.toml +++ b/frame/im-online/Cargo.toml @@ -15,16 +15,16 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } log = { version = "0.4.17", default-features = false } -scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } +scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde"] } frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../benchmarking" } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } pallet-authorship = { version = "4.0.0-dev", default-features = false, path = "../authorship" } -sp-application-crypto = { version = "23.0.0", default-features = false, path = "../../primitives/application-crypto" } -sp-core = { version = "21.0.0", default-features = false, path = "../../primitives/core" } +sp-application-crypto = { version = "23.0.0", default-features = false, path = "../../primitives/application-crypto", features = ["serde"] } +sp-core = { version = "21.0.0", default-features = false, path = "../../primitives/core", features = ["serde"] } sp-io = { version = "23.0.0", default-features = false, path = "../../primitives/io" } -sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime" } -sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } +sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime", features = ["serde"] } +sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking", features = ["serde"] } sp-std = { version = "8.0.0", default-features = false, path = "../../primitives/std" } [dev-dependencies] diff --git a/frame/membership/Cargo.toml b/frame/membership/Cargo.toml index e0f2e8ae0b7f2..71be277afe758 100644 --- a/frame/membership/Cargo.toml +++ b/frame/membership/Cargo.toml @@ -15,13 +15,13 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false } log = { version = "0.4.17", default-features = false } -scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } +scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde"] } frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../benchmarking" } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } -sp-core = { version = "21.0.0", default-features = false, path = "../../primitives/core" } +sp-core = { version = "21.0.0", default-features = false, path = "../../primitives/core", features = ["serde"] } sp-io = { version = "23.0.0", default-features = false, path = "../../primitives/io" } -sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime" } +sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime", features = ["serde"] } sp-std = { version = "8.0.0", default-features = false, path = "../../primitives/std" } [features] diff --git a/frame/session/Cargo.toml b/frame/session/Cargo.toml index 44006244366d5..b26ebc975513f 100644 --- a/frame/session/Cargo.toml +++ b/frame/session/Cargo.toml @@ -16,15 +16,15 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } impl-trait-for-tuples = "0.2.2" log = { version = "0.4.17", default-features = false } -scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } +scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde"] } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } pallet-timestamp = { version = "4.0.0-dev", default-features = false, path = "../timestamp" } -sp-core = { version = "21.0.0", default-features = false, path = "../../primitives/core" } +sp-core = { version = "21.0.0", default-features = false, path = "../../primitives/core", features = ["serde"] } sp-io = { version = "23.0.0", default-features = false, path = "../../primitives/io" } -sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime" } +sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime", features = ["serde"] } sp-session = { version = "4.0.0-dev", default-features = false, path = "../../primitives/session" } -sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } +sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking", features = ["serde"] } sp-std = { version = "8.0.0", default-features = false, path = "../../primitives/std" } sp-trie = { version = "22.0.0", default-features = false, optional = true, path = "../../primitives/trie" } diff --git a/frame/staking/Cargo.toml b/frame/staking/Cargo.toml index b4577401d3366..8bf607a6cb8a0 100644 --- a/frame/staking/Cargo.toml +++ b/frame/staking/Cargo.toml @@ -13,22 +13,22 @@ readme = "README.md" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -serde = { version = "1.0.163", optional = true } +serde = { version = "1.0.163", default-features = false, features = ["alloc", "derive"]} codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = [ "derive", ] } -scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } -sp-std = { version = "8.0.0", default-features = false, path = "../../primitives/std" } +scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde"] } sp-io = { version = "23.0.0", default-features = false, path = "../../primitives/io" } -sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime" } -sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } +sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime", features = ["serde"] } +sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking", features = ["serde"] } +sp-std = { version = "8.0.0", default-features = false, path = "../../primitives/std" } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } pallet-session = { version = "4.0.0-dev", default-features = false, features = [ "historical", ], path = "../session" } pallet-authorship = { version = "4.0.0-dev", default-features = false, path = "../authorship" } -sp-application-crypto = { version = "23.0.0", default-features = false, path = "../../primitives/application-crypto" } +sp-application-crypto = { version = "23.0.0", default-features = false, path = "../../primitives/application-crypto", features = ["serde"] } frame-election-provider-support = { version = "4.0.0-dev", default-features = false, path = "../election-provider-support" } log = { version = "0.4.17", default-features = false } @@ -53,7 +53,7 @@ rand_chacha = { version = "0.2" } default = ["std"] std = [ "frame-benchmarking?/std", - "serde", + "serde/std", "codec/std", "scale-info/std", "sp-std/std", diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index c87aeb681a226..55205fad38ff9 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -849,8 +849,19 @@ impl proc_macro2::TokenStream { )); } attrs.push(syn::parse_quote!( - #[cfg_attr(feature = "std", derive(#frame_support::Serialize, #frame_support::Deserialize))] + #[derive(#frame_support::Serialize, #frame_support::Deserialize)] )); - attrs.push( - syn::parse_quote!( #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] ), - ); - attrs.push( - syn::parse_quote!( #[cfg_attr(feature = "std", serde(deny_unknown_fields))] ), - ); - attrs.push( - syn::parse_quote!( #[cfg_attr(feature = "std", serde(bound(serialize = "")))] ), - ); - attrs.push( - syn::parse_quote!( #[cfg_attr(feature = "std", serde(bound(deserialize = "")))] ), - ); - attrs.push( - syn::parse_quote!( #[cfg_attr(feature = "std", serde(crate = #serde_crate))] ), - ); + attrs.push(syn::parse_quote!( #[serde(rename_all = "camelCase")] )); + attrs.push(syn::parse_quote!( #[serde(deny_unknown_fields)] )); + attrs.push(syn::parse_quote!( #[serde(bound(serialize = ""))] )); + attrs.push(syn::parse_quote!( #[serde(bound(deserialize = ""))] )); + attrs.push(syn::parse_quote!( #[serde(crate = #serde_crate)] )); }, _ => unreachable!("Checked by genesis_config parser"), } diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index de87b59a0b943..7800fd8bba8a5 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -48,7 +48,6 @@ pub use once_cell; pub use paste; #[doc(hidden)] pub use scale_info; -#[cfg(feature = "std")] pub use serde; pub use sp_api::metadata_ir; pub use sp_core::{OpaqueMetadata, Void}; @@ -821,7 +820,6 @@ macro_rules! assert_error_encoded_size { } => {}; } -#[cfg(feature = "std")] #[doc(hidden)] pub use serde::{Deserialize, Serialize}; diff --git a/frame/system/Cargo.toml b/frame/system/Cargo.toml index 2dfe46b548d9b..d7dc334900913 100644 --- a/frame/system/Cargo.toml +++ b/frame/system/Cargo.toml @@ -16,15 +16,15 @@ targets = ["x86_64-unknown-linux-gnu"] cfg-if = "1.0" codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } log = { version = "0.4.17", default-features = false } -scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } -serde = { version = "1.0.163", features = ["derive"], optional = true } +scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde"] } +serde = { version = "1.0.163", default-features = false, features = ["derive", "alloc"] } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } -sp-core = { version = "21.0.0", default-features = false, path = "../../primitives/core" } +sp-core = { version = "21.0.0", default-features = false, path = "../../primitives/core", features = ["serde"] } sp-io = { version = "23.0.0", default-features = false, path = "../../primitives/io" } -sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime" } +sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime", features = ["serde"] } sp-std = { version = "8.0.0", default-features = false, path = "../../primitives/std" } -sp-version = { version = "22.0.0", default-features = false, path = "../../primitives/version" } -sp-weights = { version = "20.0.0", default-features = false, path = "../../primitives/weights" } +sp-version = { version = "22.0.0", default-features = false, path = "../../primitives/version", features = ["serde"] } +sp-weights = { version = "20.0.0", default-features = false, path = "../../primitives/weights", features = ["serde"] } [dev-dependencies] criterion = "0.4.0" @@ -38,7 +38,7 @@ std = [ "frame-support/std", "log/std", "scale-info/std", - "serde", + "serde/std", "sp-core/std", "sp-io/std", "sp-runtime/std", diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index 8c717e3f5eb12..79cdcf22f55c7 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -673,7 +673,7 @@ pub mod pallet { #[derive(Default)] #[pallet::genesis_config] pub struct GenesisConfig { - #[cfg_attr(feature = "std", serde(with = "sp_core::bytes"))] + #[serde(with = "sp_core::bytes")] pub code: Vec, } diff --git a/primitives/runtime/src/traits.rs b/primitives/runtime/src/traits.rs index a2af0b778040b..a1874bcecf3c5 100644 --- a/primitives/runtime/src/traits.rs +++ b/primitives/runtime/src/traits.rs @@ -1772,7 +1772,7 @@ macro_rules! impl_opaque_keys_inner { /// } /// ``` #[macro_export] -#[cfg(feature = "std")] +#[cfg(any(feature = "serde", feature = "std"))] macro_rules! impl_opaque_keys { { $( #[ $attr:meta ] )* @@ -1802,7 +1802,7 @@ macro_rules! impl_opaque_keys { } #[macro_export] -#[cfg(not(feature = "std"))] +#[cfg(all(not(feature = "std"), not(feature = "serde")))] #[doc(hidden)] macro_rules! impl_opaque_keys { { diff --git a/primitives/staking/Cargo.toml b/primitives/staking/Cargo.toml index 83b9849f266bd..f50934b29482c 100644 --- a/primitives/staking/Cargo.toml +++ b/primitives/staking/Cargo.toml @@ -13,7 +13,7 @@ readme = "README.md" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -serde = { version = "1.0.163", optional = true } +serde = { version = "1.0.163", default-features = false, features = ["derive", "alloc"], optional = true } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } sp-core = { version = "21.0.0", default-features = false, path = "../core" } @@ -23,7 +23,7 @@ sp-std = { version = "8.0.0", default-features = false, path = "../std" } [features] default = ["std"] std = [ - "serde", + "serde/std", "codec/std", "scale-info/std", "sp-core/std", diff --git a/primitives/staking/src/lib.rs b/primitives/staking/src/lib.rs index 57128bd327d9e..2fd5c6acc6a04 100644 --- a/primitives/staking/src/lib.rs +++ b/primitives/staking/src/lib.rs @@ -35,7 +35,7 @@ pub type EraIndex = u32; /// Representation of the status of a staker. #[derive(RuntimeDebug, TypeInfo)] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone))] pub enum StakerStatus { /// Chilling. Idle,