Skip to content
This repository was archived by the owner on Oct 19, 2022. It is now read-only.

How To build libdeltachat.a (Delta Chat Core)

Daniel edited this page Nov 25, 2019 · 12 revisions

Preparations

libdeltachat.a is based on and built from the Delta Chat Core (DCC). Sometimes you need to build your own version based on a specific branch or with your own additions.

Rust

To build your own version of libdeltachat.a you should have installed the Rust tool chain before. You can check if it's installed by simply execute the command:

rustc --version

If you see something like this:

$ ~ rustc --version
rustc 1.36.0 (a53f9df32 2019-07-03)

there is nothing more to do regarding Rust. Otherwise, if it's missing, execute this command in your terminal:

curl https://sh.rustup.rs -sSf | sh

Targets

Rust needs a set of targets to build the actual core, please add the required targets for your platform after navigating in the DCC sub module.

cd delta_chat_core
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android # Android
rustup target add aarch64-apple-ios armv7-apple-ios armv7s-apple-ios x86_64-apple-ios i386-apple-ios # iOS

Cargo configuration

Rust needs to know where to find some Android-specific tools. These are configured in $GIT/.cargo/config:

paths = ["tokio-imap", "tokio-imap/imap-proto", "rust-imap"]

[target.armv7-linux-androideabi]
ar     = "arm-linux-androideabi-ar"
linker = "armv7a-linux-androideabi21-clang"

[target.aarch64-linux-android]
ar     = "aarch64-linux-android-ar"
linker = "aarch64-linux-android21-clang"

[target.i686-linux-android]
ar     = "i686-linux-android-ar"
linker = "i686-linux-android21-clang"

[target.x86_64-linux-android]
ar     = "x86_64-linux-android-ar"
linker = "x86_64-linux-android21-clang"

The first line contains relative paths and is only necessary if locally modified dependencies of deltachat-core-rust are used. The path to the local deltachat-core-rust itself was specified by the symlink in Rust and Flutter. Currently, this method of overwriting dependencies prints a warning, and might stop working in the future. Cargo issue #6713 hopefully provides a better solution until then.

The rest of the file relies on the PATH entries added in Native Development Kit (NDK) and can be put in any other directory where Cargo will find it, e.g. in particular $HOME/.cargo/config.

Additional tools and environment adjustments

To be able to build for specific platforms some tools must be installed beside the Rust tool chain.

Android

Native Development Kit (NDK)

Android requires an installation of the NDK. You can either manually download it or install it via the Android Studio SDK manager.

Launch the SDK Manger by selecting Configure/ToolsSDK Manager. In the tab SDK Tools, select NDK (Side by side) and install it. After the download is finished, the log window should contain a line like

Installing NDK (Side by side) 20.1.5948944 in /home/…/Android/Sdk/ndk/20.1.5948944

This installation directory, and its subdirectory toolchains/llvm/prebuilt/linux-x86_64/bin need to be added to your PATH, e.g. by adding something like the following to $HOME/.bashrc:

export PATH="$PATH:$HOME/Android/Sdk/ndk/20.1.5948944"
export PATH="$PATH:$HOME/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/bin"

Build Delta Chat Core

Update the repository and initialize the sub repository which contains the Delta Chat Core.

git pull
git submodule update --init --recursive

Execute the shell script in the root folder with the correct parameters.

Build for Android only:

./build-dcc.sh android

Build for iOS only:

./build-dcc.sh android

Build for both:

./build-dcc.sh all

Now the shell script build-dcc.sh is executed. So, this will take a while. You can standup to have a break, walk into the kitchen to grab a Coffee|Tea|Glas of Water|WhiskeyLemon Soda|Whatever, or you browse to Cancer Research Institute to donate for cancer research.

If the build script is done and everything is fine, then you should read something like that in your terminal:

-- Build succeeded --

That's all building libdeltachat.a. The library is placed in the appropriate directories for the given platforms. Leave it there, open Xcode or Android Studio and start using the plugin.

Errors

If an error occurs the script should give a hint how to fix the actual problem. If this is the case please proceed with executing the given hint. If the cargo build process itself fails, please verify your rust / cargo configuration is setup correctly.

Clone this wiki locally