Ditto(Live)'s Rust SDK
Please visit https://docs.ditto.live/ for more info about Ditto, and its Rust documentation.
Note: for historical reasons, this SDK has been minimally maintained during 2022 and the first half of 2023. We have gradually been able to improve this, and especially since 2024, we take this SDK very seriously, to keep it on par with the high quality standards that our customers can expect from us, showcased in other SDKs such as Swift and Javascript.
- A main example of this has been linkage or ABI incompatibilities with certain Rust toolchains, which have since been fixed.
That being said, some technical debt from that time may still linger for a few extra months, until everything is properly cleaned up (which will come with a major bump to rename and clean up certain rougher parts of the API).
We apologize for the inconvenience.
Some notes about using a Rust-wrapped C library
Ditto's core functionality is released and packaged as a C library, which is then imported into Rust via the ::dittolive-ditto-sys crate.
Downloading the companion binary artifact
Such a crate will download —at build time— the appropriate binary artifact from https://software.ditto.live/rust/Ditto/<version>/<target>/release/[lib]dittoffi.{a,so,dylib,dll,lib}
- For instance:
https://software.ditto.live/rust/Ditto/4.5.4/aarch64-apple-darwin/release/libdittoffi.so
If you wish to avoid this, you will have to do it yourself:
-
Download the proper binary artifact;
-
Instruct
::dittolive-ditto-sys'build.rsscript about it by setting theDITTOFFI_SEARCH_PATHappropriately (using an absolute path is recommended).
More precisely, the library search resolution order is as follows:
$DITTOFFI_SEARCH_PATH(if set)$OUT_DIR(e.g.,${CARGO_TARGET_DIR}/<profile>/build/dittolive-ditto-sys-.../out)- the current working directory (
$PWD) $CARGO_TARGET_DIR- Host built-in defaults (e.g.,
/usr/lib,/lib,/usr/local/lib,$HOME/lib) controlled by (system) linker setup.
If the library artifact is not found at any of these locations, the build script will attempt its own download into the $OUT_DIR (and use that path).
Linkage
C linkage is typically accompanied with some idiosyncrasies, such as symbol conflicts, or path resolution errors.
The first and foremost question is about dynamic vs. static linkage.
-
Statically linking
libdittoffi(default; recommended)This happens whenever the
LIBDITTO_STATICis explicitly set to1, or unset.If you have a special path to the
libdittoffi.a/dittoffi.libfile (on Unix and Windows, respectively), then you can use theDITTOFFI_SEARCH_PATHenv var to point to its location (using an absolute path), at linkage time (duringcargo buildexclusively). -
Dynamically linking (advanced)
You can opt into this behavior by setting the
LIBDITTO_STATIC=0environment variable.When opting into this, you will have to handle library path resolution to the
libdittoffi.so/libdittoffi.dylib/dittoffi.dllfile (on Linux, macOS, and Windows, respectively).That is, whilst the
DITTOFFI_SEARCH_PATHis still important to help thecargo build/ linkage step resolve the dynamic library, the actual usage of this file happens at runtime, when the (Rust) binary using::dittolive_dittois executed.It is thus advisable to install the C dynamic library artifact under one of the system folders, such as
/usr/libor whatnot on Unix.Otherwise, you would have to:
-
either meddle with link-time flags to set OS-specific loader metadata in the binary, such as the
R{,UN}PATH/install_path, paying special attention to the choice of absolute paths, binary-relative paths (such as$ORIGIN/…on Linux), or even working-directory-relative paths; -
or use env vars directives for the dynamic loader, such as
DYLD_FALLBACK_LIBRARY_PATHon macOS, orLD_LIBRARY_PATHon Linux.
(For the technically-savy, on macOS, the
install_pathof our.dylibartifact is set to$rpath/libdittoffi.dylib). -