Skip to content

Instantly share code, notes, and snippets.

@Mazyod
Last active October 10, 2018 11:15
Show Gist options
  • Save Mazyod/d94a9a38fe4b73330f557395017669fa to your computer and use it in GitHub Desktop.
Save Mazyod/d94a9a38fe4b73330f557395017669fa to your computer and use it in GitHub Desktop.
Build a universal iOS framework/library
#!/bin/bash
set -e
# required arguments:
# WORKSPACE_DIR=Networking.xcworkspace
# SCHEME_NAME=Networking
# PRODUCT_NAME=Networking
CONFIGURATION=Release
BUILD_DIR="$(pwd)/Build/${PRODUCT_NAME}"
BUILD_ROOT="${BUILD_DIR}"
UNIVERSAL_OUTPUTFOLDER="${BUILD_DIR}/${CONFIGURATION}-Universal"
rm -Rf "$BUILD_ROOT"
xcodebuild \
-workspace "${WORKSPACE_DIR}" \
-scheme "${SCHEME_NAME}" \
-configuration "${CONFIGURATION}" \
-sdk iphoneos \
BUILD_DIR="${BUILD_DIR}" \
BUILD_ROOT="${BUILD_ROOT}" \
clean build
xcodebuild \
-workspace "${WORKSPACE_DIR}" \
-scheme "${SCHEME_NAME}" \
-configuration "${CONFIGURATION}" \
-sdk iphonesimulator \
BUILD_DIR="${BUILD_DIR}" \
BUILD_ROOT="${BUILD_ROOT}" \
clean build
# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
cp -R \
"${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PRODUCT_NAME}.framework" \
"${UNIVERSAL_OUTPUTFOLDER}/${PRODUCT_NAME}.framework"
# Step 3. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
cp -R \
"${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PRODUCT_NAME}.framework/Modules/${PRODUCT_NAME}.swiftmodule/." \
"${UNIVERSAL_OUTPUTFOLDER}/${PRODUCT_NAME}.framework/Modules/${PRODUCT_NAME}.swiftmodule"
# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create \
-output "${UNIVERSAL_OUTPUTFOLDER}/${PRODUCT_NAME}.framework/${PRODUCT_NAME}" \
"${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PRODUCT_NAME}.framework/${PRODUCT_NAME}" \
"${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PRODUCT_NAME}.framework/${PRODUCT_NAME}"
open "${UNIVERSAL_OUTPUTFOLDER}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment