elf-magic ✨
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.
Quick Start
# Create an ELF crate in your workspace
Add to my-elves/Cargo.toml:
[]
= "0.5"
Add to my-elves/build.rs:
What You Get
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!;
Generated at build time (in $OUT_DIR):
pub const TOKEN_MANAGER_ELF: & = include_bytes!;
pub const GOVERNANCE_ELF: & = include_bytes!;
Use your programs anywhere:
use ;
// Deploy, test, embed - whatever you need
let program_id = deploy_program?;
Three Modes for Every Workflow
🪄 Magic Mode (Default)
Zero config, just works
Perfect for: Single workspaces, development, getting started
🎛️ Permissive Mode
Multi-workspace with exclusions
[]
= "permissive"
= ["package:*-test"]
= [
{ = "./Cargo.toml", = ["target:dev*"] },
{ = "examples/Cargo.toml" }
]
Perfect for: Complex repos, excluding test programs, multi-workspace projects
🎯 Laser Eyes Mode
Precision targeting
[]
= "laser-eyes"
= [
{ = "./Cargo.toml", = ["target:token_manager", "target:governance"] }
]
Perfect for: Production builds, CI optimization, focused development
Rich Build Reporting
First build shows what's happening:
)
)
The + shows included programs, - shows excluded programs.
How It Works
The magic behind the one-liner:
- 🔍 Auto-discovery:
cargo metadatafinds all workspace members - 🎯 Smart filtering:
crate-type = ["cdylib"]identifies Solana programs - 🔨 Automatic building:
cargo build-sbfruns when source changes - 📝 Code generation: Target names become
TARGET_NAME_ELFconstants - ⚡ Incremental: Only rebuilds what changed
Installation
Add to your ELF crate's Cargo.toml:
[]
= "0.5"
Documentation
- 🪄 Magic Mode - Zero config auto-discovery
- 🎛️ Permissive Mode - Multi-workspace with exclusions
- 🎯 Laser Eyes Mode - Precision targeting
- 📖 Usage Guide - Using your generated constants
- 🏗️ Architecture - How it works under the hood
Examples
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
Requirements
- Rust 2021 edition
- Solana CLI tools for
cargo build-sbf
License
MIT