docs.rs failed to build xgboost-rust-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
xgboost-rust
Rust bindings for XGBoost, a gradient boosting library for machine learning.
Features
- Automatic Binary Download: Downloads XGBoost binaries at build time from PyPI wheels
- Cross-Platform: Supports Linux (x86_64, aarch64) and macOS (x86_64, arm64)
- Version Control: Specify XGBoost version via
XGBOOST_VERSIONenvironment variable - Version-Aware Thread Safety: Automatically enables
Send + Syncfor XGBoost ≥ 1.4 - Easy to Use: Simple, safe Rust API wrapping the XGBoost C API
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Requirements
- Rust 1.70 or later
- clang/LLVM (for bindgen)
- Internet connection (for downloading XGBoost binaries during build)
Platform-Specific Requirements
macOS:
install_name_tool(included with Xcode Command Line Tools)
Linux:
- Optional:
patchelf(for setting SONAME, but not required)
Windows:
- ⚠️ Not currently supported via automatic download
- Python wheels don't include import libraries (
.lib) needed for MSVC linking - Alternative: Build XGBoost from source or use WSL/MinGW
Usage
Basic Example
use ;
Advanced Usage
See the examples directory for more examples including:
- Feature contributions (SHAP values)
- Loading models from buffers
- Different prediction options
XGBoost Version
By default, XGBoost version 3.1.1 is used. To use a different version, set the XGBOOST_VERSION environment variable before building:
How It Works
This crate downloads the appropriate XGBoost Python wheel from PyPI during the build process, extracts the compiled library, and links against it. This approach ensures:
- No need to compile XGBoost from source
- Consistent binaries across platforms
- Easy version management
Thread Safety
Thread safety is version-aware:
- XGBoost ≥ 1.4:
BoosterimplementsSend + Syncand is thread-safe for predictions on tree models. You can safely shareArc<Booster>across threads. - XGBoost < 1.4:
Boosterdoes NOT implementSend + Sync. Use one booster per thread or wrap inArc<Mutex<Booster>>.
Example with XGBoost ≥ 1.4
use Arc;
use thread;
use Booster;
let booster = new;
let booster_clone = booster.clone;
spawn;
The version check happens automatically at build time based on the XGBOOST_VERSION environment variable.
Examples
Run the basic example:
Run the advanced example:
License
Apache-2.0
Credits
Inspired by catboost-rust and lightgbm-rust.