Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save banjun/166045c994d07b9e67df9357ff6418f3 to your computer and use it in GitHub Desktop.
Save banjun/166045c994d07b9e67df9357ff6418f3 to your computer and use it in GitHub Desktop.
Generate Swift CLI executable from Xcode target, with CocoaPods Frameworks and Swift stdlibs, without statically linked with the stdlibs
FRAMEWORK_ARG=$(for f in $(echo "${FRAMEWORK_SEARCH_PATHS}"); do echo -n "-F$f "; done)
RUNPATH_ARG=$(for p in $(echo $LD_RUNPATH_SEARCH_PATHS); do echo -n "-Xlinker -rpath -Xlinker $p "; done)
LD="${DT_TOOLCHAIN_DIR}/usr/bin/clang -arch ${arch} -isysroot ${SDKROOT} -L${CONFIGURATION_BUILD_DIR} ${FRAMEWORK_ARG} -filelist ${LINK_FILE_LIST_normal_x86_64} -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET} ${RUNPATH_ARG} -fobjc-link-runtime -L${DT_TOOLCHAIN_DIR}/usr/lib/swift/macosx -lc++ -framework Foundation -Xlinker -add_ast_path -Xlinker ${OBJECT_FILE_DIR_normal}/${arch}/${EXECUTABLE_NAME}.swiftmodule -Xlinker -dependency_info -Xlinker ${LD_DEPENDENCY_INFO_FILE} -o ${CONFIGURATION_BUILD_DIR}/${EXECUTABLE_NAME}"
echo "$LD"
zsh -c "$LD"
mkdir -p "${CONFIGURATION_BUILD_DIR}/Frameworks"
for f in ${CONFIGURATION_BUILD_DIR}/*/*.framework; do
cp -r "$f" "${CONFIGURATION_BUILD_DIR}/Frameworks/"
done
xcrun swift-stdlib-tool --copy --platform macosx --scan-folder ${CONFIGURATION_BUILD_DIR} --destination ${CONFIGURATION_BUILD_DIR}/Frameworks/
@banjun
Copy link
Author

banjun commented Dec 13, 2016

alternative for LD: SWIFT_FORCE_DYNAMIC_LINK_STDLIB = YES

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment