Provide native lib for libsignal - AsamK/signal-cli GitHub Wiki

Native libraries

signal-cli depends on the libsignal-client library. It is a rust library and needs to be compiled for a specific processor architecture and operating system that it will be used on.

signal-cli releases include the pre-compiled binaries for x86_64 Linux (with a recent enough version of glibc, see #643), Windows and macOS. For other platforms the library needs to be compiled from source.

Pre-built

Builds for some additional platforms are available in

Manual build

Dependencies

  • JDK
  • gradle
  • rust (Guide here)
  • protocol buffer compiler ("apt install protobuf-compiler")

Download libsignal-client source

Clone libsignal-client with git, or download the "Source code" file from the releases page (see below for choosing the version from the releases).

Determine the required libsignal-client version

Every signal-cli release requires a specific version of libsignal-client. The version number is a part of a libsignal-client-<VERSION>.jar filename in signal-cli's lib directory. For instance, for signal-cli v0.10.5, the file is

signal-cli-0.10.5/lib/libsignal-client-0.15.0.jar

This is the file path if you have downloaded a signal-cli release. If you have built signal-cli from source, the path will be

signal-cli/build/install/signal-cli/lib/libsignal-client-0.15.0.jar

So the required libsignal-client version is 0.15.0.

Build

Once everything is setup, navigate to the root of the libsignal-client codebase:

$ cd java
$ # Prevent building the android library
$ sed -i "s/include ':android'//" settings.gradle
$ ./build_jni.sh desktop

Then the native lib can be found in the libsignal-client sub-directory: target/release/libsignal_jni.so (the file extension will be .dylib on MacOS and .dll on Windows, instead of .so).

Using the new libsignal-client lib file

Once you have your library file, it can be bundled in the root of the libsignal-client-*.jar file (but only for one architecture at a time).

First, the currently bundled file needs to be removed:

zip -d signal-cli/lib/libsignal-client-*.jar libsignal_jni.so

For signal-cli to be able to use the newly compiled library file, it can either be bundled into the .jar file with

zip signal-cli/lib/libsignal-client-*.jar libsignal_jni.so

or be placed on the Java library path (see below). Only if there is no bundled file will libsignal search the library path (java.library.path) for the .dylib/.so/.dll file.

Note: on Windows, bundling the compiled signal_jni.dll file does not seem to work: see #517. (According a comment in that thread, bundling does work if the files are renamed).

Java library path

Finding the default java.library.path

You can run the following command to get the value of java.library.path on your system:

java -XshowSettings:properties -version 2>&1 | grep java.library.path

Note that there may be multiple paths to choose from, they are separated with a colon.

Overriding java.library.path

If your java.library.path doesn't have any usable paths or you wish to not use the system defaults, then you can override the paths by modifying the final line of build/install/signal-cli/bin/signal-cli

JAVA_LIBRARY_PATH="-Djava.library.path=/your/java/library/path"
exec "$JAVACMD" "$JAVA_LIBRARY_PATH" "$@"

Make sure to place your .dylib/.so/.dll file in that folder. Be aware that this method isn't ideal since if you rebuild signal-cli, then the script may be regenerated and you'll need to set this again.

⚠️ **GitHub.com Fallback** ⚠️