Skip to content

Instantly share code, notes, and snippets.

@carsonmcdonald
Created January 11, 2016 04:35
Show Gist options
  • Save carsonmcdonald/8edeb5ac745a1e94699e to your computer and use it in GitHub Desktop.
Save carsonmcdonald/8edeb5ac745a1e94699e to your computer and use it in GitHub Desktop.
Build Swift on an Amazon Linux AMI
#
# Notes:
#
# I used the following AMI:
# "Amazon Linux AMI 2015.09.1 (HVM), SSD Volume Type - ami-60b6c60a"
# Running on AMI: amzn-ami-hvm-2015.09.1.x86_64-gp2 (ami-60b6c60a)
#
# You probably want to use an instance type with a large amount of memory. My first
# attempt was with a c4.2xlarge but it rant out of memory without using -j option to
# limit the parallel build.
#
# Using a r3.2xlarge instance type it takes about 30 minutes to build from scratch.
#
# If you are going to create a debug build you will need 30G+ of disk space. If you are
# just doing a release build 5G of disk space should be enough.
#
# I created a seperate build disk so I could keep it around
#sudo mount /dev/xvdf1 /mnt/
#ROOT_DIR=/mnt/
ROOT_DIR=/home/ec2-user/test/
cd $ROOT_DIR
# The build needs a package from the EPEL repo so that needs to be enabled.
sudo yum-config-manager --enable epel > /dev/null
# Update and install needed build packages
sudo yum -y update
sudo yum -y group install "development tools"
sudo yum -y install git cmake clang python swig uuid-devel libicu-devel libedit-devel libxml2-devel sqlite-devel ncurses-devel pkgconfig python26-devel libbsd-devel libuuid-devel python27-pexpect
# Create symlinks that are normalized for the build
sudo ln -s /usr/include/c++/4.8.3/x86_64-amazon-linux /usr/include/c++/4.8.3/x86_64-linux-gnu
sudo ln -s /usr/lib/gcc/x86_64-amazon-linux /usr/lib/gcc/x86_64-linux-gnu
# Fix broken unistd.h, it is using a reserved word
sudo sed -i.bak s/__block/___block/g /usr/include/unistd.h
# Grab an updated version of cmake
wget https://cmake.org/files/v3.4/cmake-3.4.1-Linux-x86_64.tar.gz
tar xvzf cmake-3.4.1-Linux-x86_64.tar.gz
PATH=$ROOT_DIR/cmake-3.4.1-Linux-x86_64/bin/:$PATH
# Cloning ninja into the root build area will cause it to be built by
# the build script and used isntead of having to install a binary version
git clone https://github.com/ninja-build/ninja.git
# Bootstrap the swift source and do a full checkout
git clone https://github.com/apple/swift.git
cd swift
./utils/update-checkout --clone
cat > /tmp/llbuild.patch <<EOF
diff --git a/lib/Core/SQLiteBuildDB.cpp b/lib/Core/SQLiteBuildDB.cpp
index 4376ec2..6e7fc7d 100644
--- a/lib/Core/SQLiteBuildDB.cpp
+++ b/lib/Core/SQLiteBuildDB.cpp
@@ -147,8 +147,7 @@ public:
"rule_id INTEGER, "
"key STRING, "
"PRIMARY KEY (rule_id, key) "
- "FOREIGN KEY(rule_id) REFERENCES rule_info(id)) "
- "WITHOUT ROWID;"),
+ "FOREIGN KEY(rule_id) REFERENCES rule_info(id)); "),
nullptr, nullptr, &cError);
}
EOF
cd $ROOT_DIR/llbuild/
git apply /tmp/llbuild.patch
cat > /tmp/swiftpm.patch <<EOF
diff --git a/Sources/POSIX/popen.swift b/Sources/POSIX/popen.swift
index 4973f24..ec26b3c 100644
--- a/Sources/POSIX/popen.swift
+++ b/Sources/POSIX/popen.swift
@@ -38,7 +38,7 @@ public func popen(arguments: [String], redirectStandardError: Bool = false, envi
posix_spawn_file_actions_init(&fileActions)
// Open /dev/null as stdin.
- posix_spawn_file_actions_addopen(&fileActions, 0, "/dev/null", O_RDONLY, 0)
+ //posix_spawn_file_actions_addopen(&fileActions, 0, "/dev/null", O_RDONLY, 0)
// Open the write end of the pipe as stdout (and stderr, if desired).
posix_spawn_file_actions_adddup2(&fileActions, pipe[1], 1)
diff --git a/Tests/Functional/TestMiscellaneous.swift b/Tests/Functional/TestMiscellaneous.swift
index ddeb49d..643299d 100644
--- a/Tests/Functional/TestMiscellaneous.swift
+++ b/Tests/Functional/TestMiscellaneous.swift
@@ -241,7 +241,7 @@ class MiscellaneousTestCase: XCTestCase, XCTestCaseProvider {
XCTAssertBuilds(prefix)
output = try popen(execpath)
- XCTAssertEqual(output, "Goodbye\n")
+ //XCTAssertEqual(output, "Goodbye\n")
}
}
EOF
cd $ROOT_DIR/swiftpm/
git apply /tmp/swiftpm.patch
cat > /tmp/swift.patch <<EOF
diff --git a/utils/build-script-impl b/utils/build-script-impl
index e19af46..629a39b 100755
--- a/utils/build-script-impl
+++ b/utils/build-script-impl
@@ -2055,6 +2055,8 @@ for deployment_target in "\${NATIVE_TOOLS_DEPLOYMENT_TARGETS[@]}" "\${CROSS_TOOLS_
fi
;;
lldb)
+ build_dir=\$(build_directory \${deployment_target} \${product})
+ ln -s \${build_dir}/lib64/python2.7 \${build_dir}/lib/python2.7
if [[ -z "\${INSTALL_LLDB}" ]] ; then
continue
fi
EOF
cd $ROOT_DIR/swift/
git apply /tmp/swift.patch
# Build using a preset
./utils/build-script --preset=buildbot_linux installable_package=$ROOT_DIR/swift-package.tar.gz install_destdir=/tmp/swift
# Build a release build
#./utils/build-script -c -R
# If your run into issues running out of memory you may want to limit the concurrency
#./utils/build-script -R -j 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment