Skip to main content

Prerequisites

Before installing drift-rs, ensure you have:
  • Rust toolchain installed (rustup recommended)
  • x86_64 architecture support (required for Solana program compatibility)
  • Git (for cloning repositories with submodules)
The non-x86_64 toolchains are incompatible due to memory layout differences between Solana program (BPF) and aarch64. Using non-x86_64 architectures will fail at runtime with deserialization errors like InvalidSize.

Install from Git

Add drift-rs to your Cargo.toml:
Cargo.toml
[dependencies]
drift-rs = { git = "https://github.com/drift-labs/drift-rs", tag = "v1.0.0-alpha.18" }
Using the Git dependency is recommended. If you want to use crates.io, note that it requires libdrift to be installed and linked locally.

System Setup

macOS Setup

1

Install Rosetta (M-series Macs only)

M1/M2/M3 Macs need Rosetta for x86_64 emulation:
softwareupdate --install-rosetta
2

Install x86_64 Rust Toolchains

Install both the latest stable and 1.76.0 x86_64 toolchains:
# Replace '1.85.0' with your preferred latest stable version
rustup install 1.85.0-x86_64-apple-darwin 1.76.0-x86_64-apple-darwin --force-non-host
You must install both 1.76.0-x86_64 and your latest stable Rust version. The 1.76.0 toolchain is required for compatibility with Solana program builds.
3

Set Default Toolchain

Set the x86_64 toolchain as default for your project:
rustup override set 1.85.0-x86_64-apple-darwin
4

Verify Installation

Check that you’re using the correct toolchain:
rustc --version --verbose
You should see host: x86_64-apple-darwin in the output.

Linux Setup

1

Install x86_64 Rust Toolchains

Install both the latest stable and 1.76.0 x86_64 toolchains:
# Replace '1.85.0' with your preferred latest stable version
rustup install 1.85.0-x86_64-unknown-linux-gnu 1.76.0-x86_64-unknown-linux-gnu --force-non-host
You must install both 1.76.0-x86_64 and your latest stable Rust version. The 1.76.0 toolchain is required for compatibility with Solana program builds.
2

Set Default Toolchain

Set the x86_64 toolchain as default:
rustup override set 1.85.0-x86_64-unknown-linux-gnu
3

Verify Installation

Check that you’re using the correct toolchain:
rustc --version --verbose
You should see host: x86_64-unknown-linux-gnu in the output.

Local Development Setup

If you’re contributing to drift-rs or want to build from source:
1

Clone Repository with Submodules

drift-rs links to the drift program crate via FFI:
git clone https://github.com/drift-labs/drift-rs && \
cd drift-rs && \
git submodule update --init --recursive
2

Choose Build Configuration

You can build from source (default) or use a prebuilt library:Build from source (recommended):
export CARGO_DRIFT_FFI_STATIC=1
cargo build
Use prebuilt library:
# Download from https://github.com/drift-labs/drift-ffi-sys/releases
export CARGO_DRIFT_FFI_PATH="/path/to/libdrift_ffi_sys"
cargo build
3

Verify Build

Run the tests to ensure everything is working:
cargo test

Create Your First Project

1

Create a New Rust Project

cargo new my-drift-bot
cd my-drift-bot
2

Add Dependencies

Edit your Cargo.toml:
Cargo.toml
[package]
name = "my-drift-bot"
version = "0.1.0"
edition = "2021"

[dependencies]
drift-rs = { git = "https://github.com/drift-labs/drift-rs", tag = "v1.0.0-alpha.18" }
tokio = { version = "1.48", features = ["full"] }
solana-sdk = "2"
env_logger = "0.11"
dotenv = "0.15"
3

Set Up Environment Variables

Create a .env file:
.env
RPC_URL=https://api.mainnet-beta.solana.com
# Optional: Add your wallet private key for signing transactions
# PRIVATE_KEY=your_base58_private_key
4

Build Your Project

cargo build
If you see any compilation errors related to architecture, ensure you’ve set the correct x86_64 toolchain override.

Troubleshooting

Architecture Mismatch Errors

If you see InvalidSize deserialization errors at runtime:
  1. Verify you’re using the x86_64 toolchain:
    rustc --version --verbose | grep host
    
  2. Make sure you have the toolchain override set:
    rustup override list
    
  3. Reinstall the correct toolchain if needed (see System Setup above)

Compilation Errors

If you encounter FFI-related compilation errors:
  1. Ensure git submodules are initialized:
    git submodule update --init --recursive
    
  2. Try cleaning and rebuilding:
    cargo clean
    cargo build
    
  3. Check that you have the required build tools installed (gcc, cmake, etc.)

RPC Connection Issues

If you can’t connect to an RPC endpoint:
  1. Verify your RPC URL is correct and accessible
  2. Try using a different RPC provider (e.g., Helius, Triton)
  3. Check your firewall settings
For the best performance, use a dedicated RPC provider like Helius or Triton instead of public endpoints.

Next Steps

Quick Start Guide

Build your first drift-rs application with a complete working example

Build docs developers (and LLMs) love