Skip to content

Instantly share code, notes, and snippets.

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 romainbriche/ea8b9f494850e22214cd4d128c738fe3 to your computer and use it in GitHub Desktop.
Save romainbriche/ea8b9f494850e22214cd4d128c738fe3 to your computer and use it in GitHub Desktop.
# VERSION 1.0.4
# Author: @madhavajay
# This currently works for iOS and watchOS in the Simulator and Devices
# Changes
# Using ${TOOLCHAIN} in two places now
# Added double quotes " around paths
# Fixed watchOS Issues
# Instructions iOS
# 1. Copy this into a new Build Phase Script for your App Target
# 2. Add all the Frameworks you need as Input Files, internal and external
# 3. Reset your iOS and watchOS simulators (seriously)
# Screenshot: http://i.imgur.com/3dTjVcW.png
# Instructions watchOS
# 1. Same as above only you need to add the Build Phase Script and its
# Framework Input Files to both the Watch App and the Watch Extension.
# You can only add the Extension one in Xcode. So Add the Extension one,
# then open the .xcodeproj in a Text Editor and find the Entry you just added.
# Its a lot easier with Git. There will be two, changes, one like this:
#
# 28F65CA91D3FDC7D00043613 /* Fix Xcode 8 Beta 3 */
#
# Under the WatchKit Extension buildPhases, and a second with the actual
# script and inputs.
# 2. Cut and Paste the Line like above, linking the Script from the Extension
# Build Phase to the WatchKit App buildPhases.
# 3. Make a new one for the WatchKit Extension Again, either in Xcode or
# Text Editor.
# 4. Reset your iOS and watchOS simulators (seriously)
# 5. Clean deriveddata, spin around in your chair, build and shazam!
# Whats happening here is the same Copy Swift standard libraries step is performed
# on both the App and the Extension Targets. I was able to get the app running
# with only one of these but i'm skeptical its correct as you can see Xcode
# attempts the Copy Swift standard libraries on both Targets by default so there
# must be a need for it.
# Note, you should use the Beta 3 Toolchain, so make sure $TOOLCHAIN_DIR is resolving to:
# /Applications/{YOUR BETA}.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
# Trouble Shooting
# Check the Build Logs and you should see the New Step you add for each target.
# If its working you can see the files like libswiftCore.dylib appear in the
# Framework folders of your .app and .appex files.
# If its not working, try putting `set` on a new line of your Build Phase Script
# This will echo out all the Environment Variables used below and you can compare them
# with the expected output that Xcode uses in the normal Build Step.
# Be careful the Path Spaces are escaped by using double " around the paths below
# or the build paths for watchOS wont work, because they have spaces in their
# folder names like: APPNAME WatchKit Extension and APPNAME WatchKit App
# Include Frameworks
for i in `seq 1 ${SCRIPT_INPUT_FILE_COUNT}`; do
NUM=`expr $i - 1`
NEXT_FOLDER_ARG=SCRIPT_INPUT_FILE_$NUM
INCLUDE_FRAMEWORK_FOLDER_ARGS="${INCLUDE_FRAMEWORK_FOLDER_ARGS} --scan-folder ${!NEXT_FOLDER_ARG}"
done
# Run the correct tool 🤗
${TOOLCHAIN_DIR}/usr/bin/swift-stdlib-tool \
--copy --verbose --sign ${EXPANDED_CODE_SIGN_IDENTITY} \
--scan-executable "${TARGET_BUILD_DIR}/${EXECUTABLE_PATH}" \
--scan-folder "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" \
--scan-folder "${TARGET_BUILD_DIR}/${PLUGINS_FOLDER_PATH}" \
--platform ${PLATFORM_NAME} \
--toolchain ${TOOLCHAIN_DIR} \
--destination "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" \
--strip-bitcode --resource-destination "${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}" \
--resource-library libswiftRemoteMirror.dylib \
${INCLUDE_FRAMEWORK_FOLDER_ARGS}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment