Skip to content

Instantly share code, notes, and snippets.

@MarioIannotta
Last active October 26, 2022 15:35
Show Gist options
  • Save MarioIannotta/0603fe1830bb426bdc6b936f73c6241e to your computer and use it in GitHub Desktop.
Save MarioIannotta/0603fe1830bb426bdc6b936f73c6241e to your computer and use it in GitHub Desktop.
#!/bin/sh
# https://gist.github.com/MarioIannotta/e27ac3ec067dc5b6f00c392d7527b10a
build_path="Builds/$(date '+%d-%m-%Y-%H-%M')"
target="YourFramework"
configuration="Your configuration eg: Release"
# clean up the build folder if already exists
rm -rf build_path
devices_base_path="${build_path}/${configuration}-iphoneos"
simulator_base_path="${build_path}/${configuration}-iphonesimulator"
universal_base_path="${build_path}/${configuration}-universal"
devices_framework_path="${devices_base_path}/${target}.framework"
simulator_framework_path="${simulator_base_path}/${target}.framework"
universal_framework_path="${universal_base_path}/${target}.framework"
mkdir -p "${build_path}"
mkdir -p "${universal_framework_path}"
echo "1/3 Building the target \"${target}\" with the configuration \"${configuration}\" for the simulator"
xcodebuild ENABLE_BITCODE=YES BITCODE_GENERATION_MODE=bitcode BUILD_DIR=${build_path} SWIFT_ENABLE_BATCH_MODE=NO > /dev/null -target ${target} -configuration ${configuration} -sdk iphonesimulator clean build
echo "2/3 Building the target \"${target}\" with the configuration \"${configuration}\" for the devices"
xcodebuild ENABLE_BITCODE=YES BITCODE_GENERATION_MODE=bitcode BUILD_DIR=${build_path} SWIFT_ENABLE_BATCH_MODE=NO > /dev/null -target ${target} -configuration ${configuration} -sdk iphoneos clean build ONLY_ACTIVE_ARCH=NO
cp -R "${build_path}/${configuration}-iphoneos/" "${universal_base_path}/"
simulator_module_dir="${simulator_framework_path}/Modules/${target}.swiftmodule/."
if [ -d "${simulator_module_dir}" ]; then
cp -R "${simulator_module_dir}" "${universal_framework_path}/Modules/${target}.swiftmodule"
fi
echo "3/3 Creating FAT framework in ${universal_base_path}"
lipo -create -output "${universal_framework_path}/${target}" "${simulator_framework_path}/${target}" "${devices_framework_path}/${target}"
cp -R "${universal_framework_path}" "${build_path}"
rm -rf "build"
rm -rf "${devices_base_path}"
rm -rf "${simulator_base_path}"
rm -rf "${universal_base_path}"
lipo -info "${build_path}/${target}.framework/${target}"
open "${build_path}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment