2020-11-11 20:02:24 +01:00
|
|
|
#!/bin/bash
|
2020-10-17 01:13:18 +02:00
|
|
|
|
|
|
|
#
|
2021-01-04 21:19:09 +01:00
|
|
|
# Copyright 2020-2021 Signal Messenger, LLC.
|
2020-10-17 01:13:18 +02:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
#
|
|
|
|
|
2020-11-11 20:02:24 +01:00
|
|
|
set -euo pipefail
|
2020-10-23 20:32:45 +02:00
|
|
|
|
2020-11-16 19:39:27 +01:00
|
|
|
SCRIPT_DIR=$(dirname "$0")
|
|
|
|
cd "${SCRIPT_DIR}"/..
|
2020-11-11 20:02:24 +01:00
|
|
|
. bin/build_helpers.sh
|
2020-10-17 01:13:18 +02:00
|
|
|
|
2023-01-12 02:27:42 +01:00
|
|
|
export IPHONEOS_DEPLOYMENT_TARGET=12.2
|
2021-02-11 19:47:14 +01:00
|
|
|
export CARGO_PROFILE_RELEASE_DEBUG=1 # enable line tables
|
2021-06-09 21:19:49 +02:00
|
|
|
export CARGO_PROFILE_RELEASE_LTO=fat # use fat LTO to reduce binary size
|
2022-06-13 20:33:14 +02:00
|
|
|
export CFLAGS="-DOPENSSL_SMALL ${CFLAGS:-}" # use small BoringSSL curve tables to reduce binary size
|
2021-02-11 19:47:14 +01:00
|
|
|
|
2023-05-10 01:41:29 +02:00
|
|
|
# Work around cc crate bug with Catalyst targets
|
|
|
|
export CFLAGS_aarch64_apple_ios_macabi="--target=arm64-apple-ios-macabi ${CFLAGS}"
|
|
|
|
export CFLAGS_x86_64_apple_ios_macabi="--target=x86_64-apple-ios-macabi ${CFLAGS}"
|
|
|
|
|
2020-10-17 01:13:18 +02:00
|
|
|
usage() {
|
|
|
|
cat >&2 <<END
|
2021-10-06 01:32:42 +02:00
|
|
|
Usage: $(basename "$0") [-d|-r] [-v] [--generate-ffi|--verify-ffi|--build-std]
|
2020-10-17 01:13:18 +02:00
|
|
|
|
|
|
|
Options:
|
2021-06-09 21:19:49 +02:00
|
|
|
-d -- debug build (default)
|
|
|
|
-r -- release build
|
|
|
|
-v -- verbose build
|
2021-01-04 21:19:09 +01:00
|
|
|
|
2021-06-09 21:19:49 +02:00
|
|
|
--generate-ffi -- regenerate ffi headers
|
|
|
|
--verify-ffi -- verify that ffi headers are up to date
|
2021-10-06 01:32:42 +02:00
|
|
|
--build-std -- use Cargo's -Zbuild-std to compile for a tier 3 target
|
2020-10-17 01:13:18 +02:00
|
|
|
|
|
|
|
Use CARGO_BUILD_TARGET for cross-compilation (such as for iOS).
|
|
|
|
END
|
|
|
|
}
|
|
|
|
|
2021-01-04 21:19:09 +01:00
|
|
|
check_cbindgen() {
|
2021-03-12 01:08:30 +01:00
|
|
|
if ! command -v cbindgen > /dev/null; then
|
2021-01-04 21:19:09 +01:00
|
|
|
echo 'error: cbindgen not found in PATH' >&2
|
2021-03-12 01:08:30 +01:00
|
|
|
if command -v cargo > /dev/null; then
|
2021-01-04 21:19:09 +01:00
|
|
|
echo 'note: get it by running' >&2
|
|
|
|
printf "\n\t%s\n\n" "cargo install cbindgen --vers '^0.16'" >&2
|
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 01:04:43 +01:00
|
|
|
RELEASE_BUILD=
|
2021-01-04 21:19:09 +01:00
|
|
|
VERBOSE=
|
|
|
|
SHOULD_CBINDGEN=
|
|
|
|
CBINDGEN_VERIFY=
|
2021-10-06 01:32:42 +02:00
|
|
|
BUILD_STD=
|
2020-10-17 01:13:18 +02:00
|
|
|
|
2020-11-11 20:02:24 +01:00
|
|
|
while [ "${1:-}" != "" ]; do
|
2020-10-17 01:13:18 +02:00
|
|
|
case $1 in
|
|
|
|
-d | --debug )
|
2020-11-18 19:48:41 +01:00
|
|
|
RELEASE_BUILD=
|
2020-10-17 01:13:18 +02:00
|
|
|
;;
|
2021-03-18 01:04:43 +01:00
|
|
|
-r | --release )
|
|
|
|
RELEASE_BUILD=1
|
|
|
|
;;
|
2021-01-04 21:19:09 +01:00
|
|
|
-v | --verbose )
|
|
|
|
VERBOSE=1
|
|
|
|
;;
|
|
|
|
--generate-ffi )
|
|
|
|
SHOULD_CBINDGEN=1
|
|
|
|
;;
|
|
|
|
--verify-ffi )
|
|
|
|
SHOULD_CBINDGEN=1
|
|
|
|
CBINDGEN_VERIFY=1
|
|
|
|
;;
|
2021-10-06 01:32:42 +02:00
|
|
|
--build-std)
|
|
|
|
BUILD_STD=1
|
2021-06-09 21:19:49 +02:00
|
|
|
;;
|
2020-10-17 01:13:18 +02:00
|
|
|
-h | --help )
|
|
|
|
usage
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
usage
|
2021-01-04 21:19:09 +01:00
|
|
|
exit 2
|
2020-10-17 01:13:18 +02:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2020-10-23 20:32:45 +02:00
|
|
|
check_rust
|
2020-10-17 01:13:18 +02:00
|
|
|
|
2020-12-16 19:09:35 +01:00
|
|
|
if [[ -n "${DEVELOPER_SDK_DIR:-}" ]]; then
|
|
|
|
# Assume we're in Xcode, which means we're probably cross-compiling.
|
|
|
|
# In this case, we need to add an extra library search path for build scripts and proc-macros,
|
|
|
|
# which run on the host instead of the target.
|
|
|
|
# (macOS Big Sur does not have linkable libraries in /usr/lib/.)
|
|
|
|
export LIBRARY_PATH="${DEVELOPER_SDK_DIR}/MacOSX.sdk/usr/lib:${LIBRARY_PATH:-}"
|
|
|
|
fi
|
|
|
|
|
2021-10-06 01:32:42 +02:00
|
|
|
if [[ -n "${BUILD_STD:-}" ]]; then
|
2021-09-25 00:58:29 +02:00
|
|
|
RUSTUP_TOOLCHAIN=${RUSTUP_TOOLCHAIN:-$(cat ./rust-toolchain)}
|
|
|
|
if ! rustup "+${RUSTUP_TOOLCHAIN}" component list --installed | grep -q rust-src; then
|
|
|
|
echo 'error: rust-src component not installed' >&2
|
|
|
|
echo 'note: get it by running' >&2
|
|
|
|
printf "\n\t%s\n\n" "rustup +${RUSTUP_TOOLCHAIN} component add rust-src" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-06-09 21:19:49 +02:00
|
|
|
fi
|
|
|
|
|
2021-10-06 01:32:42 +02:00
|
|
|
echo_then_run cargo build -p libsignal-ffi ${RELEASE_BUILD:+--release} ${VERBOSE:+--verbose} ${CARGO_BUILD_TARGET:+--target $CARGO_BUILD_TARGET} ${BUILD_STD:+-Zbuild-std}
|
2021-01-04 21:19:09 +01:00
|
|
|
|
|
|
|
FFI_HEADER_PATH=swift/Sources/SignalFfi/signal_ffi.h
|
|
|
|
|
|
|
|
if [[ -n "${SHOULD_CBINDGEN}" ]]; then
|
|
|
|
check_cbindgen
|
|
|
|
if [[ -n "${CBINDGEN_VERIFY}" ]]; then
|
|
|
|
echo diff -u "${FFI_HEADER_PATH}" "<(cbindgen -q ${RELEASE_BUILD:+--profile release} rust/bridge/ffi)"
|
|
|
|
if ! diff -u "${FFI_HEADER_PATH}" <(cbindgen -q ${RELEASE_BUILD:+--profile release} rust/bridge/ffi); then
|
|
|
|
echo
|
|
|
|
echo 'error: signal_ffi.h not up to date; run' "$0" '--generate-ffi' >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo cbindgen ${RELEASE_BUILD:+--profile release} -o "${FFI_HEADER_PATH}" rust/bridge/ffi
|
|
|
|
# Use sed to ignore irrelevant cbindgen warnings.
|
|
|
|
# ...and then disable the shellcheck warning about literal backticks in single-quotes
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
cbindgen ${RELEASE_BUILD:+--profile release} -o "${FFI_HEADER_PATH}" rust/bridge/ffi 2>&1 |
|
|
|
|
sed '/WARN: Missing `\[defines\]` entry for `feature = "ffi"` in cbindgen config\./ d' >&2
|
|
|
|
fi
|
|
|
|
fi
|