Created
February 16, 2021 18:44
-
-
Save cmkilger/95ce0ae482f42799cfad2691bde94f3c to your computer and use it in GitHub Desktop.
Converts iOS/Simulator universal frameworks into xcframeworks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Assumes that the framework contains i382, x86_64, armv7, and arm64 | |
for path in "$@" | |
do | |
framework=$(basename "$path") | |
# Make sure it's a framework' | |
if [ "${framework##*.}" != "framework" ]; then | |
>&2 echo "Skipping $path. It doesn't appear to be a framework." | |
continue | |
fi | |
# Get needed names | |
dir=$(dirname "$path") | |
name="${framework%.*}" | |
# Create temporary scratch area | |
temp=$(mktemp -d) | |
mkdir "$temp/ios" | |
mkdir "$temp/sim" | |
cp -r "$path" "$temp/ios" | |
cp -r "$path" "$temp/sim" | |
# Just making sure the library is where it is expected to be | |
if [ ! -f "$temp/ios/$framework/$name" ]; then | |
>&2 echo "$temp/ios/$framework/$name doesn't exist!" | |
continue | |
fi | |
if [ ! -f "$temp/sim/$framework/$name" ]; then | |
>&2 echo "$temp/sim/$framework/$name doesn't exist!" | |
continue | |
fi | |
# Extract architectures | |
lipo -extract armv7 -output "$temp/ios/$framework/$name.armv7" "$temp/ios/$framework/$name" | |
lipo -extract arm64 -output "$temp/ios/$framework/$name.arm64" "$temp/ios/$framework/$name" | |
lipo -extract i386 -output "$temp/sim/$framework/$name.i386" "$temp/sim/$framework/$name" | |
lipo -extract x86_64 -output "$temp/sim/$framework/$name.x86_64" "$temp/sim/$framework/$name" | |
# Recombine | |
lipo -create -output "$temp/ios/$framework/$name" "$temp/ios/$framework/$name.armv7" "$temp/ios/$framework/$name.arm64" | |
lipo -create -output "$temp/sim/$framework/$name" "$temp/sim/$framework/$name.i386" "$temp/sim/$framework/$name.x86_64" | |
# Cleanup individual archs | |
rm "$temp/ios/$framework/$name.armv7" | |
rm "$temp/ios/$framework/$name.arm64" | |
rm "$temp/sim/$framework/$name.i386" | |
rm "$temp/sim/$framework/$name.x86_64" | |
# Create xcframework | |
xcrun xcodebuild -create-xcframework -framework "$temp/ios/$framework" -framework "$temp/sim/$framework" -output "$dir/$name.xcframework" | |
# Cleanup | |
rm -rf "$temp" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment