Rust bindings for Apple's MLX framework.
Platform: Apple Silicon (macOS) only.
The bindings are layered, the same way as MLX Swift:
mlxcore (safe, idiomatic Rust API) <- crates/mlxcore
mlxcore-sys (raw unsafe FFI bindings) <- crates/mlxcore-sys, generated by bindgen
mlx-c (Apple's C API for MLX) <- third_party/mlx-c (git submodule)
mlx (Apple's C++ framework) <- fetched by mlx-c's CMake build
MLX itself is C++, which Rust cannot bind to directly. We bind against
mlx-c, Apple's official C API, whose
CMake build pulls in MLX via FetchContent.
git submodule update --init --recursive
make build
make testRequirements: a recent Rust toolchain, make, cmake, and Xcode command-line tools.
The first build compiles MLX from source and takes several minutes.
Runnable examples live in crates/mlxcore/examples:
cargo run --example helloUnsuffixed float literals are f64 in Rust, and Apple GPUs have no float64
support. Since the default stream is the GPU, &[1.0, 2.0] builds an array that
fails on every operation. Write &[1.0f32, 2.0], and &a * 2.0f32 for scalars.
float64 still works on an explicit Stream::cpu().
metal(default) — GPU backend via Metal.accelerate(default) — CPU BLAS via Apple's Accelerate framework.