Skip to main content
This guide covers building ONNX Runtime GenAI from source on Linux, Windows, and macOS.

Prerequisites

Common Requirements

CMake

Version 3.26 or higher (3.28+ for macOS xcframework support)

Python

Python 3.8 or higher

Git

For cloning the repository

C++ Compiler

GCC 11+, Clang, or MSVC

Platform-Specific Requirements

Optional: Hardware Acceleration

For NVIDIA GPU acceleration:
  • CUDA Toolkit 11.8 or higher
  • cuDNN compatible with your CUDA version
  • Set CUDA_HOME or CUDA_PATH environment variable
For AMD GPU acceleration:
  • ROCm 5.0 or higher
  • Compatible AMD GPU
For Windows DirectML acceleration:
  • Windows 10/11
  • DirectX 12 capable GPU
  • No additional installation required

Clone the Repository

Build Phases

The build system supports three phases:
  1. Update (--update): Run CMake to generate makefiles
  2. Build (--build): Build all projects
  3. Test (--test): Run all unit tests
Default behavior:
  • Native builds: --update --build --test
  • Cross-compiled builds: --update --build (tests skipped)

Basic Build

CPU-Only Build

This will:
  • Generate build files in build/<platform>/Release
  • Build the C++ library
  • Build the Python wheel
  • Run tests (unless --skip_tests is specified)

Build with CUDA

If CUDA_HOME or CUDA_PATH environment variable is set, you can omit --cuda_home.

Build with DirectML (Windows)

Build with ROCm

Build Options

Configuration

string
default:"RelWithDebInfo"
Build configuration: Debug, Release, RelWithDebInfo, or MinSizeRel
path
Custom build directory (default: build/<platform>/<config>)

Build Phases

flag
Run CMake to generate/update makefiles
flag
Build the project
flag
Run tests after building
flag
Clean build artifacts for the selected configuration
flag
Package the build output

Hardware Acceleration

flag
Enable CUDA support
path
Path to CUDA installation (default: $CUDA_HOME or $CUDA_PATH)
flag
Enable ROCm support for AMD GPUs
flag
Enable DirectML support (Windows only)
flag
Enable TensorRT-RTX support

Language Bindings

flag
Build C# API bindings
flag
Build Java bindings
flag
Skip building the Python wheel

Other Options

flag
Enable parallel build
flag
Skip running tests
flag
Skip building examples
flag
Enable guidance support for constrained decoding
string
CMake generator (default: “Visual Studio 17 2022” on Windows, “Unix Makefiles” elsewhere)
list
Extra CMake definitions (without -D prefix)

Advanced Build Scenarios

Cross-Compilation for Android

string
default:"arm64-v8a"
Android ABI: armeabi-v7a, arm64-v8a, x86, or x86_64
integer
default:"27"
Android API Level (27 = Android 8.1)

Cross-Compilation for iOS

flag
Build for iOS
string
macOS platform SDK location
string
Target architecture for iOS/macOS
string
Minimum target platform version

Build Apple Framework

Windows ARM64

Custom ONNX Runtime

Use a custom ONNX Runtime build:

Build Examples

Development Build with Tests

Production Build with CUDA

Build Only (Skip Update and Test)

Clean and Rebuild

Build with Constrained Decoding Support

Installing the Python Package

After building, install the Python wheel:

Troubleshooting

  • Ensure CMake version is 3.26 or higher (3.28+ for macOS)
  • Check that all dependencies are installed
  • Delete CMakeCache.txt and the build directory, then retry
  • Verify compiler version (GCC 11+ required)
  • Set CUDA_HOME or CUDA_PATH environment variable
  • Ensure nvcc is in your PATH
  • Verify CUDA Toolkit version is 11.8 or higher
  • Ensure Visual Studio 2022 is installed
  • Run build from “Developer Command Prompt for VS 2022”
  • Check that Windows SDK is installed
  • Try specifying generator explicitly: --cmake_generator "Visual Studio 17 2022"
  • Reduce parallel builds: Remove --parallel flag
  • Use Release or MinSizeRel configuration instead of Debug
  • Close other applications
  • Increase system swap/page file
  • Ensure model files are accessible
  • Check hardware acceleration is properly configured
  • Try running tests individually to isolate issues
  • Use --skip_tests to skip testing during build

Build System Details

Build Directory Structure

CMake Variables

You can pass custom CMake variables:

Environment Variables

path
Path to CUDA installation
path
Alternative path to CUDA (Windows)
path
Path to Android SDK
path
Path to Android NDK

Next Steps

Quickstart

Run your first inference with the built package

Model Builder

Build optimized ONNX models

Contributing

Contribute to ONNX Runtime GenAI

Examples

Explore code examples