| Crates.io | elf-magic |
| lib.rs | elf-magic |
| version | 0.6.0 |
| created_at | 2025-06-25 03:29:34.44029+00 |
| updated_at | 2025-06-28 04:47:34.436373+00 |
| description | Automatic compile-time ELF exports for Solana programs. One-liner integration, zero config, just works. ✨ |
| homepage | https://github.com/levicook/elf-magic |
| repository | https://github.com/levicook/elf-magic |
| max_upload_size | |
| id | 1725271 |
| size | 185,124 |
Automatic compile-time ELF exports for Solana programs. One-liner integration, zero config, just works.
Stop wrestling with Solana program builds. elf-magic automatically discovers all your programs, builds them, and generates clean Rust code so your ELF bytes are always available as constants.
# Create an ELF crate in your workspace
cargo new my-elves --lib
Add to my-elves/Cargo.toml:
[build-dependencies]
elf-magic = "0.5"
Add to my-elves/build.rs:
fn main() { elf_magic::build().unwrap(); }
cargo build # magic ✨
After building, your ELF crate exports constants for every Solana program in your workspace:
Your hand-written src/lib.rs:
//! ELF binaries for my Solana programs.
include!(env!("ELF_MAGIC_GENERATED_PATH"));
Generated at build time (in $OUT_DIR):
pub const TOKEN_MANAGER_ELF: &[u8] = include_bytes!(env!("TOKEN_MANAGER_ELF_PATH"));
pub const GOVERNANCE_ELF: &[u8] = include_bytes!(env!("GOVERNANCE_ELF_PATH"));
pub fn elves() -> Vec<(&'static str, &'static [u8])> {
vec![
("token_manager", TOKEN_MANAGER_ELF),
("governance", GOVERNANCE_ELF),
]
}
Use your programs anywhere:
use my_elves::{TOKEN_MANAGER_ELF, GOVERNANCE_ELF};
// Deploy, test, embed - whatever you need
let program_id = deploy_program(TOKEN_MANAGER_ELF)?;
Zero config, just works
cargo build # Discovers and builds all programs automatically
Perfect for: Single workspaces, development, getting started
Multi-workspace with exclusions
[package.metadata.elf-magic]
mode = "permissive"
global_deny = ["package:*-test"]
workspaces = [
{ manifest_path = "./Cargo.toml", deny = ["target:dev*"] },
{ manifest_path = "examples/Cargo.toml" }
]
Perfect for: Complex repos, excluding test programs, multi-workspace projects
Precision targeting
[package.metadata.elf-magic]
mode = "laser-eyes"
workspaces = [
{ manifest_path = "./Cargo.toml", only = ["target:token_manager", "target:governance"] }
]
Perfect for: Production builds, CI optimization, focused development
First build shows what's happening:
$ cargo build
Mode: magic (1 workspace specified)
Workspace: ./Cargo.toml
+ token_manager
+ governance
Generated constants with 2 Solana programs
Compiling token-manager v0.1.0
Compiling governance v0.1.0
Compiling my-elves v0.1.0
Finished dev [unoptimized + debuginfo] target(s)
The + shows included programs, - shows excluded programs.
The magic behind the one-liner:
cargo metadata finds all workspace memberscrate-type = ["cdylib"] identifies Solana programscargo build-sbf runs when source changesTARGET_NAME_ELF constantsAdd to your ELF crate's Cargo.toml:
[build-dependencies]
elf-magic = "0.5"
Works with any workspace layout:
Single Workspace (Magic Mode)
my-workspace/
├── Cargo.toml # Workspace root
├── my-elves/ # Generated ELF exports
│ ├── build.rs # One-liner magic ✨
│ └── src/lib.rs # Hand-written wrapper
└── programs/
├── token-manager/ # Your Solana programs
└── governance/
Multi-Workspace (Permissive/Laser Eyes Mode)
arch-network/
├── Cargo.toml # Main workspace (5 programs)
├── elves/ # ELF exports with advanced config
└── examples/ # Separate workspaces
├── basic/Cargo.toml # Independent workspace
└── advanced/Cargo.toml
cargo build-sbfMIT