From 9b29626616d639b34fe5507077c616d7b42b66ec Mon Sep 17 00:00:00 2001 From: Kevin Heavey Date: Thu, 14 Nov 2024 15:30:27 +0400 Subject: [PATCH] extract deserialize-utils crate (#3387) * extract deserialize-utils crate * missing dev dep * rename to solana-serde * fix deprecated since --- Cargo.lock | 10 ++++++++++ Cargo.toml | 2 ++ programs/sbf/Cargo.lock | 8 ++++++++ sdk/Cargo.toml | 1 + sdk/serde/Cargo.toml | 20 +++++++++++++++++++ .../deserialize_utils.rs => serde/src/lib.rs} | 4 ++-- sdk/src/lib.rs | 3 ++- 7 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 sdk/serde/Cargo.toml rename sdk/{src/deserialize_utils.rs => serde/src/lib.rs} (95%) diff --git a/Cargo.lock b/Cargo.lock index 361d38d60f46ba..143443c30bc32b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8379,6 +8379,7 @@ dependencies = [ "solana-secp256k1-recover", "solana-seed-derivable", "solana-seed-phrase", + "solana-serde", "solana-serde-varint", "solana-short-vec", "solana-signature", @@ -8461,6 +8462,15 @@ dependencies = [ "solana-tpu-client", ] +[[package]] +name = "solana-serde" +version = "2.2.0" +dependencies = [ + "bincode", + "serde", + "serde_derive", +] + [[package]] name = "solana-serde-varint" version = "2.2.0" diff --git a/Cargo.toml b/Cargo.toml index ab7605e3fccce4..5ff6d1f7c3d84b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -149,6 +149,7 @@ members = [ "sdk/sdk-ids", "sdk/seed-derivable", "sdk/seed-phrase", + "sdk/serde", "sdk/serde-varint", "sdk/serialize-utils", "sdk/sha256-hasher", @@ -506,6 +507,7 @@ solana-reward-info = { path = "sdk/reward-info", version = "=2.2.0" } solana-sanitize = { path = "sdk/sanitize", version = "=2.2.0" } solana-seed-derivable = { path = "sdk/seed-derivable", version = "=2.2.0" } solana-seed-phrase = { path = "sdk/seed-phrase", version = "=2.2.0" } +solana-serde = { path = "sdk/serde", version = "=2.2.0" } solana-serde-varint = { path = "sdk/serde-varint", version = "=2.2.0" } solana-serialize-utils = { path = "sdk/serialize-utils", version = "=2.2.0" } solana-sha256-hasher = { path = "sdk/sha256-hasher", version = "=2.2.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 9c94cc8a7ead0a..60f000836f7df7 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -7101,6 +7101,7 @@ dependencies = [ "solana-secp256k1-recover", "solana-seed-derivable", "solana-seed-phrase", + "solana-serde", "solana-serde-varint", "solana-short-vec", "solana-signature", @@ -7176,6 +7177,13 @@ dependencies = [ "solana-tpu-client", ] +[[package]] +name = "solana-serde" +version = "2.2.0" +dependencies = [ + "serde", +] + [[package]] name = "solana-serde-varint" version = "2.2.0" diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 2475950c971c9d..1b79c869cae005 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -133,6 +133,7 @@ solana-sdk-macro = { workspace = true } solana-secp256k1-recover = { workspace = true } solana-seed-derivable = { workspace = true, optional = true } solana-seed-phrase = { workspace = true, optional = true } +solana-serde = { workspace = true } solana-serde-varint = { workspace = true } solana-short-vec = { workspace = true } solana-signature = { workspace = true, features = [ diff --git a/sdk/serde/Cargo.toml b/sdk/serde/Cargo.toml new file mode 100644 index 00000000000000..4baf21010cb7ca --- /dev/null +++ b/sdk/serde/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "solana-serde" +description = "Solana serde helpers" +documentation = "https://docs.rs/solana-serde" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +serde = { workspace = true } + +[dev-dependencies] +bincode = { workspace = true } +serde_derive = { workspace = true } + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] diff --git a/sdk/src/deserialize_utils.rs b/sdk/serde/src/lib.rs similarity index 95% rename from sdk/src/deserialize_utils.rs rename to sdk/serde/src/lib.rs index 2d1464c17bbeb9..438b3b00a67eec 100644 --- a/sdk/src/deserialize_utils.rs +++ b/sdk/serde/src/lib.rs @@ -33,7 +33,7 @@ pub mod tests { #[test] fn test_default_on_eof() { - #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] + #[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug, PartialEq, Eq)] struct Foo { bar: u16, #[serde(deserialize_with = "default_on_eof")] @@ -108,7 +108,7 @@ pub mod tests { fn test_default_on_eof_additional_untagged_fields() { // If later fields are not tagged `deserialize_with = "default_on_eof"`, deserialization // will panic on any missing fields/data - #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] + #[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug, PartialEq, Eq)] struct Foo { bar: u16, #[serde(deserialize_with = "default_on_eof")] diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index befe275a0ee223..94e58c5a082a52 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -63,7 +63,6 @@ pub use solana_program::{borsh, borsh0_10, borsh1}; pub use solana_signer::signers; pub mod client; pub mod compute_budget; -pub mod deserialize_utils; pub mod entrypoint; pub mod entrypoint_deprecated; pub mod epoch_info; @@ -191,6 +190,8 @@ pub use solana_sdk_macro::declare_id; pub use solana_sdk_macro::pubkeys; #[deprecated(since = "2.1.0", note = "Use `solana-secp256k1-recover` crate instead")] pub use solana_secp256k1_recover as secp256k1_recover; +#[deprecated(since = "2.2.0", note = "Use `solana-serde` crate instead")] +pub use solana_serde as deserialize_utils; #[deprecated(since = "2.1.0", note = "Use `solana-serde-varint` crate instead")] pub use solana_serde_varint as serde_varint; #[deprecated(since = "2.1.0", note = "Use `solana-short-vec` crate instead")]