{"id":3245,"date":"2016-09-24T14:23:40","date_gmt":"2016-09-24T19:23:40","guid":{"rendered":"http:\/\/dev.iachieved.it\/iachievedit\/?p=3245"},"modified":"2019-01-13T03:24:52","modified_gmt":"2019-01-13T09:24:52","slug":"building-swift-3-0-on-an-armv7-system","status":"publish","type":"post","link":"https:\/\/dev.iachieved.it\/iachievedit\/building-swift-3-0-on-an-armv7-system\/","title":{"rendered":"Building Swift 3.0 on an ARMv7 System"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.shields.io\/badge\/Swift-3.0-orange.svg?style=flat\" alt=\"Swift 3.0\" \/> <img decoding=\"async\" src=\"https:\/\/img.shields.io\/badge\/OS-Linux-blue.svg?style=flat\" alt=\"Swift 3.0\" \/> <img decoding=\"async\" src=\"https:\/\/img.shields.io\/badge\/Arch-ARM-red.svg?style=flat\" alt=\"Swift 3.0\" \/><\/p>\n<p><b>Editor&#8217;s Note:<\/b>  This post supersedes our other posts on building Swift 3.0 for the BeagleBone Black or Raspberry Pi 3 as it utilizes the repository&#8217;s hosted by the <a href=\"https:\/\/github.com\/swift-arm\">Swift ARM<\/a> organization.<\/p>\n<p>To get started with building Swift 3.0 natively on an ARMv7 you&#8217;re going to need:<\/p>\n<ul>\n<li>a suitably powerful ARMv7 system; we have used the <a href=\"http:\/\/dev.iachieved.it\/iachievedit\/a-look-at-the-beagleboard-x15\/\">BeagleBoard X15<\/a> with build times of about 4 hours and <a href=\"https:\/\/www.raspberrypi.org\/products\/raspberry-pi-3-model-b\/\">Raspberry Pi 3<\/a> for initial build times of 6 hours<\/li>\n<li>high-speed IO on either a USB3 flash drive or a UHS-I\/class 10 microSD card with a capacity of <strong>16GB<\/strong> or greater (I like the <a href=\"https:\/\/www.amazon.com\/Patriot-Performance-MicroSDHC-Class-10-Compliant\/dp\/B00KXO0M3I\">Patriot EP Series<\/a> for the price combined with relatively high write speeds)<\/li>\n<li>one of the supported Ubuntu releases such as <a href=\"https:\/\/wiki.ubuntu.com\/XenialXerus\/ReleaseNotes\">Ubuntu Xenial 16.04<\/a><\/li>\n<li>Patience<\/li>\n<\/ul>\n<h2>Install Build Prerequisites<\/h2>\n<p>Compiling Swift requires a number of prerequisites.  Get them in one fell swoop with:<\/p>\n<pre class=\"crayon:false\">\n# sudo apt-get install -y git cmake ninja-build clang uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config autoconf libtool systemtap-sdt-dev libcurl4-openssl-dev\n<\/pre>\n<h2>Add Some Swap<\/h2>\n<p>You will need at a minimum 2G of RAM on an ARMv7 system to build Swift.  If you are working with the Pi3 you will want to add some swap to double up from the base 1G.<\/p>\n<pre class=\"crayon:false\">\n# cd \/var\/cache\n# sudo mkdir swap\n# cd swap\n# sudo fallocate -l 1G 1G.swap\n# sudo mkswap 1G.swap\nSetting up swapspace version 1, size = 1024 MiB (1073737728 bytes)\nno label, UUID=184d002a-2f15-4b23-8360-8e792badc6a2\n# sudo chmod 600 1G.swap\n# sudo swapon 1G.swap\n<\/pre>\n<h2>Using `build-swift`<\/h2>\n<p><code>build-swift<\/code> is our Github repository that has several helper scripts to make life a little easier building Swift on ARM.<\/p>\n<pre class=\"crayon:false\">\n# git clone https:\/\/github.com\/swift-arm\/build-swift\n# cd build-swift\n<\/pre>\n<p>By default <code>build-swift<\/code> will check out to the <code>swift-3.0<\/code> branch.<\/p>\n<p>The contained scripts (located in the <code>scripts<\/code> directory) are pretty simple:<\/p>\n<ul>\n<li><code>get.sh<\/code> &#8211; Downloads all of the required repositories for building Swift; these repositories are from the <a href=\"https:\/\/github.com\/swift-arm\/\">Swift ARM<\/a> organization and have been patched specifically for building ARMv7<\/li>\n<li><code>update.sh<\/code> &#8211; Updates all of your local repositories with the latest on Github<\/li>\n<li><code>package.sh<\/code> &#8211; Runs the Swift <code>build-script<\/code> <\/li>\n<li><code>clean.sh<\/code> &#8211; Deletes the build artifacts<\/li>\n<li><code>distclean.sh<\/code> &#8211; Deletes both the build artifacts and the deletes the repositories<\/li>\n<\/ul>\n<p>I suggest you look at each shell script and walk through the logic before executing.  They are straightforward but it&#8217;s worth the time understanding what they are doing.<\/p>\n<h2>Let&#8217;s Do This<\/h2>\n<p>Remember to make sure you have:<\/p>\n<ul>\n<li>installed all of the prerequisite packages\n<li>have plenty of RAM available on your system (2G minimum)\n<li>cloned `build-swift` from Github\n<\/ul>\n<p>Now, clone all of the required repositories:<\/p>\n<pre class=\"crayon:false\">\n# cd build-swift\n# .\/scripts\/get.sh\n<\/pre>\n<p>On a high-speed SD card this step took about 15 minutes to download and write everything.<\/p>\n<p>Now, compile.  The Swift on ARM team uses <a href=\"https:\/\/jenkins.io\">Jenkins<\/a> to run this in a headless build job, but if you use <code>nohup<\/code> to ensure your compile continues even if the terminal detaches you should be fine:<\/p>\n<pre class=\"crayon:false\">\n# nohup .\/scripts\/package.sh > swiftbuild.log&\n<\/pre>\n<p>To watch the output of the build use <code>tail -F swiftbuild.log<\/code>.<\/p>\n<p>Now, be prepared to wait!  A clean build of Swift on a Raspberry Pi 3 can take upwards of 6 hours.  The reward is well worth it, however, and that is a <code>swift.tar.gz<\/code> bundle that can be installed on <i>either<\/i> a Raspberry Pi 2 or Pi 3 running Ubuntu Xenial (do not try to install this on a Raspbian machine, you will be sorry).  I like to install Swift in <code>\/opt\/swift\/<\/code> like so:<\/p>\n<pre class=\"crayon:false\">\n# cd \/opt\n# mkdir -p swift\/swift-3.0\n# cd swift\/swift-3.0\n# tar -xzvf \/path\/to\/swift.tar.gz\n<\/pre>\n<p>You can then set your <code>PATH<\/code> with <code>export PATH=\/opt\/swift\/swift-3.0\/usr\/bin:$PATH<\/code>.  To properly use <code>swiftc<\/code> and <code>swift build<\/code> you will also need to run the following commands:<\/p>\n<pre class=\"crayon:false\">\nsudo apt-get install -y libicu-dev\nsudo apt-get install -y clang-3.6\nsudo update-alternatives --install \/usr\/bin\/clang clang \/usr\/bin\/clang-3.6 100\nsudo update-alternatives --install \/usr\/bin\/clang++ clang++ \/usr\/bin\/clang++-3.6 100\n<\/pre>\n<h2>Getting Help<\/h2>\n<p>If you are having trouble compiling feel free to join our <a href=\"https:\/\/slackpass.io\/swift-arm\">swift-arm Slack<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Editor&#8217;s Note: This post supersedes our other posts on building Swift 3.0 for the BeagleBone Black or Raspberry Pi 3 as it utilizes the repository&#8217;s hosted by the Swift ARM organization. To get started with building Swift 3.0 natively on an ARMv7 you&#8217;re going to need: a suitably powerful ARMv7 system; we have used the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3108,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-3245","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-swift"],"_links":{"self":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/3245"}],"collection":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/comments?post=3245"}],"version-history":[{"count":5,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/3245\/revisions"}],"predecessor-version":[{"id":3648,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/3245\/revisions\/3648"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/media\/3108"}],"wp:attachment":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/media?parent=3245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/categories?post=3245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/tags?post=3245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}