Skip to content

Instantly share code, notes, and snippets.

@shaps80

shaps80/strip-intel.sh

Last active Dec 17, 2020
Embed
What would you like to do?
Strip Intel architecture's from Xcode frameworks for use on Apple Silicon
#!/bin/sh
# strip-intel.sh
# Usage example: ./strip-intel.sh
# This script is design to remove Intel architecture's from Xcode frameworks
# to enable development and installation of 3rd party pre-compiled frameworks
# that are not currently distributed as either XCFramework or SPM packages.
# The most common use-case would be carthage dependencies that are distributed
# as pre-compiled Universal framework.
arch_name="$(uname -m)"
if [ "${arch_name}" = "x86_64" ]; then
if [ "$(sysctl -in sysctl.proc_translated)" = "1" ]; then
break
else
echo "This script isn't required for Intel Macs"
fi
elif [ "${arch_name}" = "arm64" ]; then
break
else
echo "Unknown architecture: ${arch_name}"
exit 1
fi
echo $PWD
find . -name '*.framework' -type d | while read -r FRAMEWORK
do
PATH_COUNT=$(echo "$FRAMEWORK/" | grep -o '/' | wc -l)
FILE_NAME=$(echo $FRAMEWORK | cut -d '/' -f $PATH_COUNT | cut -d '.' -f 1)
EXECUTE_FILE="$FRAMEWORK/$FILE_NAME"
echo $EXECUTE_FILE
if $(lipo $EXECUTE_FILE -verify_arch i386); then
lipo -remove i386 $EXECUTE_FILE -o $EXECUTE_FILE
fi
if $(lipo $EXECUTE_FILE -verify_arch x86_64); then
lipo -remove x86_64 $EXECUTE_FILE -o $EXECUTE_FILE
fi
lipo -archs $EXECUTE_FILE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment