When including this crate as a local dependency, whisper.cpp rebuilds every time (several minutes per build).
By default, cargo build invokes CMake to compile whisper.cpp from source. This works for all features including CUDA — just install the toolkit and cargo build --features cuda.
The first build takes several minutes (CMake configure + full C++ compile). Subsequent builds are cached by cargo unless the source changes.
For CI pipelines or to skip recompilation, you can prebuild and cache the static libraries. The xtask commands:
| Command | Description |
|---|---|
cargo xtask prebuild |
Build and cache the whisper library |
cargo xtask info |
Show available prebuilt libraries |
cargo xtask clean |
Remove all prebuilt libraries |
cargo xtask test-setup |
Download test models (whisper tiny.en + Silero VAD) |
# Build once, reuse on every subsequent cargo build
cargo xtask prebuild
# Verify it worked
cargo xtask infoThe prebuilt library is stored at prebuilt/{target}/{profile}/ and automatically detected by whisper-cpp-plus-sys/build.rs on subsequent builds.
No configuration needed. The build system checks prebuilt/{target}/{profile}/ automatically.
Set the path explicitly if you've moved the prebuilt library:
# Windows
set WHISPER_PREBUILT_PATH=C:\path\to\prebuilt\x86_64-pc-windows-msvc\release
# Unix/Mac
export WHISPER_PREBUILT_PATH=/path/to/prebuilt/x86_64-unknown-linux-gnu/releaseAdd to your project's .cargo/config.toml:
[env]
WHISPER_PREBUILT_PATH = "/path/to/prebuilt/x86_64-pc-windows-msvc/release"# Debug build
cargo xtask prebuild --profile debug
# Release build (default)
cargo xtask prebuild --profile release
# Specify target explicitly
cargo xtask prebuild --target aarch64-apple-darwin
# Force rebuild even if library exists
cargo xtask prebuild --forceDownload models required for integration tests:
cargo xtask test-setup
# Force re-download
cargo xtask test-setup --forceDownloads ggml-tiny.en.bin and ggml-silero-v6.2.0.bin into whisper-cpp-plus-sys/whisper.cpp/models/. Works on both Windows (.cmd scripts) and Unix (.sh scripts).
- Without caching: Full C++ compilation takes several minutes
- With prebuilt library: Build completes in <1 second
cargo xtask prebuildcompiles whisper.cpp via CMake and stores static libraries inprebuilt/whisper-cpp-plus-sys/build.rschecks for prebuilt libraries before invoking CMake:- First checks
WHISPER_PREBUILT_PATHenv var - Then checks
prebuilt/{target}/{profile}/relative to project root - On Unix, also checks system paths (
/usr/local/lib,/usr/lib,/opt/homebrew/lib)
- First checks
- If found, it links the prebuilt libraries instead of running CMake
When a prebuilt library is used, you'll see during build:
warning: Using prebuilt whisper library from: /path/to/prebuilt
If both projects are yours, combine them into a workspace to share build artifacts:
[workspace]
members = ["whisper-cpp-plus", "your-project"]
resolver = "2"For additional caching across projects:
cargo install sccache
export RUSTC_WRAPPER=sccacheInstall the CUDA toolkit and build directly:
cargo build --features cudaThe build script invokes CMake with -DGGML_CUDA=1 automatically. CMake handles CUDA compiler discovery.
To set a specific GPU architecture:
CMAKE_CUDA_ARCHITECTURES=86 cargo build --features cudaAny CMAKE_* environment variable is passed through to CMake.
For CI or repeated builds, use xtask:
cargo xtask prebuild --cudaOr set WHISPER_PREBUILT_PATH to a directory containing pre-compiled static libs (whisper + ggml satellites + ggml-cuda).
The build script locates the CUDA toolkit in this order:
CUDA_PATHenvironment variableCUDA_HOMEenvironment variable- Standard paths:
- Windows:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vX.Y(latest version) - Linux:
/usr/local/cuda,/usr/lib/cuda,/opt/cuda
- Windows:
| GPU | Architecture | Value |
|---|---|---|
| RTX 4090/4080/4070 | Ada Lovelace | 89 |
| RTX 3090/3080/3070 | Ampere | 86 |
| RTX 3060/3050 | Ampere | 86 |
| A100 | Ampere | 80 |
| RTX 2080/2070 | Turing | 75 |
| GTX 1080/1070 | Pascal | 61 |
| Multiple GPUs | Mixed | "75;86;89" |
- Library not found: Run
cargo xtask infoto see available prebuilt libraries - Linking errors: Ensure the prebuilt library matches your target architecture and compiler
- Outdated library: Run
cargo xtask cleanthencargo xtask prebuildto rebuild
Target auto-detection works on:
- Windows (MSVC and GNU, x86_64)
- macOS (x86_64 and ARM64)
- Linux (x86_64 and ARM64)
For other targets, use --target explicitly: cargo xtask prebuild --target <triple>