2020-11-04 23:37:41 +01:00
|
|
|
#!/bin/bash
|
2020-11-04 18:30:59 +01:00
|
|
|
|
|
|
|
#
|
2022-07-26 01:36:53 +02:00
|
|
|
# Copyright (C) 2020-2022 Signal Messenger, LLC.
|
2020-11-04 18:30:59 +01:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
#
|
|
|
|
|
2020-12-08 23:40:30 +01:00
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
SCRIPT_DIR=$(dirname "$0")
|
|
|
|
cd "${SCRIPT_DIR}"/..
|
|
|
|
. bin/build_helpers.sh
|
|
|
|
|
2020-11-04 18:30:59 +01:00
|
|
|
# These paths are relative to the root directory
|
|
|
|
ANDROID_LIB_DIR=java/android/src/main/jniLibs
|
java: Build a separate libsignal-server artifact
Reorganize the Gradle build with three targets:
- signal-client-java (client/)
- signal-client-android (android/)
- libsignal-server (server/)
plus an additional shared/ directory for sources shared between
client/ and server/.
This maintains the distinction between signal-client-java (the Java
parts, plus a Linux libsignal_jni.so for running tests outside of the
Android emulator) and signal-client-android (contains the Android JNI
libraries, plus any Android-specific code, which for now is just
AndroidSignalProtocolLogger, which the app doesn't even use).
The new libsignal-server is built very similarly to
signal-client-java, but only contains the Java sources relevant for
the server...plus the base org.whispersystems.libsignal classes from
the original libsignal-protocol-java, because some of them are
referenced directly in our generated Native.java. (We can improve on
this in the future.) The "testable" artifact that includes macOS and
Windows versions of libsignal_jni.so is now only built for
libsignal-server, not signal-client-java; our Android development
happens on Linux, but server development happens on multiple
platforms.
Tests were recently reorganized into a top-level tests/ directory, but
now there's been another reorganization:
- client/src/test/ - tests to run on any clients
- android/src/androidTest/ - tests to run only on Android devices /
emulators (currently none)
- server/src/test/ - tests to run specifically for the server
(currently none)
- shared/test/ - does not exist to avoid running the same tests twice
There are no tests to run "only not on Android devices", and it's
currently assumed that all server functionality is tested by the
client tests. The Android device tests run all the client tests as
well (by direct path reference). This may not be the "best" Gradle
layout, but it's at least straightforward to read the Gradle files.
For now there's still only one native library built for both
signal-client-java and libsignal-server, but that could change in the
future.
2022-03-10 01:45:04 +01:00
|
|
|
DESKTOP_LIB_DIR=java/shared/resources
|
2020-11-04 18:30:59 +01:00
|
|
|
|
2020-12-04 20:35:03 +01:00
|
|
|
export CARGO_PROFILE_RELEASE_DEBUG=1 # enable line tables
|
2020-11-20 03:11:43 +01:00
|
|
|
# On Linux, cdylibs don't include public symbols from their dependencies,
|
|
|
|
# even if those symbols have been re-exported in the Rust source.
|
|
|
|
# Using LTO works around this at the cost of a slightly slower build.
|
|
|
|
# https://github.com/rust-lang/rfcs/issues/2771
|
2021-10-06 21:29:50 +02:00
|
|
|
export CARGO_PROFILE_RELEASE_LTO=thin
|
|
|
|
export CARGO_PROFILE_RELEASE_OPT_LEVEL=s # optimize for size over speed
|
2020-11-04 18:30:59 +01:00
|
|
|
|
2023-10-04 22:49:19 +02:00
|
|
|
case "$1" in
|
|
|
|
desktop )
|
|
|
|
echo_then_run cargo build -p libsignal-jni --release
|
|
|
|
if [[ -z "${CARGO_BUILD_TARGET:-}" ]]; then
|
|
|
|
copy_built_library target/release signal_jni "${DESKTOP_LIB_DIR}/"
|
|
|
|
fi
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
android )
|
|
|
|
android_abis=(arm64-v8a armeabi-v7a x86_64 x86)
|
|
|
|
;;
|
|
|
|
android-arm64 | android-aarch64 )
|
|
|
|
android_abis=(arm64-v8a)
|
|
|
|
;;
|
|
|
|
android-arm | android-armv7 )
|
|
|
|
android_abis=(armeabi-v7a)
|
|
|
|
;;
|
|
|
|
android-x86_64 )
|
|
|
|
android_abis=(x86_64)
|
|
|
|
;;
|
|
|
|
android-x86 | android-i686 )
|
|
|
|
android_abis=(x86)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown target (use 'desktop', 'android', or 'android-\$ARCH')" >&2
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
2020-11-06 21:54:59 +01:00
|
|
|
|
2023-10-04 22:49:19 +02:00
|
|
|
# Use small BoringSSL curve tables to reduce binary size on Android.
|
|
|
|
export CFLAGS="-DOPENSSL_SMALL -flto=thin ${CFLAGS:-}"
|
|
|
|
|
|
|
|
# Use the Android NDK's prebuilt Clang+lld as pqcrypto's compiler and Rust's linker.
|
|
|
|
ANDROID_TOOLCHAIN_DIR=$(echo "${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt"/*/bin/)
|
|
|
|
export CC_aarch64_linux_android="${ANDROID_TOOLCHAIN_DIR}/aarch64-linux-android21-clang"
|
|
|
|
export CC_armv7_linux_androideabi="${ANDROID_TOOLCHAIN_DIR}/armv7a-linux-androideabi21-clang"
|
|
|
|
export CC_x86_64_linux_android="${ANDROID_TOOLCHAIN_DIR}/x86_64-linux-android21-clang"
|
|
|
|
export CC_i686_linux_android="${ANDROID_TOOLCHAIN_DIR}/i686-linux-android21-clang"
|
|
|
|
|
|
|
|
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${CC_aarch64_linux_android}"
|
|
|
|
export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="${CC_armv7_linux_androideabi}"
|
|
|
|
export CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="${CC_x86_64_linux_android}"
|
|
|
|
export CARGO_TARGET_I686_LINUX_ANDROID_LINKER="${CC_i686_linux_android}"
|
|
|
|
|
|
|
|
export TARGET_AR="${ANDROID_TOOLCHAIN_DIR}/llvm-ar"
|
|
|
|
export RUSTFLAGS="-C link-arg=-fuse-ld=lld ${RUSTFLAGS:-}"
|
|
|
|
export RUSTFLAGS="--cfg aes_armv8 --cfg polyval_armv8 ${RUSTFLAGS:-}" # Enable ARMv8 cryptography acceleration when available
|
|
|
|
|
2023-10-31 20:23:56 +01:00
|
|
|
# The 64-bit curve25519-dalek backend is faster than the 32-bit one on at least some armv7a phones.
|
|
|
|
# Comment out the following to allow the 32-bit backend on 32-bit targets.
|
|
|
|
export RUSTFLAGS="--cfg curve25519_dalek_bits=\"64\" ${RUSTFLAGS:-}"
|
2023-10-04 22:49:19 +02:00
|
|
|
|
|
|
|
target_for_abi() {
|
|
|
|
case "$1" in
|
|
|
|
arm64-v8a)
|
|
|
|
echo aarch64-linux-android
|
|
|
|
;;
|
|
|
|
armeabi-v7a)
|
|
|
|
echo armv7-linux-androideabi
|
|
|
|
;;
|
|
|
|
x86_64)
|
|
|
|
echo x86_64-linux-android
|
|
|
|
;;
|
|
|
|
x86)
|
|
|
|
echo i686-linux-android
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown Android ABI $1; please update build_jni.sh" >&2
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
for abi in "${android_abis[@]}"; do
|
|
|
|
rust_target=$(target_for_abi "$abi")
|
|
|
|
echo_then_run cargo build -p libsignal-jni --release -Z unstable-options --target "$rust_target" --out-dir "${ANDROID_LIB_DIR}/$abi"
|
|
|
|
done
|