2022-01-30 02:25:21 +00:00
|
|
|
#!/bin/bash
|
2022-06-10 21:07:10 +00:00
|
|
|
set -e
|
|
|
|
echo Running veilid-flutter rust iOS build script
|
2022-01-30 02:25:21 +00:00
|
|
|
|
2022-01-31 02:28:27 +00:00
|
|
|
# Setup varaiables
|
2022-01-30 02:25:21 +00:00
|
|
|
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
2022-01-31 02:28:27 +00:00
|
|
|
FLUTTER_DIR=$(dirname `which flutter`)
|
|
|
|
HOMEBREW_DIR=$(dirname `which brew`)
|
|
|
|
CARGO_DIR=$(dirname `which cargo`)
|
2022-06-10 21:07:10 +00:00
|
|
|
CARGO_MANIFEST_PATH=$(python3 -c "import os; print(os.path.realpath(\"$SCRIPTDIR/Cargo.toml\"))")
|
2022-01-31 02:28:27 +00:00
|
|
|
TARGET_DIR=$(dirname `cargo locate-project --message-format plain`)/target
|
2022-01-30 02:25:21 +00:00
|
|
|
|
2022-01-31 02:28:27 +00:00
|
|
|
# Configure outputs
|
|
|
|
OUTPUT_FILENAME=libveilid_flutter.a
|
|
|
|
OUTPUT_DIR=$TARGET_DIR/ios_lib
|
|
|
|
|
|
|
|
# Get Rust configurations from xcode configurations
|
2022-01-30 02:25:21 +00:00
|
|
|
if [ "$CONFIGURATION" == "Debug" ]; then
|
|
|
|
EXTRA_CARGO_OPTIONS="$@"
|
2022-01-31 02:28:27 +00:00
|
|
|
RUST_CONFIGURATION="debug"
|
2022-01-30 02:25:21 +00:00
|
|
|
else
|
|
|
|
EXTRA_CARGO_OPTIONS="$@ --release"
|
2022-01-31 02:28:27 +00:00
|
|
|
RUST_CONFIGURATION="release"
|
2022-01-30 02:25:21 +00:00
|
|
|
fi
|
2022-01-31 02:28:27 +00:00
|
|
|
|
|
|
|
# Build all the matching architectures for the xcode configurations
|
2022-01-30 02:25:21 +00:00
|
|
|
ARCHS=${ARCHS:=arm64}
|
2022-01-31 02:28:27 +00:00
|
|
|
echo ARCHS: $ARCHS
|
|
|
|
LIPO_LIST=""
|
2022-01-30 02:25:21 +00:00
|
|
|
for arch in $ARCHS
|
|
|
|
do
|
|
|
|
if [ "$arch" == "arm64" ]; then
|
|
|
|
echo arm64
|
|
|
|
CARGO_TARGET=aarch64-apple-ios
|
2022-06-10 21:07:10 +00:00
|
|
|
#CARGO_TOOLCHAIN=+ios-arm64-1.57.0
|
|
|
|
CARGO_TOOLCHAIN=
|
2022-01-30 02:25:21 +00:00
|
|
|
elif [ "$arch" == "x86_64" ]; then
|
|
|
|
echo x86_64
|
|
|
|
CARGO_TARGET=x86_64-apple-ios
|
|
|
|
CARGO_TOOLCHAIN=
|
|
|
|
else
|
|
|
|
echo Unsupported ARCH: $arch
|
|
|
|
continue
|
|
|
|
fi
|
2022-01-31 02:28:27 +00:00
|
|
|
|
|
|
|
# Cargo build
|
2022-01-30 04:23:50 +00:00
|
|
|
env -i PATH=/usr/bin:/bin:/usr/local/bin:$HOMEBREW_DIR:$FLUTTER_DIR:$CARGO_DIR HOME="$HOME" USER="$USER" cargo $CARGO_TOOLCHAIN build $EXTRA_CARGO_OPTIONS --target $CARGO_TARGET --manifest-path $CARGO_MANIFEST_PATH
|
2022-01-31 02:28:27 +00:00
|
|
|
|
|
|
|
# Add output to lipo list
|
|
|
|
LIPO_LIST="$LIPO_LIST $TARGET_DIR/$CARGO_TARGET/$RUST_CONFIGURATION/$OUTPUT_FILENAME"
|
2022-01-30 02:25:21 +00:00
|
|
|
done
|
|
|
|
|
2022-01-31 02:28:27 +00:00
|
|
|
# Lipo the architectures together
|
|
|
|
mkdir -p $OUTPUT_DIR
|
|
|
|
lipo -output "$OUTPUT_DIR/$OUTPUT_FILENAME" -create $LIPO_LIST
|