Skip to content

Commit

Permalink
Prefer explicitly using serde_derive instead of the "derive" feature …
Browse files Browse the repository at this point in the history
…of serde (#1329)

* use serde_derive instead of the derive feature of serde

* make serde_derive version match serde version

* remove serde dep entirely from programs/address-lookup-table

* replace remaining usage of serde "derive" feature

* update lock files

* explicitly use serde_derive in svm and frozen-abi

* add comments about serde and serde_derive versions matching
  • Loading branch information
kevinheavey authored May 14, 2024
1 parent d54e808 commit 59e3eaa
Show file tree
Hide file tree
Showing 39 changed files with 92 additions and 79 deletions.
10 changes: 9 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ rustversion = "1.0.14"
scopeguard = "1.2.0"
semver = "1.0.22"
seqlock = "0.2.0"
serde = "1.0.197"
serde = "1.0.197" # must match the serde_derive version, see https://github.com/serde-rs/serde/issues/2584#issuecomment-1685252251
serde_bytes = "0.11.14"
serde_derive = "1.0.103"
serde_derive = "1.0.197" # must match the serde version, see https://github.com/serde-rs/serde/issues/2584#issuecomment-1685252251
serde_json = "1.0.115"
serde_with = { version = "2.3.3", default-features = false }
serde_yaml = "0.9.34"
Expand Down
3 changes: 2 additions & 1 deletion banks-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ license = { workspace = true }
edition = { workspace = true }

[dependencies]
serde = { workspace = true, features = ["derive"] }
serde = { workspace = true }
serde_derive = { workspace = true }
solana-sdk = { workspace = true }
tarpc = { workspace = true, features = ["full"] }

Expand Down
2 changes: 1 addition & 1 deletion banks-interface/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(deprecated)]

use {
serde::{Deserialize, Serialize},
serde_derive::{Deserialize, Serialize},
solana_sdk::{
account::Account,
clock::Slot,
Expand Down
3 changes: 2 additions & 1 deletion cargo-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ flate2 = { workspace = true }
hex = { workspace = true }
hyper = { workspace = true, features = ["full"] }
log = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
sha2 = { workspace = true }
solana-clap-utils = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion cargo-registry/src/crate_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
},
hyper::body::Bytes,
log::*,
serde::{Deserialize, Serialize},
serde_derive::{Deserialize, Serialize},
serde_json::from_slice,
sha2::{Digest, Sha256},
solana_cli::program_v4::{process_deploy_program, process_dump, read_and_verify_elf},
Expand Down
2 changes: 1 addition & 1 deletion cargo-registry/src/sparse_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
response_builder,
},
log::info,
serde::{Deserialize, Serialize},
serde_derive::{Deserialize, Serialize},
std::{
collections::BTreeMap,
sync::{Arc, RwLock},
Expand Down
2 changes: 1 addition & 1 deletion frozen-abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = { workspace = true }
bs58 = { workspace = true }
bv = { workspace = true, features = ["serde"] }
log = { workspace = true, features = ["std"] }
serde = { workspace = true, features = ["derive", "rc"] }
serde = { workspace = true, features = ["rc"] }
serde_derive = { workspace = true }
sha2 = { workspace = true }
solana-frozen-abi-macro = { workspace = true }
Expand Down
40 changes: 20 additions & 20 deletions frozen-abi/src/abi_digester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,22 +542,22 @@ mod tests {
type TestTypeAlias = i32;

#[frozen_abi(digest = "Apwkp9Ah9zKirzwuSzVoU9QRc43EghpkD1nGVakJLfUY")]
#[derive(Serialize, AbiExample)]
#[derive(serde_derive::Serialize, AbiExample)]
struct TestStruct {
test_field: i8,
test_field2: i8,
}

#[frozen_abi(digest = "4LbuvQLX78XPbm4hqqZcHFHpseDJcw4qZL9EUZXSi2Ss")]
#[derive(Serialize, AbiExample)]
#[derive(serde_derive::Serialize, AbiExample)]
struct TestTupleStruct(i8, i8);

#[frozen_abi(digest = "FNHa6mNYJZa59Fwbipep5dXRXcFreaDHn9jEUZEH1YLv")]
#[derive(Serialize, AbiExample)]
#[derive(serde_derive::Serialize, AbiExample)]
struct TestNewtypeStruct(i8);

#[frozen_abi(digest = "Hbs1X2X7TF2gFEfsspwfZ1JKr8ZGbLY3uidQBebqcMYt")]
#[derive(Serialize, AbiExample)]
#[derive(serde_derive::Serialize, AbiExample)]
struct Foo<'a> {
#[serde(with = "serde_bytes")]
data1: Vec<u8>,
Expand All @@ -568,21 +568,21 @@ mod tests {
}

#[frozen_abi(digest = "5qio5qYurHDv6fq5kcwP2ue2RBEazSZF8CPk2kUuwC2j")]
#[derive(Serialize, AbiExample)]
#[derive(serde_derive::Serialize, AbiExample)]
struct TestStructReversed {
test_field2: i8,
test_field: i8,
}

#[frozen_abi(digest = "DLLrTWprsMjdJGR447A4mui9HpqxbKdsFXBfaWPcwhny")]
#[derive(Serialize, AbiExample)]
#[derive(serde_derive::Serialize, AbiExample)]
struct TestStructAnotherType {
test_field: i16,
test_field2: i8,
}

#[frozen_abi(digest = "GMeECsxg37a5qznstWXeeX3d6HXs6j12oB4SKaZZuNJk")]
#[derive(Serialize, AbiExample)]
#[derive(serde_derive::Serialize, AbiExample)]
struct TestNest {
nested_field: [TestStruct; 5],
}
Expand All @@ -591,34 +591,34 @@ mod tests {
type TestUnitStruct = std::marker::PhantomData<i8>;

#[frozen_abi(digest = "6kj3mPXbzWTwZho48kZWxZjuseLU2oiqhbpqca4DmcRq")]
#[derive(Serialize, AbiExample, AbiEnumVisitor)]
#[derive(serde_derive::Serialize, AbiExample, AbiEnumVisitor)]
enum TestEnum {
Variant1,
Variant2,
}

#[frozen_abi(digest = "3WqYwnbQEdu6iPZi5LJa2b5kw55hxBtZdqFqiViFCKPo")]
#[derive(Serialize, AbiExample, AbiEnumVisitor)]
#[derive(serde_derive::Serialize, AbiExample, AbiEnumVisitor)]
enum TestTupleVariant {
Variant1(u8, u16),
Variant2(u8, u16),
}

#[frozen_abi(digest = "4E9gJjvKiETBeZ8dybZPAQ7maaHTHFucmLqgX2m6yrBh")]
#[derive(Serialize, AbiExample)]
#[derive(serde_derive::Serialize, AbiExample)]
struct TestVecEnum {
enums: Vec<TestTupleVariant>,
}

#[derive(Serialize, AbiExample)]
#[derive(serde_derive::Serialize, AbiExample)]
struct TestGenericStruct<T: Ord> {
test_field: T,
}

#[frozen_abi(digest = "2Dr5k3Z513mV4KrGeUfcMwjsVHLmVyLiZarmfnXawEbf")]
type TestConcreteStruct = TestGenericStruct<i64>;

#[derive(Serialize, AbiExample, AbiEnumVisitor)]
#[derive(serde_derive::Serialize, AbiExample, AbiEnumVisitor)]
enum TestGenericEnum<T: serde::Serialize + Sized + Ord> {
TestVariant(T),
}
Expand Down Expand Up @@ -647,7 +647,7 @@ mod tests {
#[frozen_abi(digest = "7rH7gnEhJ8YouzqPT6VPyUDELvL51DGednSPcoLXG2rg")]
type TestOptionWithIsize = Option<isize>;

#[derive(Serialize, AbiExample, AbiEnumVisitor)]
#[derive(serde_derive::Serialize, AbiExample, AbiEnumVisitor)]
enum TestMyOption<T: serde::Serialize + Sized + Ord> {
None,
Some(T),
Expand All @@ -663,7 +663,7 @@ mod tests {

bitflags::bitflags! {
#[frozen_abi(digest = "HhKNkaeAd7AohTb8S8sPKjAWwzxWY2DPz5FvkWmx5bSH")]
#[derive(Serialize, Deserialize)]
#[derive(serde_derive::Serialize, serde_derive::Deserialize)]
struct TestFlags: u8 {
const TestBit = 0b0000_0001;
}
Expand All @@ -688,20 +688,20 @@ mod tests {

mod skip_should_be_same {
#[frozen_abi(digest = "4LbuvQLX78XPbm4hqqZcHFHpseDJcw4qZL9EUZXSi2Ss")]
#[derive(Serialize, AbiExample)]
#[derive(serde_derive::Serialize, AbiExample)]
#[allow(dead_code)]
struct TestTupleStruct(i8, i8, #[serde(skip)] i8);

#[frozen_abi(digest = "Hk7BYjZ71upWQJAx2PqoNcapggobPmFbMJd34xVdvRso")]
#[derive(Serialize, AbiExample)]
#[derive(serde_derive::Serialize, AbiExample)]
struct TestStruct {
test_field: i8,
#[serde(skip)]
_skipped_test_field: i8,
}

#[frozen_abi(digest = "6kj3mPXbzWTwZho48kZWxZjuseLU2oiqhbpqca4DmcRq")]
#[derive(Serialize, AbiExample, AbiEnumVisitor)]
#[derive(serde_derive::Serialize, AbiExample, AbiEnumVisitor)]
enum TestEnum {
Variant1,
Variant2,
Expand All @@ -711,18 +711,18 @@ mod tests {
}

#[frozen_abi(digest = "3WqYwnbQEdu6iPZi5LJa2b5kw55hxBtZdqFqiViFCKPo")]
#[derive(Serialize, AbiExample, AbiEnumVisitor)]
#[derive(serde_derive::Serialize, AbiExample, AbiEnumVisitor)]
enum TestTupleVariant {
Variant1(u8, u16),
Variant2(u8, u16, #[serde(skip)] u32),
}
}

#[frozen_abi(digest = "B1PcwZdUfGnxaRid9e6ZwkST3NZ2KUEYobA1DkxWrYLP")]
#[derive(Serialize, AbiExample)]
#[derive(serde_derive::Serialize, AbiExample)]
struct TestArcWeak(std::sync::Weak<u64>);

#[frozen_abi(digest = "4R8uCLR1BVU1aFgkSaNyKcFD1FeM6rGdsjbJBFpnqx4v")]
#[derive(Serialize, AbiExample)]
#[derive(serde_derive::Serialize, AbiExample)]
struct TestRcWeak(std::rc::Weak<u64>);
}
5 changes: 0 additions & 5 deletions frozen-abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ mod hash;
#[macro_use]
extern crate solana_frozen_abi_macro;

#[cfg(RUSTC_WITH_SPECIALIZATION)]
#[cfg(test)]
#[macro_use]
extern crate serde_derive;

// Not public API. Referenced by macro-generated code.
#[doc(hidden)]
pub mod __private {
Expand Down
3 changes: 2 additions & 1 deletion install/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ nix = { workspace = true, features = ["signal"] }
reqwest = { workspace = true, features = ["blocking", "brotli", "deflate", "gzip", "rustls-tls", "json"] }
scopeguard = { workspace = true }
semver = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde = { workspace = true }
serde_derive = { workspace = true }
serde_yaml = { workspace = true }
serde_yaml_08 = { package = "serde_yaml", version = "0.8.26" }
solana-clap-utils = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion install/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
console::{style, Emoji},
crossbeam_channel::unbounded,
indicatif::{ProgressBar, ProgressStyle},
serde::{Deserialize, Serialize},
serde_derive::{Deserialize, Serialize},
solana_config_program::{config_instruction, get_config_data, ConfigState},
solana_rpc_client::rpc_client::RpcClient,
solana_sdk::{
Expand Down
2 changes: 1 addition & 1 deletion install/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
crate::update_manifest::UpdateManifest,
serde::{Deserialize, Serialize},
serde_derive::{Deserialize, Serialize},
solana_sdk::pubkey::Pubkey,
std::{
fs::{create_dir_all, File},
Expand Down
2 changes: 1 addition & 1 deletion install/src/update_manifest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
serde::{Deserialize, Serialize},
serde_derive::{Deserialize, Serialize},
solana_config_program::ConfigState,
solana_sdk::{
hash::Hash,
Expand Down
3 changes: 2 additions & 1 deletion ledger-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ log = { workspace = true }
num_cpus = { workspace = true }
rayon = { workspace = true }
regex = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
solana-account-decoder = { workspace = true }
solana-accounts-db = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use {
},
dashmap::DashMap,
log::*,
serde::Serialize,
serde_derive::Serialize,
solana_account_decoder::UiAccountEncoding,
solana_accounts_db::{
accounts_db::CalcAccountsHashDataSource, accounts_index::ScanConfig,
Expand Down
8 changes: 3 additions & 5 deletions ledger-tool/src/output.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use {
crate::ledger_utils::get_program_ids,
chrono::{Local, TimeZone},
serde::{
ser::{Impossible, SerializeSeq, SerializeStruct, Serializer},
Deserialize, Serialize,
},
serde::ser::{Impossible, SerializeSeq, SerializeStruct, Serializer},
serde_derive::{Deserialize, Serialize},
solana_account_decoder::{UiAccount, UiAccountData, UiAccountEncoding},
solana_accounts_db::accounts_index::ScanConfig,
solana_cli_output::{
Expand Down Expand Up @@ -742,7 +740,7 @@ impl AccountsScanner {
}
}

impl Serialize for AccountsScanner {
impl serde::Serialize for AccountsScanner {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
Expand Down
2 changes: 1 addition & 1 deletion ledger-tool/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use {
crate::{args::*, canonicalize_ledger_path, ledger_utils::*},
clap::{value_t, App, AppSettings, Arg, ArgMatches, SubCommand},
log::*,
serde::{Deserialize, Serialize},
serde_derive::{Deserialize, Serialize},
serde_json::Result,
solana_bpf_loader_program::{
create_vm, load_program_from_bytes, serialization::serialize_parameters,
Expand Down
Loading

0 comments on commit 59e3eaa

Please sign in to comment.