Skip to main content

Overview

The anchor 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

flag
default:"false"
Skip checking for safety comments (“CHECK”) in the code
flag
default:"false"
Skip checking for program ID mismatch between keypair and declare_id!
string
Name of a specific program to build (builds all programs if not specified)
enum
default:"sbf"
Architecture to use when building the programOptions: sbf, bpf

IDL Options

flag
default:"false"
Do not build the IDL
string
Output directory for the IDL (defaults to target/idl)
string
Output directory for the TypeScript IDL (defaults to target/types)
flag
default:"false"
Suppress doc strings in IDL output

Verifiable Builds

flag
default:"false"
Build artifact must be deterministic and verifiable using Docker
string
Solana toolchain version to use (for verifiable builds only)
string
Custom Docker image to use (for verifiable builds only)
enum
default:"none"
Bootstrap Docker image from scratch, installing all requirementsOptions: none, debian
array
Environment variables to pass into the Docker container (for verifiable builds)

Additional Arguments

string
Arguments to pass to the underlying cargo build-sbf command (use -- to separate)

Examples

Basic Build

Build all programs in the workspace:
Output:

Build Specific Program

Verifiable Build

Create a deterministic build that can be verified:
With a specific Solana version:

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:
  1. Creates a Docker container with the specified Solana version
  2. Compiles the program inside the container
  3. Copies the build artifact to target/verifiable/
  4. 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:
  1. Checks for program ID mismatches (unless --ignore-keys is set)
  2. Runs pre-build hooks (if configured in Anchor.toml)
  3. Compiles the Rust program using cargo build-sbf
  4. Generates IDL from the compiled program (unless --no-idl is set)
  5. Writes IDL JSON and TypeScript types to output directories
  6. 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-docs is specified)

Notes

Overflow checks are required in the release profile. The build will fail if they are disabled.
Use --verifiable when preparing programs for public deployment to allow others to verify your build matches the on-chain bytecode.
The default architecture is sbf (Solana Bytecode Format). The bpf option is for legacy compatibility.