Overview
Theanchor build command compiles Solana programs in the workspace using cargo build-sbf and generates Interface Definition Language (IDL) files.
Command Syntax
Alias
Options
Build Configuration
Skip checking for safety comments (“CHECK”) in the code
Skip checking for program ID mismatch between keypair and
declare_id!Name of a specific program to build (builds all programs if not specified)
Architecture to use when building the programOptions:
sbf, bpfIDL Options
Do not build the IDL
Output directory for the IDL (defaults to
target/idl)Output directory for the TypeScript IDL (defaults to
target/types)Suppress doc strings in IDL output
Verifiable Builds
Build artifact must be deterministic and verifiable using Docker
Solana toolchain version to use (for verifiable builds only)
Custom Docker image to use (for verifiable builds only)
Bootstrap Docker image from scratch, installing all requirementsOptions:
none, debianEnvironment variables to pass into the Docker container (for verifiable builds)
Additional Arguments
Arguments to pass to the underlying
cargo build-sbf command (use -- to separate)Examples
Basic Build
Build all programs in the workspace:Build Specific Program
Verifiable Build
Create a deterministic build that can be verified:Custom IDL Output
Build Without IDL
Pass Additional Cargo Arguments
Build with Environment Variables (Verifiable)
Output Structure
After a successful build, artifacts are located in:Verifiable Builds
Verifiable builds use Docker to ensure deterministic compilation:- Creates a Docker container with the specified Solana version
- Compiles the program inside the container
- Copies the build artifact to
target/verifiable/ - Allows anyone to reproduce the exact same binary
Verifiable builds require Docker to be installed and running on your system.
Build Process
The build command:- Checks for program ID mismatches (unless
--ignore-keysis set) - Runs pre-build hooks (if configured in
Anchor.toml) - Compiles the Rust program using
cargo build-sbf - Generates IDL from the compiled program (unless
--no-idlis set) - Writes IDL JSON and TypeScript types to output directories
- Runs post-build hooks (if configured)
IDL Generation
The IDL is automatically generated and includes:- Program instructions and their parameters
- Account structures
- Custom types and enums
- Error codes
- Documentation strings (unless
--no-docsis specified)
Notes
The default architecture is
sbf (Solana Bytecode Format). The bpf option is for legacy compatibility.