Skip to content

Instantly share code, notes, and snippets.

@samsymons
Last active Nov 20, 2017
Embed
What would you like to do?
A Swift toolchain build script. Change `SWIFT_SOURCE_PATH` to your Swift source location. Originally from https://gist.github.com/ddunbar/598bf66952fba0e9d8aecc54995f018e
#!/bin/sh
set -e
if [ -z "${CONFIGURATION}" ]; then
CONFIGURATION=debug
fi
if [ -z "${SWIFT_SOURCE_PATH}" ]; then
SWIFT_SOURCE_PATH=~/Code/OSS/Swift
fi
# Create the development toolchain.
rm -rf ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain
mkdir -p ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/bin
if ! /usr/libexec/PlistBuddy -c "Add CFBundleIdentifier string 'swift-dev'" "${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/Info.plist" > /dev/null; then
echo "error: unable to create Info.plist"
exit 1
fi
if ! /usr/libexec/PlistBuddy -c "Add CompatibilityVersion integer 2" "${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/Info.plist" > /dev/null; then
echo "error: unable to create Info.plist"
exit 1
fi
# Install the `swift` provided binaries.
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/ \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swiftc \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift-demangle \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/bin
# Install the `swiftpm` provided binaries.
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swiftpm-macosx-x86_64/${CONFIGURATION}/ \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swiftpm-macosx-x86_64/${CONFIGURATION}/swift-build \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swiftpm-macosx-x86_64/${CONFIGURATION}/swift-package \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swiftpm-macosx-x86_64/${CONFIGURATION}/swift-test \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/bin/
# Install the `llbuild` provided binaries.
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/llbuild-macosx-x86_64/bin/ \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/llbuild-macosx-x86_64/bin/swift-build-tool \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/bin/
# Install fake versions of `lldb` and `lldb-mi`.
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/llbuild-macosx-x86_64/bin/ \
$(which false) \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/bin/lldb
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/llbuild-macosx-x86_64/bin/ \
$(which false) \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/bin/lldb-mi
# Install the `swiftpm` runtime libraries.
mkdir -p ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/pm/
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swiftpm-macosx-x86_64/${CONFIGURATION}/ \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swiftpm-macosx-x86_64/${CONFIGURATION}/libPackageDescription.dylib \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swiftpm-macosx-x86_64/${CONFIGURATION}/PackageDescription.swiftmodule \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/pm/
# Install the `clang` runtime data.
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/llvm-macosx-x86_64/lib/libclang.dylib \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/llvm-macosx-x86_64/lib/libclang.dylib \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/
# Install the standard libraries.
mkdir -p ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/macosx/
rsync -a \
--link-dest ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/macosx/ \
$(ls ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/macosx/*.dylib | \
grep -v SwiftPrivate | \
grep -v StdlibUnittest | \
grep -v SwiftReflectionTest | \
grep -v SwiftExperimental) \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/macosx/
rsync -a \
--link-dest ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/macosx/x86_64/ \
$(ls ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/macosx/x86_64/*.swiftdoc | \
grep -v SwiftPrivate | \
grep -v StdlibUnittest | \
grep -v SwiftReflectionTest | \
grep -v SwiftExperimental) \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/macosx/x86_64/
rsync -a \
--link-dest ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/macosx/x86_64/ \
$(ls ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/macosx/x86_64/*.swiftmodule | \
grep -v SwiftPrivate | \
grep -v StdlibUnittest | \
grep -v SwiftReflectionTest | \
grep -v SwiftExperimental) \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/macosx/x86_64/
rsync -a \
--link-dest ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/macosx/x86_64/ \
$(ls ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/macosx/x86_64/*.apinotesc | \
grep -v SwiftPrivate | \
grep -v StdlibUnittest | \
grep -v SwiftReflectionTest | \
grep -v SwiftExperimental) \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/macosx/x86_64/
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/sourcekitd.framework/ \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/sourcekitd.framework/ \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/sourcekitd.framework/
# Install the `clang` symlink.
rsync -ar \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/clang \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/clang
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/shims/ \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/shims/ \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/shims/
rsync -a \
--link-dest ${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/ \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/lib*Demangle.dylib \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/
# Copy over `swift-stdlib-tool`.
cp $(xcrun --find swift-stdlib-tool) \
${SWIFT_SOURCE_PATH}/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/bin/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment