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

anchor build [OPTIONS]

Alias

anchor b

Options

Build Configuration

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

IDL Options

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

Verifiable Builds

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

Additional Arguments

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

Examples

Basic Build

Build all programs in the workspace:
anchor build
Output:
Building program...
Build success

Build Specific Program

anchor build --program-name my_program

Verifiable Build

Create a deterministic build that can be verified:
anchor build --verifiable
With a specific Solana version:
anchor build --verifiable --solana-version 2.0.6

Custom IDL Output

anchor build --idl ./custom-idl --idl-ts ./custom-types

Build Without IDL

anchor build --no-idl

Pass Additional Cargo Arguments

anchor build -- --features "my-feature"

Build with Environment Variables (Verifiable)

anchor build --verifiable --env "VAR1=value1" --env "VAR2=value2"

Output Structure

After a successful build, artifacts are located in:
target/
├── deploy/
│   ├── my_program.so          # Compiled program binary
│   └── my_program-keypair.json
├── idl/
│   └── my_program.json        # JSON IDL
├── types/
│   └── my_program.ts          # TypeScript types
└── verifiable/                 # Verifiable build artifacts (if --verifiable)
    └── my_program.so

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.

Build docs developers (and LLMs) love