Rust bindings for the MNN neural network inference engine.
This library will attempt to automatically download MNN source code when needed, but due to potential repository structure changes, it may not always work with the latest versions.
The most reliable method is to use git submodules:
git submodule update --init --recursiveYou can also manually download MNN and specify its location:
- Clone MNN repository:
git clone https://github.com/alibaba/MNN.git /path/to/mnn - Set environment variable:
export MNN_SRC=/path/to/mnn - Build your project:
cargo build
| Variable | Description |
|---|---|
MNN_SRC |
Path to MNN source code |
MNN_VERSION |
When downloading, specifies version tag (default: "3.0.5") |
MNN_COMPILE |
Set to "0" to skip compilation (requires MNN_LIB_DIR) |
MNN_LIB_DIR |
Path to pre-built MNN libraries |
MNN_SYSTEM |
Set to "1" to use system-installed MNN libraries |
MNN_FORCE_DOWNLOAD |
Set to "1" to force re-download of MNN source |
To use system-installed MNN libraries:
MNN_SYSTEM=1 cargo buildmetal- Enable Metal backend (Apple platforms)coreml- Enable CoreML backend (Apple platforms)vulkan- Enable Vulkan backendopencl- Enable OpenCL backendopengl- Enable OpenGL backendcrt_static- Use static CRT on Windowsopenmp- Enable OpenMP (disables MNN threadpool)mnn-threadpool- Use MNN's threadpool (default)tracing- Enable tracing supportprofile- Enable profiling supportserde- Enable serialization/deserialization support
Check the examples directory for usage examples.