Skip to content

Instantly share code, notes, and snippets.

@karosLi
Created March 11, 2022 10:25
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 karosLi/4773174d0bd5e595b980827048a0598e to your computer and use it in GitHub Desktop.
Save karosLi/4773174d0bd5e595b980827048a0598e to your computer and use it in GitHub Desktop.
build_framework
# Merge Script
# 1
# Set bash script to exit immediately if any commands fail.
set -e
# 2
# Setup some constants for use later on.
PROJECT=WPFixDemo.xcodeproj
FRAMEWORK_NAME=WPFix
SYMROOT=build
# 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 -project ${PROJECT} -target "${FRAMEWORK_NAME}" SYMROOT="$SYMROOT" -configuration Release -arch arm64 -arch armv7s only_active_arch=no defines_module=yes -sdk "iphoneos" -verbose
xcodebuild -project ${PROJECT} -target "${FRAMEWORK_NAME}" SYMROOT="$SYMROOT" -configuration Release -arch x86_64 -arch i386 only_active_arch=no defines_module=yes -sdk "iphonesimulator" -verbose
# 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