veilid/scripts/ios_build.sh

74 lines
2.3 KiB
Bash
Raw Permalink Normal View History

2022-11-26 21:37:23 -05:00
#!/bin/bash
2023-01-03 09:13:18 -05:00
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
pushd $SCRIPTDIR >/dev/null
2022-11-26 21:37:23 -05:00
2022-11-29 12:32:05 -05:00
CARGO=`which cargo`
CARGO=${CARGO:=~/.cargo/bin/cargo}
CARGO_DIR=$(dirname $CARGO)
CARGO_MANIFEST_PATH=$(python3 -c "import os; import json; print(json.loads(os.popen('$CARGO locate-project').read())['root'])")
CARGO_WORKSPACE_PATH=$(python3 -c "import os; import json; print(json.loads(os.popen('$CARGO locate-project --workspace').read())['root'])")
2022-11-29 12:16:28 -05:00
TARGET_PATH=$(python3 -c "import os; print(os.path.realpath(\"$CARGO_WORKSPACE_PATH/../target\"))")
2022-11-27 22:33:41 -05:00
PACKAGE_NAME=$1
shift
2022-11-26 21:37:23 -05:00
if [ "$CONFIGURATION" == "Debug" ]; then
EXTRA_CARGO_OPTIONS="$@"
2022-11-27 22:33:41 -05:00
BUILD_MODE="debug"
2022-11-26 21:37:23 -05:00
else
EXTRA_CARGO_OPTIONS="$@ --release"
2022-11-27 22:33:41 -05:00
BUILD_MODE="release"
2022-11-26 21:37:23 -05:00
fi
ARCHS=${ARCHS:=arm64}
2022-11-27 22:33:41 -05:00
if [ "$PLATFORM_NAME" == "iphonesimulator" ]; then
LIPO_OUT_NAME="lipo-ios-sim"
else
LIPO_OUT_NAME="lipo-ios"
fi
set -euxo pipefail
LIPOS=""
2022-11-26 21:37:23 -05:00
for arch in $ARCHS
do
if [ "$arch" == "arm64" ]; then
echo arm64
2022-11-27 22:33:41 -05:00
if [ "$PLATFORM_NAME" == "iphonesimulator" ]; then
CARGO_TARGET=aarch64-apple-ios-sim
else
CARGO_TARGET=aarch64-apple-ios
fi
2022-11-26 21:37:23 -05:00
CARGO_TOOLCHAIN=
elif [ "$arch" == "x86_64" ]; then
echo x86_64
CARGO_TARGET=x86_64-apple-ios
CARGO_TOOLCHAIN=
else
echo Unsupported ARCH: $arch
continue
fi
2024-06-23 14:59:03 -04:00
2022-11-26 21:37:23 -05:00
# Choose arm64 brew for unit tests by default if we are on M1
if [ -f /opt/homebrew/bin/brew ]; then
HOMEBREW_DIR=/opt/homebrew/bin
elif [ -f /usr/local/bin/brew ]; then
HOMEBREW_DIR=/usr/local/bin
else
HOMEBREW_DIR=$(dirname `which brew`)
fi
2023-05-29 15:24:57 -04:00
env -i PATH=/usr/bin:/bin:$HOMEBREW_DIR:$CARGO_DIR HOME="$HOME" USER="$USER" IPHONEOS_DEPLOYMENT_TARGET="$IPHONEOS_DEPLOYMENT_TARGET" cargo $CARGO_TOOLCHAIN build $EXTRA_CARGO_OPTIONS --target $CARGO_TARGET --manifest-path $CARGO_MANIFEST_PATH
2022-11-27 22:33:41 -05:00
LIPOS="$LIPOS $TARGET_PATH/$CARGO_TARGET/$BUILD_MODE/lib$PACKAGE_NAME.a"
2022-11-26 21:37:23 -05:00
done
2022-12-03 12:36:06 -05:00
# Make lipo build
2022-11-27 22:33:41 -05:00
mkdir -p "$TARGET_PATH/$LIPO_OUT_NAME/$BUILD_MODE/"
lipo $LIPOS -create -output "$TARGET_PATH/$LIPO_OUT_NAME/$BUILD_MODE/lib$PACKAGE_NAME.a"
2022-12-03 12:36:06 -05:00
# Make most recent dylib available without build mode for flutter
cp "$TARGET_PATH/$LIPO_OUT_NAME/$BUILD_MODE/lib$PACKAGE_NAME.a" "$TARGET_PATH/$LIPO_OUT_NAME/lib$PACKAGE_NAME.a"
2023-01-03 09:13:18 -05:00
popd >/dev/null