Forked from brett-stover-hs/frameworks_blogpost_merge_script.sh
Last active
July 27, 2023 17:17
-
-
Save kientux/8ed105dddc99382707ecc82b619db1da to your computer and use it in GitHub Desktop.
Merge simulator and device dynamic frameworks into one
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
# Merge Script | |
# 1 | |
# Set bash script to exit immediately if any commands fail. | |
set -e | |
# 2 | |
# Setup some constants for use later on. | |
FRAMEWORK_NAME="${PROJECT_NAME}" | |
# 3 | |
# If remnants from a previous build exist, delete them. | |
if [ -d "${SYMROOT}" ]; then | |
echo "${SYMROOT}" | |
rm -rf "${SYMROOT}" | |
fi | |
# 4 | |
# Build the framework for device and for simulator (using all needed architectures). | |
xcodebuild -target "${FRAMEWORK_NAME}" SYMROOT="$SYMROOT" -configuration Release -arch arm64 -arch armv7 -arch armv7s only_active_arch=no defines_module=yes -sdk "iphoneos" | |
xcodebuild -target "${FRAMEWORK_NAME}" SYMROOT="$SYMROOT" -configuration Release -arch x86_64 -arch i386 only_active_arch=no defines_module=yes -sdk "iphonesimulator" | |
# 5 | |
# Copy the device version of framework to build dir. | |
cp -r "${SYMROOT}/Release-iphoneos/${FRAMEWORK_NAME}.framework" "${SYMROOT}/${FRAMEWORK_NAME}.framework" | |
# 6 | |
# Replace the framework executable within the framework with | |
# a new version created by merging the device and simulator | |
# frameworks' executables with lipo. | |
lipo -create -output "${SYMROOT}/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${SYMROOT}/Release-iphoneos/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${SYMROOT}/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" | |
# 7 | |
# Copy the Swift module mappings for the simulator into the | |
# framework. The device mappings already exist from step 5. | |
cp -r "${SYMROOT}/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule/" "${SYMROOT}/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule" | |
open "$SYMROOT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fork to:
xcodebuild
build the project into${SYMROOT}
(usually derived data folder) instead of default location (${SRCROOT}/build
)