veilid/veilid-flutter/rust/ios_build.sh

56 lines
1.7 KiB
Bash
Raw Normal View History

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