> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/solana-foundation/anchor/llms.txt
> Use this file to discover all available pages before exploring further.

# anchor build

> Build Anchor programs with optional IDL generation and verifiable builds

## Overview

The `anchor build` command compiles Solana programs in the workspace using `cargo build-sbf` and generates Interface Definition Language (IDL) files.

## Command Syntax

```bash theme={null}
anchor build [OPTIONS]
```

## Alias

```bash theme={null}
anchor b
```

## Options

### Build Configuration

<ParamField path="--skip-lint" type="flag" default="false">
  Skip checking for safety comments ("CHECK") in the code
</ParamField>

<ParamField path="--ignore-keys" type="flag" default="false">
  Skip checking for program ID mismatch between keypair and `declare_id!`
</ParamField>

<ParamField path="--program-name" type="string">
  Name of a specific program to build (builds all programs if not specified)
</ParamField>

<ParamField path="--arch" type="enum" default="sbf">
  Architecture to use when building the program

  **Options:** `sbf`, `bpf`
</ParamField>

### IDL Options

<ParamField path="--no-idl" type="flag" default="false">
  Do not build the IDL
</ParamField>

<ParamField path="--idl" type="string">
  Output directory for the IDL (defaults to `target/idl`)
</ParamField>

<ParamField path="--idl-ts" type="string">
  Output directory for the TypeScript IDL (defaults to `target/types`)
</ParamField>

<ParamField path="--no-docs" type="flag" default="false">
  Suppress doc strings in IDL output
</ParamField>

### Verifiable Builds

<ParamField path="--verifiable" type="flag" default="false">
  Build artifact must be deterministic and verifiable using Docker
</ParamField>

<ParamField path="--solana-version" type="string">
  Solana toolchain version to use (for verifiable builds only)
</ParamField>

<ParamField path="--docker-image" type="string">
  Custom Docker image to use (for verifiable builds only)
</ParamField>

<ParamField path="--bootstrap" type="enum" default="none">
  Bootstrap Docker image from scratch, installing all requirements

  **Options:** `none`, `debian`
</ParamField>

<ParamField path="--env" type="array">
  Environment variables to pass into the Docker container (for verifiable builds)
</ParamField>

### Additional Arguments

<ParamField path="cargo_args" type="string">
  Arguments to pass to the underlying `cargo build-sbf` command (use `--` to separate)
</ParamField>

## Examples

### Basic Build

Build all programs in the workspace:

```bash theme={null}
anchor build
```

**Output:**

```
Building program...
Build success
```

### Build Specific Program

```bash theme={null}
anchor build --program-name my_program
```

### Verifiable Build

Create a deterministic build that can be verified:

```bash theme={null}
anchor build --verifiable
```

With a specific Solana version:

```bash theme={null}
anchor build --verifiable --solana-version 2.0.6
```

### Custom IDL Output

```bash theme={null}
anchor build --idl ./custom-idl --idl-ts ./custom-types
```

### Build Without IDL

```bash theme={null}
anchor build --no-idl
```

### Pass Additional Cargo Arguments

```bash theme={null}
anchor build -- --features "my-feature"
```

### Build with Environment Variables (Verifiable)

```bash theme={null}
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

<Note>
  Verifiable builds require Docker to be installed and running on your system.
</Note>

## 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

<Warning>
  Overflow checks are required in the release profile. The build will fail if they are disabled.
</Warning>

<Tip>
  Use `--verifiable` when preparing programs for public deployment to allow others to verify your build matches the on-chain bytecode.
</Tip>

<Info>
  The default architecture is `sbf` (Solana Bytecode Format). The `bpf` option is for legacy compatibility.
</Info>
