Skip to content

Instantly share code, notes, and snippets.

@phausler
Last active June 24, 2016 19:34
Show Gist options
  • Save phausler/70c8a6c231fedd8a8008f6a6bbaf48d4 to your computer and use it in GitHub Desktop.
Save phausler/70c8a6c231fedd8a8008f6a6bbaf48d4 to your computer and use it in GitHub Desktop.
Swift Toolchain Build Script
#!/usr/bin/env bash
set -e
# This should live in the same directory that contains the swift repository and other tools.
SRC_DIR=$PWD/swift
RUN_TESTS=
if [[ "$1" == "-t" || "$1" == "--test" ]] ; then
RUN_TESTS="-t"
shift
fi
# reconfigure prevents actual incremental builds, so only use when the cmake files are changed
RECONFIG=
if [[ "$1" == "-r" || "$1" == "--reconfigure" ]] ; then
RECONFIG="--reconfigure"
shift
fi
YEAR=$(date +"%Y")
MONTH=$(date +"%m")
DAY=$(date +"%d")
TOOLCHAIN_VERSION="swift-LOCAL-${YEAR}-${MONTH}-${DAY}-a"
ARCHIVE="${TOOLCHAIN_VERSION}-osx.tar.gz"
SYM_ARCHIVE="${TOOLCHAIN_VERSION}-osx-symbols.tar.gz"
BUNDLE_IDENTIFIER="${BUNDLE_PREFIX}.${YEAR}${MONTH}${DAY}"
DISPLAY_NAME_SHORT="Local Swift Development Snapshot"
DISPLAY_NAME="${DISPLAY_NAME_SHORT} ${YEAR}-${MONTH}-${DAY}"
TOOLCHAIN_NAME="${TOOLCHAIN_VERSION}"
SWIFT_INSTALLABLE_PACKAGE="${SRC_DIR}/${ARCHIVE}"
SWIFT_INSTALL_DIR="${SRC_DIR}/swift-nightly-install"
SWIFT_INSTALL_SYMROOT="${SRC_DIR}/swift-nightly-symroot"
SWIFT_TOOLCHAIN_DIR="/Library/Developer/Toolchains/${TOOLCHAIN_NAME}.xctoolchain"
SYMBOLS_PACKAGE="${SRC_DIR}/${SYM_ARCHIVE}"
TOOLCHAIN_ALIAS="Local"
SWIFT_PACKAGE="custom"
SWIFT_TOOLCHAIN_INFO_PLIST="$SWIFT_TOOLCHAIN_DIR/Info.plist"
TOOLCHAIN_REPORT_URL="https://bugs.swift.org/"
COMPATIBILITY_VERSION=2
COMPATIBILITY_VERSION_DISPLAY_STRING="Xcode 8.0"
TOOLCHAIN_CREATED_DATE="$(date -u +'%a %b %d %T GMT %Y')"
SWIFT_BUILDDIR="./build/$SWIFT_PACKAGE"
./swift/utils/build-script $RUN_TESTS \
--ios --tvos --watchos \
--lldb --llbuild \
--release-debuginfo \
--build-subdir=$SWIFT_PACKAGE \
--assertions \
--no-swift-stdlib-assertions \
-- $RECONFIG \
--skip-build-benchmarks --build-swift-examples=0 \
--skip-test-lldb \
--skip-test-ios-host --skip-test-tvos-host --skip-test-watchos-host \
--lldb-no-debugserver \
--lldb-use-system-debugserver \
--lldb-build-type=Release \
--build-ninja \
--build-swift-static-stdlib \
--compiler-vendor=apple \
--install-swift --install-lldb --install-llbuild --install-swiftpm \
--install-destdir="$SWIFT_INSTALL_DIR" \
--darwin-install-extract-symbols \
--install-symroot="$SWIFT_INSTALL_SYMROOT" \
--install-prefix="$SWIFT_TOOLCHAIN_DIR/usr" \
--swift-enable-ast-verifier=0 \
--swift-install-components="compiler;clang-builtin-headers;stdlib;sdk-overlay;license;sourcekit-xpc-service;swift-remote-mirror-headers" \
--llvm-install-components="libclang;libclang-headers" \
--darwin-toolchain-bundle-identifier=$BUNDLE_IDENTIFIER \
--darwin-toolchain-display-name="$DISPLAY_NAME" \
--darwin-toolchain-display-name-short="$DISPLAY_NAME_SHORT" \
--darwin-toolchain-name=$TOOLCHAIN_NAME \
--darwin-toolchain-version=$TOOLCHAIN_NAME \
--darwin-toolchain-alias=$TOOLCHAIN_ALIAS
# Install phase: this is a brutal and unforgiving install... it will erase data (namely what is in $SWIFT_TOOLCHAIN_DIR)
rm -Rf "$SWIFT_TOOLCHAIN_DIR"
mkdir -p "$SWIFT_TOOLCHAIN_DIR"
rsync -a --stats --progress "$SWIFT_INSTALL_DIR/$SWIFT_TOOLCHAIN_DIR" "$SWIFT_TOOLCHAIN_DIR/.."
rsync -a --stats --progress "$SWIFT_BUILDDIR/swift-macosx-x86_64/bin"* "$SWIFT_TOOLCHAIN_DIR/usr/"
mkdir -p "$SWIFT_TOOLCHAIN_DIR/usr/lib"
# Ensure swift itself is installed if this is an incremental build
rsync -av --stats --progress "$SWIFT_BUILDDIR/swift-macosx-x86_64/lib/swift" "$SWIFT_TOOLCHAIN_DIR/usr/lib/"
rsync -a --stats --progress "$SWIFT_BUILDDIR/swift-macosx-x86_64/lib/sourcekitd.framework" "$SWIFT_TOOLCHAIN_DIR/usr/lib/"
rsync -a --stats --progress "$SWIFT_BUILDDIR/swift-macosx-x86_64/lib/swift_static" "$SWIFT_TOOLCHAIN_DIR/usr/lib/"
rm -f "$SWIFT_TOOLCHAIN_INFO_PLIST"
/usr/libexec/PlistBuddy -c "Add DisplayName string '${DISPLAY_NAME}'" "${SWIFT_TOOLCHAIN_INFO_PLIST}"
/usr/libexec/PlistBuddy -c "Add ShortDisplayName string '${DISPLAY_NAME}'" "${SWIFT_TOOLCHAIN_INFO_PLIST}"
/usr/libexec/PlistBuddy -c "Add CreatedDate date '${TOOLCHAIN_CREATED_DATE}'" "${SWIFT_TOOLCHAIN_INFO_PLIST}"
/usr/libexec/PlistBuddy -c "Add CompatibilityVersion integer ${COMPATIBILITY_VERSION}" "${SWIFT_TOOLCHAIN_INFO_PLIST}"
/usr/libexec/PlistBuddy -c "Add CompatibilityVersionDisplayString string ${COMPATIBILITY_VERSION_DISPLAY_STRING}" "${SWIFT_TOOLCHAIN_INFO_PLIST}"
/usr/libexec/PlistBuddy -c "Add Version string '${TOOLCHAIN_VERSION}'" "${SWIFT_TOOLCHAIN_INFO_PLIST}"
/usr/libexec/PlistBuddy -c "Add CFBundleIdentifier string '${BUNDLE_IDENTIFIER}'" "${SWIFT_TOOLCHAIN_INFO_PLIST}"
/usr/libexec/PlistBuddy -c "Add ReportProblemURL string '${TOOLCHAIN_REPORT_URL}'" "${SWIFT_TOOLCHAIN_INFO_PLIST}"
/usr/libexec/PlistBuddy -c "Add Aliases array" "${SWIFT_TOOLCHAIN_INFO_PLIST}"
/usr/libexec/PlistBuddy -c "Add Aliases:0 string '${TOOLCHAIN_ALIAS}'" "${SWIFT_TOOLCHAIN_INFO_PLIST}"
/usr/libexec/PlistBuddy -c "Add OverrideBuildSettings dict" "${SWIFT_TOOLCHAIN_INFO_PLIST}"
/usr/libexec/PlistBuddy -c "Add OverrideBuildSettings:ENABLE_BITCODE string 'NO'" "${SWIFT_TOOLCHAIN_INFO_PLIST}"
/usr/libexec/PlistBuddy -c "Add OverrideBuildSettings:SWIFT_DISABLE_REQUIRED_ARCLITE string 'YES'" "${SWIFT_TOOLCHAIN_INFO_PLIST}"
/usr/libexec/PlistBuddy -c "Add OverrideBuildSettings:SWIFT_LINK_OBJC_RUNTIME string 'YES'" "${SWIFT_TOOLCHAIN_INFO_PLIST}"
chmod a+r "${SWIFT_TOOLCHAIN_INFO_PLIST}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment