Skip to content

Instantly share code, notes, and snippets.

@ddunbar
Created June 2, 2016 17:35
Show Gist options
  • Save ddunbar/598bf66952fba0e9d8aecc54995f018e to your computer and use it in GitHub Desktop.
Save ddunbar/598bf66952fba0e9d8aecc54995f018e to your computer and use it in GitHub Desktop.
This is the script I currently use on OS X to get a working "swift-dev.xctoolchain" out of a built Swift. It isn't designed to work for anyone but me, but it should be easy to adapt. I always run this after every build, and then use `TOOLCHAINS=swift-dev swift build` (etc) to use the development compiler.
#!/bin/sh
set -e
if [ -z "${CONFIGURATION}" ]; then
CONFIGURATION=debug
fi
# Create the development toolchain.
rm -rf ~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain
mkdir -p ~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/bin
if ! /usr/libexec/PlistBuddy -c "Add CFBundleIdentifier string 'swift-dev'" "${HOME}/public/swift-project/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 1" "${HOME}/public/swift-project/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 ~/public/swift-project/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/ \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swiftc \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift-demangle \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/bin
# Install the `swiftpm` provided binaries.
rsync -ar \
--link-dest ~/public/swift-project/build/Ninja-ReleaseAssert/swiftpm-macosx-x86_64/${CONFIGURATION}/ \
~/public/swift-project/build/Ninja-ReleaseAssert/swiftpm-macosx-x86_64/${CONFIGURATION}/swift-build \
~/public/swift-project/build/Ninja-ReleaseAssert/swiftpm-macosx-x86_64/${CONFIGURATION}/swift-package \
~/public/swift-project/build/Ninja-ReleaseAssert/swiftpm-macosx-x86_64/${CONFIGURATION}/swift-test \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/bin/
# Install the `llbuild` provided binaries.
rsync -ar \
--link-dest ~/public/swift-project/build/Ninja-ReleaseAssert/llbuild-macosx-x86_64/bin/ \
~/public/swift-project/build/Ninja-ReleaseAssert/llbuild-macosx-x86_64/bin/swift-build-tool \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/bin/
# Install fake versions of `lldb` and `lldb-mi`.
rsync -ar \
--link-dest ~/public/swift-project/build/Ninja-ReleaseAssert/llbuild-macosx-x86_64/bin/ \
$(which false) \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/bin/lldb
rsync -ar \
--link-dest ~/public/swift-project/build/Ninja-ReleaseAssert/llbuild-macosx-x86_64/bin/ \
$(which false) \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/bin/lldb-mi
# Install the `swiftpm` runtime libraries.
mkdir -p ~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/pm/
rsync -ar \
--link-dest ~/public/swift-project/build/Ninja-ReleaseAssert/swiftpm-macosx-x86_64/${CONFIGURATION}/ \
~/public/swift-project/build/Ninja-ReleaseAssert/swiftpm-macosx-x86_64/${CONFIGURATION}/libPackageDescription.dylib \
~/public/swift-project/build/Ninja-ReleaseAssert/swiftpm-macosx-x86_64/${CONFIGURATION}/PackageDescription.swiftmodule \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/pm/
# Install the `clang` runtime data.
rsync -ar \
--link-dest ~/public/swift-project/build/Ninja-ReleaseAssert/llvm-macosx-x86_64/lib/libclang.dylib \
~/public/swift-project/build/Ninja-ReleaseAssert/llvm-macosx-x86_64/lib/libclang.dylib \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/
# Install the standard libraries.
mkdir -p ~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/macosx/
rsync -a \
--link-dest ~/public/swift-project/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/macosx/ \
$(ls ~/public/swift-project/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/macosx/*.dylib | \
grep -v SwiftPrivate | \
grep -v StdlibUnittest | \
grep -v SwiftReflectionTest | \
grep -v SwiftExperimental) \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/macosx/
rsync -a \
--link-dest ~/public/swift-project/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/macosx/x86_64/ \
$(ls ~/public/swift-project/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) \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/macosx/x86_64/
rsync -a \
--link-dest ~/public/swift-project/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/macosx/x86_64/ \
$(ls ~/public/swift-project/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) \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/macosx/x86_64/
rsync -a \
--link-dest ~/public/swift-project/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/macosx/x86_64/ \
$(ls ~/public/swift-project/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) \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/macosx/x86_64/
rsync -ar \
--link-dest ~/public/swift-project/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/sourcekitd.framework/ \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/sourcekitd.framework/ \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/sourcekitd.framework/
# Install the `clang` symlink.
rsync -ar \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/clang \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/clang
rsync -ar \
--link-dest ~/public/swift-project/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/shims/ \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift/shims/ \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/swift/shims/
rsync -a \
--link-dest ~/public/swift-project/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/ \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/lib*Demangle.dylib \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/lib/
# Copy over `swift-stdlib-tool`.
cp $(xcrun --find swift-stdlib-tool) \
~/public/swift-project/build/Ninja-ReleaseAssert/swift-dev.xctoolchain/usr/bin/
@SUNNYANANYA
Copy link

Verify Github on Galxe. gid:WM67BBmqZzJbBigsmgsXK

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