SDK Setup Guides
Rust

Setting Up

This quickstart provides step-by-step instructions on installing and setting up the Ditto SDK in your Rust project.

To integrate Ditto with your app:

  1. Create a new project and add the Ditto SDK as a project dependency. (Creating Project and Installing Ditto SDK)
  2. Set up the directory and file structure for your project. (Setting Up Project Layout)
  3. Configure your project for cross-compilation. (Configuring for Cross-Compilation)

Creating Project and Installing Ditto SDK

Create a new Rust project that uses the Ditto SDK:

  1. Create your new Rust project by running cargo init --bin
  2. From the Cargo.toml file in your project directory, add the Ditto SDK as a project dependency:
Cargo


Setting Up Project Layout

The Rust programming language does not enforce that you use a specific file structure on your app’s end-user device’s filesystem; you can organize your project layout however you prefer; however, Ditto recommends that you organize and structure your project layout as follows:

Text


App Entry Point: AppRoot/AppExecutable

The AppRoot/AppExecutable path is the entry point of your app that contains your app’s main executable file. Structure everything else in your filesystem relative to the AppRoot/AppExecutable path.

By default, the binary component of Ditto (libdittoffi.dll) is statically linked into your app’s main executable file. For more information, see Dynamic Link Library: libdittooffi.dll, as follows.

Dynamic Link Library: AppRoot/libdittooffi.dll

The AppRoot/libdittoffi.dll path contains the binary component of Ditto. Ditto’s binary component is a pre-compiled shared library file, also known as the dynamic link library (DLL). This libdittoffi.dll file contains the actual code implementations that enable Ditto platform capabilities, such as data sync.

If you want to use Ditto’s dynamic link library, configure your app’s linker to search for the libdittoffi.dll file in this path at build. For example, if configuring the linker to reference the @executable_path, configure your app’s linker as: @executable_path/../libdittoffi.dylib.

When distributing your app to end users, if you are using the Ditto SDK’s shared library version, you must include the build output directory’s shared library file in your distributed app. 

Configuring for Cross-Compilation

With Rust’s native support for cross-compilation, you can deploy your code on a wide range of environments and platforms. For instance, using the same Rust code, you can cross-compile to create native code that runs on iOS and Android platforms for mobile apps; WebAssembly (Wasm), Rust-in-the-browser deployment; as well as Linux and MacOS for desktop and server apps.