baml-sys
Low-level FFI bindings to the BAML runtime library with runtime dynamic loading.
Overview
This crate provides the FFI bindings to libbaml_cffi, the C FFI interface to the BAML runtime.
Unlike traditional -sys crates that link at compile time, baml-sys loads the library
dynamically at runtime using libloading.
Library Resolution
The library is searched in the following order:
- Explicit path - Set via
baml_sys::set_library_path()before first use - Environment variable -
BAML_LIBRARY_PATH - User cache -
~/.cache/baml/libs/{VERSION}/(Linux),~/Library/Caches/baml/libs/{VERSION}/(macOS),%LOCALAPPDATA%\baml\libs\{VERSION}\(Windows) - Auto-download - From GitHub releases (if
downloadfeature enabled) - System paths -
/usr/local/lib/, etc.
Usage
Runtime Loading (Default)
use version;
Build-time Hook
In your build.rs:
Environment Variables
BAML_LIBRARY_PATH- Explicit path to the library fileBAML_CACHE_DIR- Override the cache directory locationBAML_LIBRARY_DISABLE_DOWNLOAD- Set to "true" to disable auto-download
Features
download(default) - Enable automatic download from GitHub releasesno-download- Disable download functionality
Platform Support
- macOS (x86_64, aarch64)
- Linux (x86_64, aarch64, glibc)
- Windows (x86_64, MSVC)