#!/usr/bin/env sh set -eo pipefail # Check if lipo and xcodebuild exist if [ -z `command -v lipo` ] || [ -z `command -v xcodebuild` ] || [ -z `command -v sed` ] then echo "!!! lipo, xcodebuild or sed could not be found !!!" help fi NAME="aries_askar" BUNDLE_NAME="aries-askar" VERSION=$(cargo generate-lockfile && cargo pkgid | sed -e "s/^.*#//") BUNDLE_IDENTIFIER="org.hyperledger.$BUNDLE_NAME" LIBRARY_NAME="lib$NAME.a" XC_FRAMEWORK_NAME="$NAME.xcframework" FRAMEWORK_LIBRARY_NAME=$NAME FRAMEWORK_NAME="$FRAMEWORK_LIBRARY_NAME.framework" HEADER_NAME="lib$NAME.h" OUT_PATH="out" MIN_IOS_VERSION="12.0" # Setting some default paths AARCH64_APPLE_IOS_PATH="./target/aarch64-apple-ios/release" AARCH64_APPLE_IOS_SIM_PATH="./target/aarch64-apple-ios-sim/release" X86_64_APPLE_IOS_PATH="./target/x86_64-apple-ios/release" HEADER_PATH="./include" # Simple helper command to display some information Help() { echo "required dependencies:" echo " - lipo" echo " - sed" echo " - xcodebuild" echo "To build an xcframework with underlying Frameworks" echo "the following can be passed in as positional arguments" echo " 1. Path to the aarch64-apple-ios directory where $LIBRARY_NAME is stored" echo " 2. Path to the aarch64-apple-ios-sim directory where $LIBRARY_NAME is stored" echo " 3. Path to the x86_64-apple-ios directory where $LIBRARY_NAME is stored" echo " 4. Path to the header file, excluding the header" echo "Make sure to add the 'release' section of the path for a" echo "release build." exit 1 } # override if its provided if [ ! -z "$1" ] then AARCH64_APPLE_IOS_PATH=$1 fi # override if its provided if [ ! -z "$2" ] then AARCH64_APPLE_IOS_SIM_PATH=$2 fi # override if its provided if [ ! -z "$3" ] then X86_64_APPLE_IOS_PATH=$3 fi # override if its provided if [ ! -z "$4" ] then HEADER_PATH=$4 fi if [ ! -f $AARCH64_APPLE_IOS_SIM_PATH/$LIBRARY_NAME ] then echo "$AARCH64_APPLE_IOS_SIM_PATH/$LIBRARY_NAME does not exist!" exit 1 fi if [ ! -f $AARCH64_APPLE_IOS_PATH/$LIBRARY_NAME ] then echo "$AARCH64_APPLE_IOS_PATH/$LIBRARY_NAME does not exist!" exit 1 fi if [ ! -f $X86_64_APPLE_IOS_PATH/$LIBRARY_NAME ] then echo "$X86_64_APPLE_IOS_PATH/$LIBRARY_NAME does not exist!" exit 1 fi if [ ! -f $HEADER_PATH/$HEADER_NAME ] then echo "$HEADER_PATH/$HEADER_NAME does not exist!" exit 1 fi # Displaying the supplied paths to the user # So there will not be any mistakes cat << EOF Using $AARCH64_APPLE_IOS_PATH for aarch64-apple-ios Using $AARCH64_APPLE_IOS_SIM_PATH for aarch64-apple-ios-sim Using $X86_64_APPLE_IOS_PATH for x86_64-apple-ios Building xcframework with the following values: Name: $NAME Version: $VERSION Bundle identifier: $BUNDLE_IDENTIFIER Library name: $LIBRARY_NAME Framework name: $FRAMEWORK_NAME XCFramework name: $XC_FRAMEWORK_NAME Framework library name: $FRAMEWORK_LIBRARY_NAME EOF echo "Setting op output directory in $OUT_PATH" mkdir $OUT_PATH echo "Combining aarch64 and x86-64 for the simulator.." lipo -create $AARCH64_APPLE_IOS_SIM_PATH/$LIBRARY_NAME \ $X86_64_APPLE_IOS_PATH/$LIBRARY_NAME \ -output $OUT_PATH/sim-$LIBRARY_NAME echo "Creating a framework template..." mkdir $OUT_PATH/$FRAMEWORK_NAME cd $OUT_PATH/$FRAMEWORK_NAME mkdir Headers cp ../../$HEADER_PATH/$HEADER_NAME Headers/$FRAMEWORK_LIBRARY_NAME.h mkdir Modules touch Modules/module.modulemap cat <> Modules/module.modulemap framework module $FRAMEWORK_LIBRARY_NAME { umbrella header "$FRAMEWORK_LIBRARY_NAME.h" export * module * { export * } } EOT cat <> Info.plist CFBundleDevelopmentRegion en CFBundleExecutable $FRAMEWORK_LIBRARY_NAME CFBundleIdentifier $BUNDLE_IDENTIFIER CFBundleInfoDictionaryVersion 6.0 CFBundleName $NAME CFBundlePackageType FMWK CFBundleShortVersionString 1.0 CFBundleVersion $VERSION NSPrincipalClass MinimumOSVersion $MIN_IOS_VERSION EOT cd .. echo "Creating both frameworks (real device and simulator)..." mkdir sim mkdir real cp -r $FRAMEWORK_NAME sim/ cp -r $FRAMEWORK_NAME real/ mv sim-$LIBRARY_NAME sim/$FRAMEWORK_NAME/$FRAMEWORK_LIBRARY_NAME cp ../$AARCH64_APPLE_IOS_PATH/$LIBRARY_NAME real/$FRAMEWORK_NAME/$FRAMEWORK_LIBRARY_NAME echo "Creating XC Framework..." xcodebuild -create-xcframework \ -framework sim/$FRAMEWORK_NAME \ -framework real/$FRAMEWORK_NAME \ -output $XC_FRAMEWORK_NAME echo "cleaning up..." rm -rf $FRAMEWORK_NAME real sim echo "Framework written to $OUT_PATH/$XC_FRAMEWORK_NAME"