Created
December 7, 2023 15:01
-
-
Save maxxfrazer/c8a6ff8ab84dca68de2d01b7c41ac13e to your computer and use it in GitHub Desktop.
Script to process .xcframework files and create new versions with specific configurations.
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/bash | |
# Script to process .xcframework files and create new versions with specific configurations | |
# Usage: ./script_name.sh path_to_xcframeworks | |
set -e # Exit immediately if a command exits with a non-zero status | |
all_frameworks_path="$1" # The first argument is the path to the xcframeworks | |
# Change directory to the specified frameworks path | |
pushd "$all_frameworks_path" > /dev/null | |
# Loop through each .xcframework file in the directory | |
while IFS= read -r xcframework; do | |
# Extract the binary name from the xcframework path | |
binary_name="${xcframework%.*}" | |
binary_name="${binary_name#./}" # Remove './' from the beginning | |
# Define framework paths for different platforms and architectures | |
physical_ios="$xcframework/ios-arm64_armv7/$binary_name.framework" | |
simulator_ios="$xcframework/ios-arm64_x86_64-simulator/$binary_name.framework" | |
macos_framework="$xcframework/macos-arm64_x86_64/$binary_name.framework" | |
physical_xros="$xcframework/xros-arm64/$binary_name.framework" | |
simulator_xros="$xcframework/xros-arm64_x86_64-simulator/$binary_name.framework" | |
# Process the physical iOS framework | |
if [ -d "$physical_ios" ]; then | |
mkdir -p "$(dirname "$physical_xros")" | |
cp -rp "$physical_ios" "$(dirname "$physical_xros")" | |
xcrun lipo -remove armv7 "$physical_xros/$binary_name" -output "$physical_xros/$binary_name" || true | |
xcrun vtool -arch arm64 -set-build-version 11 1.0 1.0 -replace "$physical_xros/$binary_name" -output "$physical_xros/$binary_name" | |
fi | |
# Process the simulator iOS framework | |
if [ -d "$simulator_ios" ]; then | |
mkdir -p "$(dirname "$simulator_xros")" | |
cp -rp "$simulator_ios" "$(dirname "$simulator_xros")" | |
# Add commands to separate binaries for arm64 and x86_64 if necessary | |
xcrun vtool -arch arm64 -set-build-version 12 1.0 1.0 -replace "$simulator_xros/$binary_name" -output "$simulator_xros/$binary_name" | |
xcrun vtool -arch x86_64 -set-build-version 12 1.0 1.0 -replace "$simulator_xros/$binary_name" -output "$simulator_xros/$binary_name" | |
fi | |
# Prepare a list of frameworks to include in the new xcframework | |
frameworks_to_include=() | |
for framework in "$physical_ios" "$simulator_ios" "$macos_framework" "$physical_xros" "$simulator_xros"; do | |
[ -d "$framework" ] && frameworks_to_include+=("-framework" "$framework") | |
done | |
# Create a new xcframework with all specified components | |
xcrun xcodebuild -create-xcframework "${frameworks_to_include[@]}" -output "XROS_$binary_name.xcframework" | |
# Replace the original xcframework with the newly created one | |
rm -rf "$xcframework" | |
mv "XROS_$binary_name.xcframework" "$xcframework" | |
done < <(find . -name '*.xcframework' -type d) | |
# Return to the original directory | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment