Skip to content

Commit ff55d10

Browse files
chore: add a feature to compile only types needed for the SDK (#117)
* chore: allow to compile only core types to export * chore: rename core feature to sdk & refactor * chore: simplify sdk & program feature * chore: group imports
1 parent e8d0393 commit ff55d10

File tree

3 files changed

+68
-34
lines changed

3 files changed

+68
-34
lines changed

Cargo.lock

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "magicblock-delegation-program"
33
description = "Delegation program for the Ephemeral Rollups"
4-
version = "1.1.2"
4+
version = "1.1.3"
55
authors = ["Magicblock Labs <dev@magicblock.gg>"]
66
edition = "2021"
77
license = "MIT"
@@ -27,34 +27,48 @@ name = "dlp"
2727

2828
[features]
2929
no-entrypoint = []
30-
default = ["solana-security-txt"]
30+
sdk = ["no-entrypoint"]
31+
program = [
32+
"dep:pinocchio",
33+
"dep:pinocchio-log",
34+
"dep:pinocchio-pubkey",
35+
"dep:pinocchio-system",
36+
"dep:rkyv",
37+
"dep:solana-curve25519",
38+
]
39+
40+
# Default build = program path + security txt
41+
default = [
42+
"program",
43+
"solana-security-txt",
44+
]
3145
unit_test_config = []
3246
log-cost = []
3347
logging = []
3448

3549
[dependencies]
3650
borsh = { version = "1.5.3", features = [ "derive" ] }
37-
paste = "^1.0"
38-
solana-program = "2.2"
39-
bytemuck = { version = "1.21", features = [ "derive" ] }
51+
solana-program = { version = ">=1.16" }
52+
bytemuck = { version = ">=1", features = [ "derive" ] }
4053
num_enum = "^0.7.2"
41-
thiserror = "^1.0.57"
42-
solana-security-txt = { version = "1.1.1", optional = true }
43-
solana-curve25519 = "2.2"
44-
bincode = "1.3.3"
45-
pinocchio-log = "0.5.0"
46-
pinocchio = "0.9.2"
47-
pinocchio-pubkey = "0.3.0"
48-
pinocchio-system = "0.3.0"
49-
rkyv = "0.7.45"
54+
thiserror = { version = ">=1" }
55+
solana-security-txt = { version = ">=1.1", optional = true }
56+
solana-curve25519 = { version = ">=2.2", optional = true }
57+
bincode = { version = "^1.3" }
58+
pinocchio-log = { version = "0.5.0", optional = true }
59+
pinocchio = { version = "0.9.2", optional = true }
60+
pinocchio-pubkey = { version = "0.3.0", optional = true }
61+
pinocchio-system = { version = "0.3.0", optional = true }
62+
rkyv = { version = "0.7.45", optional = true }
5063
static_assertions = "1.1.0"
51-
strum = { version = "0.27.2", features = ["derive"] }
64+
strum = { version = ">=0.27", features = ["derive"] }
5265

5366
[dev-dependencies]
54-
base64 = "0.22.1"
55-
rand = "0.8.5"
56-
solana-program-test = "2.2"
57-
solana-sdk = "2.2"
58-
tokio = { version = "1.0", features = ["full"] }
67+
rand = { version = "=0.8.5", features = ["small_rng"] }
68+
solana-program-test = ">=1.16"
69+
solana-sdk = ">=1.16"
70+
tokio = { version = "^1.0", features = ["full"] }
5971
magicblock-delegation-program = { path = ".", features = ["unit_test_config"] }
6072

73+
[lints.rust]
74+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] }

src/lib.rs

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,45 @@
1-
#![allow(unexpected_cfgs)] // silence clippy for target_os solana and other solana program custom features
1+
#![allow(unexpected_cfgs)]
2+
3+
// Exactly one of `sdk` or `program` must be enabled
4+
#[cfg(all(feature = "sdk", feature = "program"))]
5+
compile_error!("Features `sdk` and `program` are mutually exclusive. Enable exactly one.");
6+
7+
#[cfg(all(not(feature = "sdk"), not(feature = "program")))]
8+
compile_error!(
9+
"Enable either `program` (default) or `sdk`. Building with neither is not supported."
10+
);
11+
12+
#[cfg(not(feature = "sdk"))]
13+
use {
14+
crate::discriminator::DlpDiscriminator,
15+
solana_program::{
16+
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
17+
pubkey::Pubkey,
18+
},
19+
};
220

3-
use crate::discriminator::DlpDiscriminator;
4-
use pinocchio_log::log;
5-
use solana_program::account_info::AccountInfo;
621
use solana_program::declare_id;
7-
use solana_program::entrypoint::ProgramResult;
8-
use solana_program::program_error::ProgramError;
9-
use solana_program::pubkey::Pubkey;
1022

1123
#[cfg(feature = "logging")]
1224
use solana_program::msg;
1325

1426
pub mod args;
1527
pub mod consts;
28+
#[cfg(not(feature = "sdk"))]
1629
mod discriminator;
30+
#[cfg(not(feature = "sdk"))]
1731
pub mod error;
32+
#[cfg(not(feature = "sdk"))]
1833
pub mod instruction_builder;
1934
pub mod pda;
2035
pub mod state;
2136

37+
#[cfg(not(feature = "sdk"))]
2238
mod diff;
39+
#[cfg(not(feature = "sdk"))]
2340
mod processor;
2441

42+
#[cfg(not(feature = "sdk"))]
2543
pub use diff::*;
2644

2745
#[cfg(feature = "log-cost")]
@@ -32,20 +50,22 @@ mod entrypoint;
3250

3351
declare_id!("DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh");
3452

53+
#[cfg(not(feature = "sdk"))]
3554
pub mod fast {
3655
pinocchio_pubkey::declare_id!("DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh");
3756
}
3857

39-
#[cfg(all(not(feature = "no-entrypoint"), feature = "solana-security-txt"))]
58+
#[cfg(feature = "solana-security-txt")]
4059
solana_security_txt::security_txt! {
4160
name: "MagicBlock Delegation Program",
42-
project_url: "https://magicblock.gg",
61+
project_url: "https://magicblock.xyz",
4362
contacts: "email:dev@magicblock.gg,twitter:@magicblock",
4463
policy: "https://github.com/magicblock-labs/delegation-program/blob/master/LICENSE.md",
4564
preferred_languages: "en",
4665
source_code: "https://github.com/magicblock-labs/delegation-program"
4766
}
4867

68+
#[cfg(not(feature = "sdk"))]
4969
pub fn fast_process_instruction(
5070
program_id: &pinocchio::pubkey::Pubkey,
5171
accounts: &[pinocchio::account_info::AccountInfo],
@@ -62,7 +82,7 @@ pub fn fast_process_instruction(
6282
let discriminator = match DlpDiscriminator::try_from(discriminator_bytes[0]) {
6383
Ok(discriminator) => discriminator,
6484
Err(_) => {
65-
log!("Failed to read and parse discriminator");
85+
pinocchio_log::log!("Failed to read and parse discriminator");
6686
return Some(Err(
6787
pinocchio::program_error::ProgramError::InvalidInstructionData,
6888
));
@@ -95,6 +115,7 @@ pub fn fast_process_instruction(
95115
}
96116
}
97117

118+
#[cfg(not(feature = "sdk"))]
98119
pub fn slow_process_instruction(
99120
program_id: &Pubkey,
100121
accounts: &[AccountInfo],
@@ -139,7 +160,8 @@ pub fn slow_process_instruction(
139160
processor::process_call_handler(program_id, accounts, data)?
140161
}
141162
_ => {
142-
log!("PANIC: Instruction must be processed by fast_process_instruction");
163+
#[cfg(feature = "logging")]
164+
msg!("PANIC: Instruction must be processed by fast_process_instruction");
143165
return Err(ProgramError::InvalidInstructionData);
144166
}
145167
}

0 commit comments

Comments
 (0)