Skip to content

Instantly share code, notes, and snippets.

@rajagp
Created September 28, 2016 01:50
Show Gist options
  • Save rajagp/3309edf21b2751637e7f89c260e8a7fb to your computer and use it in GitHub Desktop.
Save rajagp/3309edf21b2751637e7f89c260e8a7fb to your computer and use it in GitHub Desktop.
iOS Run Script to Generate Aggregate multi-platform Framework (swift)
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: I am NOT the root invocation, so I'm NOT going to recurse"
else
# CRITICAL:
# Prevent infinite recursion by setting flag
export ALREADYINVOKED="true"
# Step 1. Build Device and Simulator versions
echo "xcodebuild -configuration \"${CONFIGURATION}\" -project \"${PROJECT_DIR}/${PROJECT_NAME}.xcodeproj\" -scheme \"${TARGET_NAME}\" -sdk \"iphoneos\" ${ACTION} RUN_CLANG_STATIC_ANALYZER=NO" BUILD_DIR=\"${BUILD_DIR}\" BUILD_ROOT=\"${BUILD_ROOT}\" SYMROOT=\"${SYMROOT}\"
xcodebuild ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -project "${PROJECT_DIR}/${PROJECT_NAME}.xcodeproj" -scheme "${TARGET_NAME}" -sdk iphoneos -destination generic/platform=iOS BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
# If you want to build workspace ....
#xcodebuild ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -workspace "${PROJECT_DIR}/${PROJECT_NAME}.xcworkspace" -scheme "${TARGET_NAME}" -sdk "${SDK_TO_BUILD}" BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
echo "xcodebuild -configuration \"${CONFIGURATION}\" -project \"${PROJECT_DIR}/${PROJECT_NAME}.xcodeproj\" -scheme \"${TARGET_NAME}\" -sdk \"iphonesimulator\" ${ACTION} RUN_CLANG_STATIC_ANALYZER=NO" BUILD_DIR=\"${BUILD_DIR}\" BUILD_ROOT=\"${BUILD_ROOT}\" SYMROOT=\"${SYMROOT}\
xcodebuild ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -project "${PROJECT_DIR}/${PROJECT_NAME}.xcodeproj" -scheme "${TARGET_NAME}" -sdk iphonesimulator BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" -destination 'platform=iOS Simulator,name=iPhone 6s Plus' clean build
# Step 2. Copy the framework structure to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
# Step 3: copy swift module mappings
cp -r "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/"
cp -r "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_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}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment