Skip to content

Commit 6621213

Browse files
authored
rust-legacy: Lighten dependencies (#662)
#### Problem The rust token-client has dependencies on solana-program-test and solana-sdk, which are very heavy to build, but none of them are strictly required. #### Summary of changes Remove all usage of solana-sdk, and gate solana-program-test usage behind the `dev-context-only-utils` feature, since those are only ever used in tests. On my machine, build times go down from ~1m to 18s!
1 parent 0da6eb8 commit 6621213

File tree

4 files changed

+76
-24
lines changed

4 files changed

+76
-24
lines changed

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/rust-legacy/Cargo.toml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ edition = { workspace = true }
1212

1313
[features]
1414
default = ["display"]
15+
dev-context-only-utils = [
16+
"dep:solana-banks-client",
17+
"dep:solana-banks-interface",
18+
"dep:solana-program-test",
19+
]
1520
display = ["dep:solana-cli-output"]
1621

1722
[dependencies]
@@ -20,13 +25,25 @@ bincode = "1.3.2"
2025
bytemuck = "1.23.1"
2126
futures = "0.3.31"
2227
futures-util = "0.3"
23-
solana-banks-interface = "2.3.4"
28+
solana-account = "2.2.1"
29+
solana-banks-client = { version = "2.3.4", optional = true }
30+
solana-banks-interface = { version = "2.3.4", optional = true }
31+
solana-compute-budget-interface = "2.2.1"
2432
solana-cli-output = { version = "2.2.0", optional = true }
25-
solana-program-test = "2.3.4"
33+
solana-hash = "2.2.1"
34+
solana-instruction = "2.2.1"
35+
solana-message = "2.2.1"
36+
solana-packet = "2.2.1"
37+
solana-program-error = "2.2.1"
38+
solana-program-pack = "2.2.1"
39+
solana-program-test = { version = "2.3.4", optional = true }
40+
solana-pubkey = "2.2.1"
2641
solana-rpc-client = "2.3.4"
2742
solana-rpc-client-api = "2.3.4"
28-
solana-sdk = "2.2.1"
43+
solana-signature = "2.2.1"
44+
solana-signer = "2.2.1"
2945
solana-system-interface = "1"
46+
solana-transaction = "2.2.1"
3047
spl-associated-token-account-client = { version = "2.0.0" }
3148
spl-elgamal-registry = { version = "0.3.0",features = ["no-entrypoint"], path = "../../confidential-transfer/elgamal-registry"}
3249
spl-memo = { version = "6.0", features = ["no-entrypoint"] }
@@ -38,6 +55,7 @@ spl-token-2022 = { version = "9.0.0", features = ["no-entrypoint"], path = "../.
3855
spl-token-group-interface = { version = "0.6.0" }
3956
spl-token-metadata-interface = { version = "0.7.0" }
4057
spl-transfer-hook-interface = { version = "0.10.0" }
58+
tokio = "1"
4159
thiserror = "2.0"
4260

4361
[dev-dependencies]
@@ -46,8 +64,11 @@ borsh = "1.5.7"
4664
bytemuck = "1.23.1"
4765
futures-util = "0.3"
4866
solana-program = "2.3.0"
67+
solana-program-test = "2.3.4"
68+
solana-sdk = "2.2.1"
4969
spl-associated-token-account = { version = "7.0.0" }
5070
spl-pod = { version = "0.5.1" }
5171
spl-instruction-padding = { version = "0.3.0", features = ["no-entrypoint"] }
5272
spl-tlv-account-resolution = { version = "0.10.0" }
73+
spl-token-client = { path = ".", features = ["dev-context-only-utils"] }
5374
test-case = "3.3"

clients/rust-legacy/src/client.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
use {
22
async_trait::async_trait,
3-
solana_banks_interface::BanksTransactionResultWithSimulation,
4-
solana_program_test::{tokio::sync::Mutex, BanksClient, ProgramTestContext},
3+
solana_account::Account,
4+
solana_hash::Hash,
5+
solana_pubkey::Pubkey,
56
solana_rpc_client::nonblocking::rpc_client::RpcClient,
67
solana_rpc_client_api::response::RpcSimulateTransactionResult,
7-
solana_sdk::{
8-
account::Account, hash::Hash, pubkey::Pubkey, signature::Signature,
9-
transaction::Transaction,
10-
},
8+
solana_signature::Signature,
9+
solana_transaction::Transaction,
1110
std::{fmt, future::Future, pin::Pin, sync::Arc},
1211
};
1312

13+
#[cfg(feature = "dev-context-only-utils")]
14+
use {
15+
solana_banks_client::BanksClient, solana_banks_interface::BanksTransactionResultWithSimulation,
16+
solana_program_test::ProgramTestContext, tokio::sync::Mutex,
17+
};
18+
1419
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
1520

1621
/// Basic trait for sending transactions to validator.
@@ -30,6 +35,7 @@ pub trait SimulationResult {
3035

3136
/// Extends basic `SendTransaction` trait with function `send` where client is
3237
/// `&mut BanksClient`. Required for `ProgramBanksClient`.
38+
#[cfg(feature = "dev-context-only-utils")]
3339
pub trait SendTransactionBanksClient: SendTransaction {
3440
fn send<'a>(
3541
&self,
@@ -40,6 +46,7 @@ pub trait SendTransactionBanksClient: SendTransaction {
4046

4147
/// Extends basic `SimulateTransaction` trait with function `simulation` where
4248
/// client is `&mut BanksClient`. Required for `ProgramBanksClient`.
49+
#[cfg(feature = "dev-context-only-utils")]
4350
pub trait SimulateTransactionBanksClient: SimulateTransaction {
4451
fn simulate<'a>(
4552
&self,
@@ -50,12 +57,15 @@ pub trait SimulateTransactionBanksClient: SimulateTransaction {
5057

5158
/// Send transaction to validator using `BanksClient::process_transaction`.
5259
#[derive(Debug, Clone, Copy, Default)]
60+
#[cfg(feature = "dev-context-only-utils")]
5361
pub struct ProgramBanksClientProcessTransaction;
5462

63+
#[cfg(feature = "dev-context-only-utils")]
5564
impl SendTransaction for ProgramBanksClientProcessTransaction {
5665
type Output = ();
5766
}
5867

68+
#[cfg(feature = "dev-context-only-utils")]
5969
impl SendTransactionBanksClient for ProgramBanksClientProcessTransaction {
6070
fn send<'a>(
6171
&self,
@@ -71,6 +81,7 @@ impl SendTransactionBanksClient for ProgramBanksClientProcessTransaction {
7181
}
7282
}
7383

84+
#[cfg(feature = "dev-context-only-utils")]
7485
impl SimulationResult for BanksTransactionResultWithSimulation {
7586
fn get_compute_units_consumed(&self) -> ProgramClientResult<u64> {
7687
self.simulation_details
@@ -80,10 +91,12 @@ impl SimulationResult for BanksTransactionResultWithSimulation {
8091
}
8192
}
8293

94+
#[cfg(feature = "dev-context-only-utils")]
8395
impl SimulateTransaction for ProgramBanksClientProcessTransaction {
8496
type SimulationOutput = BanksTransactionResultWithSimulation;
8597
}
8698

99+
#[cfg(feature = "dev-context-only-utils")]
87100
impl SimulateTransactionBanksClient for ProgramBanksClientProcessTransaction {
88101
fn simulate<'a>(
89102
&self,
@@ -213,23 +226,27 @@ where
213226
) -> ProgramClientResult<ST::SimulationOutput>;
214227
}
215228

229+
#[cfg(feature = "dev-context-only-utils")]
216230
enum ProgramBanksClientContext {
217231
Client(Arc<Mutex<BanksClient>>),
218232
Context(Arc<Mutex<ProgramTestContext>>),
219233
}
220234

221235
/// Program client for `BanksClient` from crate `solana-program-test`.
236+
#[cfg(feature = "dev-context-only-utils")]
222237
pub struct ProgramBanksClient<ST> {
223238
context: ProgramBanksClientContext,
224239
send: ST,
225240
}
226241

242+
#[cfg(feature = "dev-context-only-utils")]
227243
impl<ST> fmt::Debug for ProgramBanksClient<ST> {
228244
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
229245
f.debug_struct("ProgramBanksClient").finish()
230246
}
231247
}
232248

249+
#[cfg(feature = "dev-context-only-utils")]
233250
impl<ST> ProgramBanksClient<ST> {
234251
fn new(context: ProgramBanksClientContext, send: ST) -> Self {
235252
Self { context, send }
@@ -260,6 +277,7 @@ impl<ST> ProgramBanksClient<ST> {
260277
}
261278
}
262279

280+
#[cfg(feature = "dev-context-only-utils")]
263281
#[async_trait]
264282
impl<ST> ProgramClient<ST> for ProgramBanksClient<ST>
265283
where

clients/rust-legacy/src/token.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,19 @@ use {
55
bytemuck::{bytes_of, Pod},
66
futures::future::join_all,
77
futures_util::TryFutureExt,
8-
solana_program_test::tokio::time,
9-
solana_sdk::{
10-
account::Account as BaseAccount,
11-
compute_budget::ComputeBudgetInstruction,
12-
hash::Hash,
13-
instruction::{AccountMeta, Instruction},
14-
message::Message,
15-
packet::PACKET_DATA_SIZE,
16-
program_error::ProgramError,
17-
program_pack::Pack,
18-
pubkey::Pubkey,
19-
signature::Signature,
20-
signer::{signers::Signers, Signer, SignerError},
21-
transaction::Transaction,
22-
},
8+
solana_account::Account as BaseAccount,
9+
solana_compute_budget_interface::ComputeBudgetInstruction,
10+
solana_hash::Hash,
11+
solana_instruction::{AccountMeta, Instruction},
12+
solana_message::Message,
13+
solana_packet::PACKET_DATA_SIZE,
14+
solana_program_error::ProgramError,
15+
solana_program_pack::Pack,
16+
solana_pubkey::Pubkey,
17+
solana_signature::Signature,
18+
solana_signer::{signers::Signers, Signer, SignerError},
2319
solana_system_interface::instruction as system_instruction,
20+
solana_transaction::Transaction,
2421
spl_associated_token_account_client::{
2522
address::get_associated_token_address_with_program_id,
2623
instruction::{
@@ -87,6 +84,7 @@ use {
8784
time::{Duration, Instant},
8885
},
8986
thiserror::Error,
87+
tokio::time,
9088
};
9189

9290
#[derive(Error, Debug)]

0 commit comments

Comments
 (0)