rust-api-examples/for-advanced-users.md
This note is for users who want to control how the sherpa-onnx Rust crate
finds and links its native libraries.
Most users do not need anything here. The default behavior is:
If you already have sherpa-onnx libraries on disk, set
SHERPA_ONNX_LIB_DIR to the lib directory before building:
export SHERPA_ONNX_LIB_DIR=/path/to/sherpa-onnx/lib
Examples:
/path/to/sherpa-onnx/build/install/lib/path/to/sherpa-onnx-v1.13.0-linux-x64-static-lib/libIf SHERPA_ONNX_LIB_DIR is set, the build script uses that directory and does
not auto-download another archive.
If SHERPA_ONNX_LIB_DIR is not set, sherpa-onnx-sys/build.rs downloads a
matching prebuilt -lib archive from GitHub releases and uses its lib
directory automatically.
The build script currently selects archives like this:
Default mode uses the default crate feature set, which means static linking. Most users just get this behavior automatically.
| OS | Architecture | Archive example |
|---|---|---|
| Linux | x86_64 | sherpa-onnx-v1.13.0-linux-x64-static-lib.tar.bz2 |
| Linux | aarch64 | sherpa-onnx-v1.13.0-linux-aarch64-static-lib.tar.bz2 |
| macOS | x86_64 | sherpa-onnx-v1.13.0-osx-x64-static-lib.tar.bz2 |
| macOS | arm64 | sherpa-onnx-v1.13.0-osx-arm64-static-lib.tar.bz2 |
| Windows | x86_64 | sherpa-onnx-v1.13.0-win-x64-static-MT-Release-lib.tar.bz2 |
If you enable the shared feature, the build script downloads these shared
archives instead:
| OS | Architecture | Archive example |
|---|---|---|
| Linux | x86_64 | sherpa-onnx-v1.13.0-linux-x64-shared-lib.tar.bz2 |
| Linux | aarch64 | sherpa-onnx-v1.13.0-linux-aarch64-shared-cpu-lib.tar.bz2 |
| macOS | x86_64 | sherpa-onnx-v1.13.0-osx-x64-shared-lib.tar.bz2 |
| macOS | arm64 | sherpa-onnx-v1.13.0-osx-arm64-shared-lib.tar.bz2 |
| Windows | x86_64 | sherpa-onnx-v1.13.0-win-x64-shared-MT-Release-lib.tar.bz2 |
In practice, use the latest release tag instead of the example version above.
sherpa-onnx crate in Cargo.tomlThis is enough for most users:
[dependencies]
sherpa-onnx = "1.13.0"
That uses the crate's default feature set.
To use shared libraries instead, disable default features and enable shared:
[dependencies]
sherpa-onnx = { version = "1.13.0", default-features = false, features = ["shared"] }
From the command line, the equivalent example command is:
cargo run --no-default-features --features shared --example version
In rust-api-examples, microphone support is controlled by the mic feature:
cargo run --features mic --example streaming_zipformer_microphone -- --help
If you want both microphone support and shared libraries:
cargo run --no-default-features --features "shared,mic" \
--example streaming_zipformer_microphone -- --help
When shared libraries are used:
When SHERPA_ONNX_LIB_DIR is set, the same behavior applies, but the files come
from your directory instead of an auto-downloaded archive.