Building Swift 5.1 - levivic/zEcoTest GitHub Wiki

Building Swift 5.1

The instructions provided below specify the steps to build Swift v5.1 on Linux on IBM Z for

  • Ubuntu (18.04)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.
  • The directories /<source_root>/, /<install_dir>/ will be referred to in these instructions, and these are temporary writable directories anywhere you'd like to place them.

Step 1. Build using script

If you want to build using manual steps, go to STEP 2.

Use the following commands to build Swift 5.1 using the build script. Please make sure you have wget installed.

wget https://github.com/linux-on-ibm-z/scripts/blob/master/Swift/build_swift_51.sh

# Configure Git User Name and Email
export GIT_USER_NAME = <your_git_user_name>
export GIT_USER_EMAIL = <your_git_user_email>

# Build Swift
bash build_swift_51.sh [Provide -t option for executing build with tests]

Step 2. Install the dependencies

  • Ubuntu (18.04)
sudo apt-get update
sudo apt-get install -y git autoconf libtool git cmake ninja-build python \
        python-dev python3-dev uuid-dev libicu-dev \
        icu-devtools libbsd-dev libedit-dev libxml2-dev \
        libsqlite3-dev swig libpython-dev libncurses5-dev \
        pkg-config libcurl4-openssl-dev systemtap-sdt-dev tzdata clang

Step 3. Obtain the source code and apply patches

3.1 Obtain the source code

export SOURCE_ROOT=/<source_root>/
export INSTALL_DIR=/<install_dir>/
mkdir -p $SOURCE_ROOT
cd $SOURCE_ROOT
git clone https://github.com/apple/swift.git
cd swift
git checkout swift-5.1-branch
./utils/update-checkout --clone --scheme swift-5.1-branch

3.2 Apply patches to Swift

You need to configure your git username and email address before picking up any patches.

git config --global user.email "<your_git_user_email>"
git config --global user.name "<your_git_user_name>"
git fetch
git cherry-pick cacf9c72b6f5ca7249dcf4b1cb81de6d8b120acb
git cherry-pick 04976e1a75d37592d6d6d688de07a210d0c046ef
git cherry-pick 6bb79cafd9e4de34ffc4b2c798960466cf3da70f
git cherry-pick 25a075cbb6abba3d71d833abe704bc13f12350a2
git cherry-pick d3262ec10d7e41b9403f83f2f89474795f9eed3a
git cherry-pick 253d5b5d18c9be2eae2b94be60976ab91f3e4ef6
git cherry-pick a06abbb3b5f3b6cae3ec5dfefe883dbfb6993118
git cherry-pick 931eccb34d34548c8d3e86bf08b471185988fe8b
git cherry-pick e08359c2013a154e1bc740e1984a1c3b645cd7fe
git cherry-pick ce3aff12da2821314b6555c6ff98de4abeaa5cdc
git cherry-pick 2f8b5ac9e2f4395f2633b0dfe03b7d6fd1685b7d
git cherry-pick 6ab83122acf6cc8f98e24a3d47e62483d63c4df9
git cherry-pick 71fa7ece3fcfe4900f5a75b775efe2a7e94663db
git cherry-pick 43bfbd5f38bbc72a4d79f103c962f4a9e9adefff
git cherry-pick 8b3c1a459b13a27f63e7a967f6071d146606d4bc
git cherry-pick bb2740e540a4679c26d80d9e58d29ef50a38349f
git cherry-pick 192bcb2007b89bc941d7ea6f348301f3ecf5ee86
git cherry-pick eb1c203cbf0a306cf084579f090b1ea6ebd55125
git cherry-pick 6ac15e93482ccd988b2bbc7d3d50a72899c62ed7
git cherry-pick 81ece42b1847d6cb647fd8f21910d0f0aa71df42
git remote add loz https://github.com/linux-on-ibm-z/swift.git
git fetch loz
git cherry-pick cbf68876f51fa804fd538b4f2ad0b2f70c893a57

3.3 Apply patches to Swift Foundation

cd ../swift-corelibs-foundation/
git remote add loz https://github.com/linux-on-ibm-z/swift-corelibs-foundation.git
git fetch loz
git cherry-pick 68412be28a843e37e0be2557669d13024443d718

3.4 Apply patches to Swift LLDB

cd ../lldb
git fetch
git cherry-pick 852d35a9c161fd44222b14ebe10fb06529c96817

3.5 Apply patches to Swift Package Manager

cd ../swiftpm
git fetch
git cherry-pick b8768525da66690622b37ce8ebc034945604154e

Step 4. Build Swift 5.1 and its components

cd $SOURCE_ROOT
env LD_LIBRARY_PATH=$SOURCE_ROOT/build/buildbot_linux/swift-linux-s390x/lib/swift/linux/s390x/:$SOURCE_ROOT/build/buildbot_linux/swift-linux-s390x/libdispatch-prefix/lib/ $SOURCE_ROOT/swift/utils/build-script --preset=buildbot_linux,no_test install_destdir=$INSTALL_DIR installable_package=$INSTALL_DIR/install.tar.gz

Step 5. Run tests for Swift, Swift Foundation and Swift Package Manager (Optional)

cd $SOURCE_ROOT
cp -r ./build/buildbot_linux/swift-linux-s390x/lib/swift/linux/s390x/* build/buildbot_linux/swift-linux-s390x/lib/swift/linux/
cp -r ./build/buildbot_linux/swift-linux-s390x/libdispatch-prefix/lib/* build/buildbot_linux/swift-linux-s390x/lib/swift/linux/
env LD_LIBRARY_PATH=$INSTALL_DIR/usr/lib/swift/linux $SOURCE_ROOT/swift/utils/build-script --assertions --no-swift-stdlib-assertions --swift-enable-ast-verifier=0 '--swift-install-components=autolink-driver;compiler;clang-resource-dir-symlink;stdlib;swift-remote-mirror;sdk-overlay;parser-lib;toolchain-tools;license;sourcekit-inproc' '--llvm-install-components=llvm-cov;llvm-profdata;IndexStore;clang;clang-headers;compiler-rt;clangd' --llbuild --swiftpm --xctest --libicu --libcxx --build-ninja --install-swift --install-lldb --install-llbuild --install-swiftpm --install-xctest --install-libicu --install-prefix=/usr --install-libcxx --install-sourcekit-lsp --build-swift-static-stdlib --build-swift-static-sdk-overlay --build-swift-stdlib-unittest-extra --test-installable-package --install-destdir=/home/ubuntu/swift-5.1/swift-install --installable-package=/home/ubuntu/swift-5.1/swift-install/install.tar.gz --build-subdir=buildbot_linux --lldb --release --test --validation-test --long-test --stress-test --test-optimized --foundation --libdispatch --indexstore-db --sourcekit-lsp '--lit-args=-v --time-tests' --lldb-test-swift-only --install-foundation --install-libdispatch --reconfigure --skip-test-cmark --skip-test-lldb --skip-test-llbuild --skip-test-xctest --skip-test-libdispatch --skip-test-playgroundsupport --skip-test-libicu --skip-test-indexstore-db --skip-test-sourcekit-lsp

Step 6. Verify installation

$INSTALL_DIR/usr/bin/swift --version

You should see the following output:

Swift version 5.1-dev (LLVM <***>, Swift <***>)
Target: s390x-ibm-linux
⚠️ **GitHub.com Fallback** ⚠️