Building Programs (cargo build-sbf)
Compile on-chain programs to sBPF ELF with cargo build-sbf, inspect artifact size, and prepare .so files for deploy.
Search across all documentation pages
Compile on-chain programs to sBPF ELF with cargo build-sbf, inspect artifact size, and prepare .so files for deploy.
Quick-reference recipe card - copy-paste ready.
cargo build-sbf
cargo build-sbf --release
ls -lh target/deploy/*.so
wc -c target/deploy/my_program.soWhen to reach for this:
solana-program crates without Anchor wrapper.solana program deploy.cd programs/my_native_program
cargo build-sbf --manifest-path Cargo.toml --sbf-out-dir ../../target/deploy
ls -lh ../../target/deploy/
file ../../target/deploy/my_native_program.so
# Anchor equivalent (calls build-sbf under the hood)
cd ../../
anchor build
ls -lh target/deploy/my_program.soWhat this demonstrates:
cargo build-sbf emits deployable .so ELF for BPF Loader.--sbf-out-dir controls output location for monorepos.anchor build wraps the same pipeline with IDL generation.#![no_std] constraints..so size drives programdata rent at deploy time..so artifact.| Flag | Purpose |
|---|---|
--release | Optimized production binary |
--sbf-out-dir | Custom deploy output directory |
--features | Enable crate feature flags |
--tools-version | Platform tools override (advanced) |
# Show compile warnings that affect CU (unused imports still cost parse time)
cargo build-sbf 2>&1 | tee build.log
# Compare debug vs release size
cargo build-sbf && wc -c target/deploy/*.so
cargo build-sbf --release && wc -c target/deploy/*.so--release for devnet/mainnet deploys..so. Fix: script deploy from fixed target/deploy path.solana-program / anchor-lang APIs only.
| Alternative | Use When | Don't Use When |
|---|---|---|
anchor build | Anchor workspaces + IDL | Pure native crates |
cargo build-bpf (legacy) | Old tutorials | New Agave 4.x projects |
| CI Docker image with pinned tools | Reproducible builds | Fast local iteration |
solana-verify build | Verifiable hash pipeline | Quick devnet tests |
sbf is the current Solana bytecode naming; build-bpf is legacy alias in older docs.
target/deploy/<program>.so at workspace root after anchor build.
Loader enforces a maximum deploy size (check current Agave release notes) - optimize early if approaching limits.
anchor test and cargo test-sbf compile test harnesses; deploy still uses release .so you choose explicitly.
Agave platform tools ship host-specific binaries - use Agave installer for your OS/arch.
Optional modules via #[cfg(feature)] keep unused code out of the .so.
LLVM sBPF backend and LTO - incremental builds help; clean when switching toolchains.
Cache target/deploy keyed on toolchain + lockfile for faster pipelines.
Use llvm-objdump from platform tools bundle on the .so for entrypoint verification.
No - run cargo clippy separately for off-chain crates; on-chain lints are limited.
.so outputStack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.
Reviewed by Chris St. John·Last updated Jul 19, 2026