Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create Swift toolchain from Ninja build artifacts
#!/bin/sh
set -e
if [ -z "${CONFIGURATION}" ]; then
CONFIGURATION=release
fi
if [ -z "${SWIFT_SOURCE_PATH}" ]; then
SWIFT_SOURCE_PATH="${HOME}/dev/oss/swift-sources"
fi
if [ -z "${BUILD_DIR}" ]; then
BUILD_DIR="Ninja-ReleaseAssert"
fi
# Create the development toolchain.
rm -rf ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain
mkdir -p ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain/usr/bin
if ! /usr/libexec/PlistBuddy -c "Add CFBundleIdentifier string 'swift-dev'" "${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/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/${BUILD_DIR}/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/${BUILD_DIR}/swift-macosx-x86_64/bin/ \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-macosx-x86_64/bin/swift \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-macosx-x86_64/bin/swiftc \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-macosx-x86_64/bin/swift-demangle \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain/usr/bin
# Install the `swiftpm` provided binaries.
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swiftpm-macosx-x86_64/${CONFIGURATION}/ \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swiftpm-macosx-x86_64/${CONFIGURATION}/swift-build \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swiftpm-macosx-x86_64/${CONFIGURATION}/swift-package \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swiftpm-macosx-x86_64/${CONFIGURATION}/swift-test \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain/usr/bin/
# Install the `llbuild` provided binaries.
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/llbuild-macosx-x86_64/bin/ \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/llbuild-macosx-x86_64/bin/swift-build-tool \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain/usr/bin/
# Install fake versions of `lldb` and `lldb-mi`.
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/llbuild-macosx-x86_64/bin/ \
$(which false) \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain/usr/bin/lldb
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/llbuild-macosx-x86_64/bin/ \
$(which false) \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain/usr/bin/lldb-mi
# Install the `swiftpm` runtime libraries.
mkdir -p ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain/usr/lib/swift/pm/
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swiftpm-macosx-x86_64/${CONFIGURATION}/ \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain/usr/lib/swift/pm/
# Install the `clang` runtime data.
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/llvm-macosx-x86_64/lib/libclang.dylib \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/llvm-macosx-x86_64/lib/libclang.dylib \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain/usr/lib/
# Install the standard libraries.
mkdir -p ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain/usr/lib/swift/macosx/
rsync -a \
--link-dest ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-macosx-x86_64/lib/swift/macosx/ \
$(ls ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-macosx-x86_64/lib/swift/macosx/*.dylib | \
grep -v SwiftPrivate | \
grep -v StdlibUnittest | \
grep -v SwiftReflectionTest | \
grep -v SwiftExperimental) \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain/usr/lib/swift/macosx/
rsync -a \
--link-dest ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-macosx-x86_64/lib/swift/macosx/x86_64/ \
$(ls ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/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/${BUILD_DIR}/swift-dev.xctoolchain/usr/lib/swift/macosx/x86_64/
rsync -a \
--link-dest ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-macosx-x86_64/lib/swift/macosx/x86_64/ \
$(ls ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/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/${BUILD_DIR}/swift-dev.xctoolchain/usr/lib/swift/macosx/x86_64/
rsync -a \
--link-dest ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-macosx-x86_64/lib/swift/macosx/x86_64/ \
$(ls ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/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/${BUILD_DIR}/swift-dev.xctoolchain/usr/lib/swift/macosx/x86_64/
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-macosx-x86_64/lib/sourcekitd.framework/ \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-macosx-x86_64/lib/sourcekitd.framework/ \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain/usr/lib/sourcekitd.framework/
# Install the `clang` symlink.
rsync -ar \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-macosx-x86_64/lib/swift/clang \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain/usr/lib/swift/clang
rsync -ar \
--link-dest ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-macosx-x86_64/lib/swift/shims/ \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-macosx-x86_64/lib/swift/shims/ \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain/usr/lib/swift/shims/
rsync -a \
--link-dest ${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-macosx-x86_64/lib/ \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-macosx-x86_64/lib/lib*Demangle.dylib \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain/usr/lib/
# Copy over `swift-stdlib-tool`.
cp $(xcrun --find swift-stdlib-tool) \
${SWIFT_SOURCE_PATH}/build/${BUILD_DIR}/swift-dev.xctoolchain/usr/bin/
@mgrebenets

This comment has been minimized.

Copy link
Owner Author

mgrebenets commented Feb 9, 2019

Based on https://gist.github.com/samsymons/a026756ff7afc3154d4649bc955d08ab, this version of the scripts allows to customize build directory name.

I've also removed 2 lines for Swift package manager dylib and Swift module which were missing in my build folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.