diff --git a/platforms/ios/bazel_build_tflite_catalyst b/platforms/ios/bazel_build_tflite_catalyst new file mode 100755 index 00000000..bac3cc57 --- /dev/null +++ b/platforms/ios/bazel_build_tflite_catalyst @@ -0,0 +1,67 @@ +#!/bin/bash -v + +if [ \( -n "$1" \) ]; then + echo "Building with config $1" +else + echo "Please specify the ios config and architecture to build. e.g. $0 ios_fat; $0 ios_x86_64; $0 ios_sim_arm64; $0 ios_arm64; $0 ios_armv7" + exit 1 +fi + +cd "$(dirname "$0")" +cd ../../ +mkdir -p lib/ios +cd tensorflow + +#check for x86_64 version of python3 from homebew +if test -f "/usr/local/bin/python3"; then + if test -d "/usr/local/lib/python3.9/site-packages"; then + export PYTHON_BIN_PATH="/usr/local/bin/python3" + export PYTHON_LIB_PATH="/usr/local/lib/python3.9/site-packages" + fi +fi + +#check for arm64 version of python3, if it is available, use this instead. +if test -f "/opt/homebrew/bin/python3"; then + if test -d "/opt/homebrew/lib/python3.9/site-packages"; then + export PYTHON_BIN_PATH="/opt/homebrew/bin/python3" + export PYTHON_LIB_PATH="/opt/homebrew/lib/python3.9/site-packages" + fi +fi + +#The python3 comes with Xcode seems to have issues when compiling for tflite using bazel, will disable it now. + +#if test -f "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/Current/bin/python3"; then +# if test -d "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/Current/lib/python3.8/site-packages"; then +# export PYTHON_BIN_PATH="/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/Current/bin/python3" +# export PYTHON_LIB_PATH="/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/Current/lib/python3.8/site-packages" +# fi +#fi + +echo PYTHON_BIN_PATH=$PYTHON_BIN_PATH +echo PYTHON_LIB_PATH=$PYTHON_LIB_PATH + +export TF_CONFIGURE_IOS='1' +export TF_ENABLE_XLA=1 +export TF_NEED_CUDA=0 +export TF_NEED_ROCM=0 +export TF_NEED_OPENCL_SYCL=0 +export TF_DOWNLOAD_CLANG=0 +export CC_OPT_FLAGS="-match=native -Wno-sign-compare" +export TF_SET_ANDROID_WORKSPACE=0 + +BAZEL_OUTPUT_USER_ROOT="$(pwd)/../bazel_output_$1" + +cp -f tensorflow/lite/ios/BUILD.apple tensorflow/lite/ios/BUILD + +rm -rf bazel-bin/tensorflow/lite/ios/TensorFlowLiteC_framework.zip + +./configure +#alias python="/usr/local/bin/python3" +#bazel --output_user_root=$BAZEL_OUTPUT_USER_ROOT build --verbose_failures --config=ios_fat --copt="-DCL_DELEGATE_NO_GL" --copt="-D__IOS__" -c opt --action_env PATH="$PATH" //tensorflow/lite/ios:TensorFlowLiteC_framework +bazel --output_user_root=$BAZEL_OUTPUT_USER_ROOT build --verbose_failures --incompatible_run_shell_command_string=false --apple_platform_type=macos --cpu==$1 --copt="-DCL_DELEGATE_NO_GL" --copt="-D__IOS__" -c opt ${@:2} //tensorflow/lite/ios:TensorFlowLiteC_framework +unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteC_framework.zip TensorFlowLiteC.framework/TensorFlowLiteC -d ../lib/ios +mv ../lib/ios/TensorFlowLiteC.framework/TensorFlowLiteC ../lib/ios/libtfliteextern_$1.a +#cp -r TensorFlowLiteC.framework/TensorFlowLiteC ../lib/ios/libtfliteextern.a +cd .. + + diff --git a/platforms/ios/bazel_build_tflite_ios b/platforms/ios/bazel_build_tflite_ios index 2392f3fe..b21871ef 100755 --- a/platforms/ios/bazel_build_tflite_ios +++ b/platforms/ios/bazel_build_tflite_ios @@ -3,10 +3,18 @@ if [ \( -n "$1" \) ]; then echo "Building with config $1" else - echo "Please specify the ios config and architecture to build. e.g. $0 ios_fat; $0 ios_x86_64; $0 ios_sim_arm64; $0 ios_arm64; $0 ios_armv7" + echo "Please specify the ios config and architecture to build. e.g. $0 ios_fat; $0 ios_x86_64; $0 ios_sim_arm64; $0 ios_arm64; $0 ios_armv7; $0 darwin_x86_64" exit 1 fi +if [ "$1" = "darwin_x86_64" ] || [ "$1" = "darwin_arm64" ]; then + echo "Building for Mac Catlyst" + BAZEL_BUILD_OPTION="--apple_platform_type=macos --cpu=$1" +else + echo "Building for iOS" + BAZEL_BUILD_OPTION="-config=$1" +fi + cd "$(dirname "$0")" cd ../../ mkdir -p lib/ios @@ -58,7 +66,7 @@ rm -rf bazel-bin/tensorflow/lite/ios/TensorFlowLiteC_framework.zip ./configure #alias python="/usr/local/bin/python3" #bazel --output_user_root=$BAZEL_OUTPUT_USER_ROOT build --verbose_failures --config=ios_fat --copt="-DCL_DELEGATE_NO_GL" --copt="-D__IOS__" -c opt --action_env PATH="$PATH" //tensorflow/lite/ios:TensorFlowLiteC_framework -bazel --output_user_root=$BAZEL_OUTPUT_USER_ROOT build --verbose_failures --incompatible_run_shell_command_string=false --config=$1 --copt="-DCL_DELEGATE_NO_GL" --copt="-D__IOS__" -c opt ${@:2} //tensorflow/lite/ios:TensorFlowLiteC_framework +bazel --output_user_root=$BAZEL_OUTPUT_USER_ROOT build --verbose_failures --incompatible_run_shell_command_string=false $BAZEL_BUILD_OPTION --copt="-DCL_DELEGATE_NO_GL" --copt="-D__IOS__" -c opt ${@:2} //tensorflow/lite/ios:TensorFlowLiteC_framework unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteC_framework.zip TensorFlowLiteC.framework/TensorFlowLiteC -d ../lib/ios mv ../lib/ios/TensorFlowLiteC.framework/TensorFlowLiteC ../lib/ios/libtfliteextern_$1.a #cp -r TensorFlowLiteC.framework/TensorFlowLiteC ../lib/ios/libtfliteextern.a