libopus_sys
libopus_sys is an FFI-Rust-binding to Opus version 1.5.
Originally, this sys-crate was made to empower the serenity-crate to build audio features on Windows, Linux, and macOS. However, it's not limited to that.
Everyone is welcome to contribute,
check out the CONTRIBUTING.md for further guidance.
Building & Linking
This crate can either:
- link against a system-installed
libopus, or - build Opus from vendored sources (no system
libopusrequired) via thebundledfeature.
Features
bundled: build Opus from the vendoredopus/sources using CMake (does not require a systemlibopus)static: prefer static linkingdynamic: prefer dynamic linkinggenerate_binding: regeneratesrc/lib.rsfromsrc/wrapper.h(requires libclang)
Requirements
- To build Opus from source (e.g.
--features bundled): you needcmake. - To link a system libopus via pkg-config: you need
pkg-config(Unix / GNU targets only). - This crate ships with pre-generated bindings. To regenerate bindings you need
ClangandLIBCLANG_PATH.
Recommended: build from vendored sources (no system dependency)
If you want a build that does not depend on any system-installed libopus, enable bundled:
You can also force this via environment variables:
OPUS_BUNDLED=1LIBOPUS_BUNDLED=1
When bundled is enabled, the build script uses CMake to compile the vendored opus/ sources and
links the resulting library.
Linking
libopus_sys targets Opus 1.5 and supports Windows, Linux, and macOS.
Static vs dynamic
- By default, we link statically on Windows, macOS, and
musltargets. - By default, we link dynamically on Linux
gnutargets.
You can override this with features:
--features static--features dynamic
If both are enabled, we pick the default for your target (as described above).
Environment variables LIBOPUS_STATIC or OPUS_STATIC take precedence over features: if either
is set, static linking is selected (the value does not matter).
How libopus is located (when bundled is not enabled)
On Unix / GNU targets, the build script will:
- try
pkg-configforopus(unlessLIBOPUS_NO_PKGorOPUS_NO_PKGis set) - otherwise, if
LIBOPUS_LIB_DIRorOPUS_LIB_DIRis set, link from that prefix - otherwise, if vendored sources (
opus/) are present, build Opus via CMake
If none of these work, the build fails with instructions on how to proceed.
Pkg-Config
On Unix / GNU targets (and when bundled is not enabled), libopus_sys will try pkg-config
first. Set LIBOPUS_NO_PKG=1 or OPUS_NO_PKG=1 to bypass it.
System libopus (pre-installed)
If you prefer to link an existing libopus installation (or you already ship one with your
application), you can point the build script at it:
LIBOPUS_LIB_DIR=/path/to/prefixOPUS_LIB_DIR=/path/to/prefix
Where /path/to/prefix contains lib/ (e.g. /usr/local, a Homebrew prefix, etc.).
Be aware that using an Opus other than version 1.5 may not work.
Generating The Binding
If you want to generate the binding yourself, you can use the
generate_binding-feature.
Be aware, bindgen requires Clang and its LIBCLANG_PATH
environment variable to be specified.
Installation
Add this to your Cargo.toml:
[]
= "0.3"