Skip to content

Instantly share code, notes, and snippets.

@shaps80
Last active December 17, 2020 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaps80/1d6ff07f5d6da8d0763d10e5d8b2d633 to your computer and use it in GitHub Desktop.
Save shaps80/1d6ff07f5d6da8d0763d10e5d8b2d633 to your computer and use it in GitHub Desktop.
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