Repository: solana-labs/solana-program-library
Pull request #6928 (2024-06-25 11:58:35)

pod: Use `bytemuck_derive` explicitly
#### Problem

We can't publish spl-pod because it runs into issues with trying to derive `Pod` and `Zeroable`, likely because all of our tests activate the `derive` feature on bytemuck, but the solo crate does not.

#### Solution

Use `bytemuck_derive` explicitly


Patch:
diff --git a/Cargo.lock b/Cargo.lock
index 751750cdc..88446f9ab 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -7248,6 +7248,7 @@ dependencies = [
  "base64 0.22.1",
  "borsh 1.5.1",
  "bytemuck",
+ "bytemuck_derive",
  "serde",
  "serde_json",
  "solana-program",
@@ -7452,7 +7453,7 @@ dependencies = [
  "spl-discriminator 0.3.0",
  "spl-pod 0.3.0",
  "spl-program-error 0.5.0",
- "spl-type-length-value 0.4.3",
+ "spl-type-length-value 0.5.0",
 ]
 
 [[package]]
@@ -7466,7 +7467,7 @@ dependencies = [
  "spl-discriminator 0.2.2",
  "spl-pod 0.2.2",
  "spl-program-error 0.4.1",
- "spl-type-length-value 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "spl-type-length-value 0.4.3",
 ]
 
 [[package]]
@@ -7530,7 +7531,7 @@ dependencies = [
  "spl-token-group-interface 0.2.3",
  "spl-token-metadata-interface 0.3.3",
  "spl-transfer-hook-interface 0.6.3",
- "spl-type-length-value 0.4.3",
+ "spl-type-length-value 0.5.0",
  "thiserror",
 ]
 
@@ -7554,7 +7555,7 @@ dependencies = [
  "spl-token-group-interface 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "spl-token-metadata-interface 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "spl-transfer-hook-interface 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "spl-type-length-value 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "spl-type-length-value 0.4.3",
  "thiserror",
 ]
 
@@ -7660,7 +7661,7 @@ dependencies = [
  "spl-token-group-example",
  "spl-token-group-interface 0.2.3",
  "spl-token-metadata-interface 0.3.3",
- "spl-type-length-value 0.4.3",
+ "spl-type-length-value 0.5.0",
 ]
 
 [[package]]
@@ -7676,7 +7677,7 @@ dependencies = [
  "spl-token-client",
  "spl-token-group-interface 0.2.3",
  "spl-token-metadata-interface 0.3.3",
- "spl-type-length-value 0.4.3",
+ "spl-type-length-value 0.5.0",
 ]
 
 [[package]]
@@ -7688,7 +7689,7 @@ dependencies = [
  "spl-discriminator 0.3.0",
  "spl-pod 0.3.0",
  "spl-program-error 0.5.0",
- "spl-type-length-value 0.4.3",
+ "spl-type-length-value 0.5.0",
 ]
 
 [[package]]
@@ -7748,7 +7749,7 @@ dependencies = [
  "spl-token-2022 3.0.2",
  "spl-token-client",
  "spl-token-metadata-interface 0.3.3",
- "spl-type-length-value 0.4.3",
+ "spl-type-length-value 0.5.0",
  "test-case",
 ]
 
@@ -7763,7 +7764,7 @@ dependencies = [
  "spl-discriminator 0.3.0",
  "spl-pod 0.3.0",
  "spl-program-error 0.5.0",
- "spl-type-length-value 0.4.3",
+ "spl-type-length-value 0.5.0",
 ]
 
 [[package]]
@@ -7777,7 +7778,7 @@ dependencies = [
  "spl-discriminator 0.2.2",
  "spl-pod 0.2.2",
  "spl-program-error 0.4.1",
- "spl-type-length-value 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "spl-type-length-value 0.4.3",
 ]
 
 [[package]]
@@ -7901,7 +7902,7 @@ dependencies = [
  "spl-tlv-account-resolution 0.6.3",
  "spl-token-2022 3.0.2",
  "spl-transfer-hook-interface 0.6.3",
- "spl-type-length-value 0.4.3",
+ "spl-type-length-value 0.5.0",
 ]
 
 [[package]]
@@ -7915,7 +7916,7 @@ dependencies = [
  "spl-pod 0.3.0",
  "spl-program-error 0.5.0",
  "spl-tlv-account-resolution 0.6.3",
- "spl-type-length-value 0.4.3",
+ "spl-type-length-value 0.5.0",
  "tokio",
 ]
 
@@ -7932,32 +7933,32 @@ dependencies = [
  "spl-pod 0.2.2",
  "spl-program-error 0.4.1",
  "spl-tlv-account-resolution 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "spl-type-length-value 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "spl-type-length-value 0.4.3",
 ]
 
 [[package]]
 name = "spl-type-length-value"
 version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "422ce13429dbd41d2cee8a73931c05fda0b0c8ca156a8b0c19445642550bb61a"
 dependencies = [
  "bytemuck",
  "solana-program",
- "spl-discriminator 0.3.0",
- "spl-pod 0.3.0",
- "spl-program-error 0.5.0",
- "spl-type-length-value-derive",
+ "spl-discriminator 0.2.2",
+ "spl-pod 0.2.2",
+ "spl-program-error 0.4.1",
 ]
 
 [[package]]
 name = "spl-type-length-value"
-version = "0.4.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "422ce13429dbd41d2cee8a73931c05fda0b0c8ca156a8b0c19445642550bb61a"
+version = "0.5.0"
 dependencies = [
  "bytemuck",
  "solana-program",
- "spl-discriminator 0.2.2",
- "spl-pod 0.2.2",
- "spl-program-error 0.4.1",
+ "spl-discriminator 0.3.0",
+ "spl-pod 0.3.0",
+ "spl-program-error 0.5.0",
+ "spl-type-length-value-derive",
 ]
 
 [[package]]
@@ -7976,7 +7977,7 @@ dependencies = [
  "borsh 1.5.1",
  "solana-program",
  "spl-discriminator 0.3.0",
- "spl-type-length-value 0.4.3",
+ "spl-type-length-value 0.5.0",
 ]
 
 [[package]]
diff --git a/libraries/pod/Cargo.toml b/libraries/pod/Cargo.toml
index 8f6a76137..9f5057af3 100644
--- a/libraries/pod/Cargo.toml
+++ b/libraries/pod/Cargo.toml
@@ -15,6 +15,7 @@ borsh = ["dep:borsh"]
 base64 = { version = "0.22.1", optional = true }
 borsh = { version = "1.5.1", optional = true }
 bytemuck = { version = "1.16.1" }
+bytemuck_derive = { version = "1.7.0" }
 serde = { version = "1.0.203", optional = true }
 solana-program = "2.0.0"
 solana-zk-token-sdk = "2.0.0"
diff --git a/libraries/pod/src/optional_keys.rs b/libraries/pod/src/optional_keys.rs
index 6530fb251..ad71b1bcc 100644
--- a/libraries/pod/src/optional_keys.rs
+++ b/libraries/pod/src/optional_keys.rs
@@ -9,7 +9,7 @@ use {
     std::{convert::TryFrom, fmt, str::FromStr},
 };
 use {
-    bytemuck::{Pod, Zeroable},
+    bytemuck_derive::{Pod, Zeroable},
     solana_program::{program_error::ProgramError, program_option::COption, pubkey::Pubkey},
     solana_zk_token_sdk::zk_token_elgamal::pod::ElGamalPubkey,
 };
diff --git a/libraries/pod/src/primitives.rs b/libraries/pod/src/primitives.rs
index bf3e45578..07eb232bf 100644
--- a/libraries/pod/src/primitives.rs
+++ b/libraries/pod/src/primitives.rs
@@ -1,7 +1,7 @@
 //! primitive types that can be used in `Pod`s
 #[cfg(feature = "borsh")]
 use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
-use bytemuck::{Pod, Zeroable};
+use bytemuck_derive::{Pod, Zeroable};
 #[cfg(feature = "serde-traits")]
 use serde::{Deserialize, Serialize};
 
diff --git a/libraries/pod/src/slice.rs b/libraries/pod/src/slice.rs
index ac912dc30..4b4ea2b11 100644
--- a/libraries/pod/src/slice.rs
+++ b/libraries/pod/src/slice.rs
@@ -129,7 +129,11 @@ fn max_len_for_type<T>(data_len: usize) -> Result<usize, ProgramError> {
 
 #[cfg(test)]
 mod tests {
-    use {super::*, crate::bytemuck::pod_slice_to_bytes, bytemuck::Zeroable};
+    use {
+        super::*,
+        crate::bytemuck::pod_slice_to_bytes,
+        bytemuck_derive::{Pod, Zeroable},
+    };
 
     #[repr(C)]
     #[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
diff --git a/libraries/tlv-account-resolution/Cargo.toml b/libraries/tlv-account-resolution/Cargo.toml
index b84ffb7e8..c40e3bcc8 100644
--- a/libraries/tlv-account-resolution/Cargo.toml
+++ b/libraries/tlv-account-resolution/Cargo.toml
@@ -17,8 +17,8 @@ serde = { version = "1.0.203", optional = true }
 solana-program = "2.0.0"
 spl-discriminator = { version = "0.3.0", path = "../discriminator" }
 spl-program-error = { version = "0.5.0", path = "../program-error" }
-spl-type-length-value = { version = "0.4.3", path = "../type-length-value" }
 spl-pod = { version = "0.3.0", path = "../pod" }
+spl-type-length-value = { version = "0.5.0", path = "../type-length-value" }
 
 [dev-dependencies]
 futures = "0.3.30"
diff --git a/libraries/type-length-value/Cargo.toml b/libraries/type-length-value/Cargo.toml
index ff8c75789..2fe956ce5 100644
--- a/libraries/type-length-value/Cargo.toml
+++ b/libraries/type-length-value/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "spl-type-length-value"
-version = "0.4.3"
+version = "0.5.0"
 description = "Solana Program Library Type-Length-Value Management"
 authors = ["Solana Labs Maintainers <maintainers@solanalabs.com>"]
 repository = "https://github.com/solana-labs/solana-program-library"
diff --git a/token-collection/program/Cargo.toml b/token-collection/program/Cargo.toml
index 1e5b68f00..609274371 100644
--- a/token-collection/program/Cargo.toml
+++ b/token-collection/program/Cargo.toml
@@ -19,7 +19,7 @@ spl-token-2022 = { version = "3.0.2", path = "../../token/program-2022", feature
 spl-token-group-example = { version = "0.2", path = "../../token-group/example", features = ["no-entrypoint"] }
 spl-token-group-interface = { version = "0.2.3", path = "../../token-group/interface" }
 spl-token-metadata-interface = { version = "0.3.3", path = "../../token-metadata/interface" }
-spl-type-length-value = { version = "0.4.3", path = "../../libraries/type-length-value" }
+spl-type-length-value = { version = "0.5.0", path = "../../libraries/type-length-value" }
 
 [dev-dependencies]
 solana-program-test = "2.0.0"
diff --git a/token-group/example/Cargo.toml b/token-group/example/Cargo.toml
index cf265993d..5c0518e1c 100644
--- a/token-group/example/Cargo.toml
+++ b/token-group/example/Cargo.toml
@@ -16,7 +16,7 @@ solana-program = "2.0.0"
 spl-pod = { version = "0.3.0", path = "../../libraries/pod" }
 spl-token-2022 = { version = "3.0.2", path = "../../token/program-2022", features = ["no-entrypoint"] }
 spl-token-group-interface = { version = "0.2.3", path = "../interface" }
-spl-type-length-value = { version = "0.4.3", path = "../../libraries/type-length-value" }
+spl-type-length-value = { version = "0.5.0", path = "../../libraries/type-length-value" }
 
 [dev-dependencies]
 solana-program-test = "2.0.0"
diff --git a/token-group/interface/Cargo.toml b/token-group/interface/Cargo.toml
index d79482f44..cc9c32392 100644
--- a/token-group/interface/Cargo.toml
+++ b/token-group/interface/Cargo.toml
@@ -15,7 +15,7 @@ spl-pod = { version = "0.3.0" , path = "../../libraries/pod", features = ["borsh
 spl-program-error = { version = "0.5.0" , path = "../../libraries/program-error" }
 
 [dev-dependencies]
-spl-type-length-value = { version = "0.4.3", path = "../../libraries/type-length-value", features = ["derive"] }
+spl-type-length-value = { version = "0.5.0", path = "../../libraries/type-length-value", features = ["derive"] }
 
 [lib]
 crate-type = ["cdylib", "lib"]
diff --git a/token-metadata/example/Cargo.toml b/token-metadata/example/Cargo.toml
index 68d29de37..603d5eb74 100644
--- a/token-metadata/example/Cargo.toml
+++ b/token-metadata/example/Cargo.toml
@@ -15,7 +15,7 @@ test-sbf = []
 solana-program = "2.0.0"
 spl-token-2022 = { version = "3.0.2", path = "../../token/program-2022", features = ["no-entrypoint"] }
 spl-token-metadata-interface = { version = "0.3.3", path = "../interface" }
-spl-type-length-value = { version = "0.4.3" , path = "../../libraries/type-length-value" }
+spl-type-length-value = { version = "0.5.0" , path = "../../libraries/type-length-value" }
 spl-pod = { version = "0.3.0", path = "../../libraries/pod" }
 
 [dev-dependencies]
diff --git a/token-metadata/interface/Cargo.toml b/token-metadata/interface/Cargo.toml
index 4935712ca..1d6407018 100644
--- a/token-metadata/interface/Cargo.toml
+++ b/token-metadata/interface/Cargo.toml
@@ -16,7 +16,7 @@ serde = { version = "1.0.203", optional = true }
 solana-program = "2.0.0"
 spl-discriminator = { version = "0.3.0", path = "../../libraries/discriminator" }
 spl-program-error = { version = "0.5.0", path = "../../libraries/program-error" }
-spl-type-length-value = { version = "0.4.3", path = "../../libraries/type-length-value" }
+spl-type-length-value = { version = "0.5.0", path = "../../libraries/type-length-value" }
 spl-pod = { version = "0.3.0", path = "../../libraries/pod", features = [
   "borsh",
 ] }
diff --git a/token/program-2022/Cargo.toml b/token/program-2022/Cargo.toml
index c7f7a2fe2..5d135806c 100644
--- a/token/program-2022/Cargo.toml
+++ b/token/program-2022/Cargo.toml
@@ -34,7 +34,7 @@ spl-token = { version = "6.0",  path = "../program", features = ["no-entrypoint"
 spl-token-group-interface = { version = "0.2.3", path = "../../token-group/interface" }
 spl-token-metadata-interface = { version = "0.3.3", path = "../../token-metadata/interface" }
 spl-transfer-hook-interface = { version = "0.6.3", path = "../transfer-hook/interface" }
-spl-type-length-value = { version = "0.4.3", path = "../../libraries/type-length-value" }
+spl-type-length-value = { version = "0.5.0", path = "../../libraries/type-length-value" }
 spl-pod = { version = "0.3.0", path = "../../libraries/pod" }
 thiserror = "1.0"
 serde = { version = "1.0.203", optional = true }
diff --git a/token/transfer-hook/example/Cargo.toml b/token/transfer-hook/example/Cargo.toml
index 65dac3a22..171ccd132 100644
--- a/token/transfer-hook/example/Cargo.toml
+++ b/token/transfer-hook/example/Cargo.toml
@@ -19,7 +19,7 @@ solana-program = "2.0.0"
 spl-tlv-account-resolution = { version = "0.6.3" , path = "../../../libraries/tlv-account-resolution" }
 spl-token-2022 = { version = "3.0.2",  path = "../../program-2022", features = ["no-entrypoint"] }
 spl-transfer-hook-interface = { version = "0.6.3" , path = "../interface" }
-spl-type-length-value = { version = "0.4.3" , path = "../../../libraries/type-length-value" }
+spl-type-length-value = { version = "0.5.0" , path = "../../../libraries/type-length-value" }
 
 [dev-dependencies]
 solana-program-test = "2.0.0"
diff --git a/token/transfer-hook/interface/Cargo.toml b/token/transfer-hook/interface/Cargo.toml
index aa7bee193..3d3f47a23 100644
--- a/token/transfer-hook/interface/Cargo.toml
+++ b/token/transfer-hook/interface/Cargo.toml
@@ -14,7 +14,7 @@ solana-program = "2.0.0"
 spl-discriminator = { version = "0.3.0" , path = "../../../libraries/discriminator" }
 spl-program-error = { version = "0.5.0" , path = "../../../libraries/program-error" }
 spl-tlv-account-resolution = { version = "0.6.3" , path = "../../../libraries/tlv-account-resolution" }
-spl-type-length-value = { version = "0.4.3" , path = "../../../libraries/type-length-value" }
+spl-type-length-value = { version = "0.5.0" , path = "../../../libraries/type-length-value" }
 spl-pod = { version = "0.3.0", path = "../../../libraries/pod" }
 
 [lib]


Test patch:
diff --git a/libraries/type-length-value-derive-test/Cargo.toml b/libraries/type-length-value-derive-test/Cargo.toml
index 5ab0d1b67..124e1cc40 100644
--- a/libraries/type-length-value-derive-test/Cargo.toml
+++ b/libraries/type-length-value-derive-test/Cargo.toml
@@ -11,6 +11,6 @@ edition = "2021"
 borsh = "1.5.1"
 solana-program = "2.0.0"
 spl-discriminator = { version = "0.3.0", path = "../discriminator" }
-spl-type-length-value = { version = "0.4.3", path = "../type-length-value", features = [
+spl-type-length-value = { version = "0.5.0", path = "../type-length-value", features = [
   "derive",
 ] }