{"id":2197,"date":"2015-12-22T11:21:00","date_gmt":"2015-12-22T17:21:00","guid":{"rendered":"http:\/\/dev.iachieved.it\/iachievedit\/?p=2197"},"modified":"2016-06-18T08:06:19","modified_gmt":"2016-06-18T14:06:19","slug":"debian-packages-for-swift-on-arm","status":"publish","type":"post","link":"https:\/\/dev.iachieved.it\/iachievedit\/debian-packages-for-swift-on-arm\/","title":{"rendered":"Debian Packages for Swift on ARM"},"content":{"rendered":"<p><b>June 18, 2016 Update!<\/b>  If you&#8217;re looking for Swift 3.0 on Raspberry Pi 2 or 3, come see <a href=\"http:\/\/dev.iachieved.it\/iachievedit\/swift-3-0-on-raspberry-pi-2-and-3\/\">this post<\/a>.<\/p>\n<p><b><font color=\"red\">Disclaimer!<\/font><\/b>  Swift on ARM systems is very much at an <b>alpha<\/b> stage at the moment!  The package below does not contain a working<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/apple\/swift-package-manager\">Swift package manager<\/a>\n<li><strike><a href=\"https:\/\/github.com\/apple\/swift-corelibs-foundation\">Foundation<\/a> implementation<\/strike>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Read%E2%80%93eval%E2%80%93print_loop\"><strike>REPL<\/strike><\/a>\n<\/ul>\n<p><b>12\/27\/15 Update:<\/b>  The REPL is now somewhat functional on BeagleBone and BeagleBoard.  Occasionally you may see <code>Execution interrupted. Enter code to recover and continue.<\/code><br \/>\n<b>1\/4\/16 Update:<\/b>  Foundation is now working!<\/p>\n<p>You can track the progress of the port of Swift to ARM platforms at <a href=\"https:\/\/bugs.swift.org\">bugs.swift.org<\/a>, and follow @iachievedit on Twitter for updates when new packages are released.  To help out, create an account at <code>bugs.swift.org<\/code> and when you find broken stuff, file bugs and tag them with &#8216;arm&#8217;.  This tagging process helps those working on ARM support <a href=\"https:\/\/bugs.swift.org\/issues\/?filter=10311\">track all of the open issues in JIRA<\/a>.<\/p>\n<h3>Background<\/h3>\n<p>A number of folks have been working hard to get a port of Open Source Swift working on ARM-based platforms such as the RaspberryPi, BeagleBone, etc.  A port request, <a href=\"https:\/\/bugs.swift.org\/browse\/SR-40\">SR-40<\/a> was opened in JIRA and from there several forks of the main Swift repository were created to start the work.  William Dillon <a href=\"http:\/\/www.housedillon.com\/?p=2287\">succeeded<\/a> in getting a basic port to work, which was no small feat.  This work has been a collaboration among a number of users on Github including <a href=\"https:\/\/github.com\/hpux735\">hpux735<\/a>, <a href=\"https:\/\/github.com\/tienex\">tienex<\/a>, and others.<\/p>\n<h3>Prerequisites<\/h3>\n<p>The <code>clang-3.6<\/code> and <code>libicu-dev<\/code> packages need to be installed.  In addition, you should use <code>update-alternatives<\/code> to provide <code>\/usr\/bin<\/code> links for <code>clang<\/code> and <code>clang++<\/code>.<\/p>\n<pre class=\"crayon:false\">\nsudo apt-get install libicu-dev\nsudo apt-get install 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<p><b>Editor&#8217;s Note:<\/b>  Jump down to the bottom if for whatever reason you absolutely cannot find <code>clang-3.6<\/code> for your system.<\/p>\n<h3>Installation<\/h3>\n<p>At the moment there are packages for Ubuntu 14.04 (Trusty) and Debian 8.2 (Jessie).  These have been tested on the BeagleBoard X15, BeagleBone Black, and Wandboard.<\/p>\n<p><b>1.  Add the repository key<\/b><\/p>\n<pre class=\"crayon:false\">\nwget -qO- http:\/\/dev.iachieved.it\/iachievedit.gpg.key | sudo apt-key add -\n<\/pre>\n<p><b>2.  Add the appropriate repository to <code>sources.list<\/code><\/b><\/p>\n<p><b>Ubuntu 14.04 (Trusty)<\/b><\/p>\n<pre class=\"crayon:false\">\necho \"deb [arch=armhf] http:\/\/iachievedit-repos.s3.amazonaws.com\/ trusty main\" | sudo tee --append \/etc\/apt\/sources.list\n<\/pre>\n<p><b>Debian 8.2 (Jessie)<\/b><\/p>\n<pre class=\"crayon:false\">\necho \"deb [arch=armhf] http:\/\/iachievedit-repos.s3.amazonaws.com\/ jessie main\" | sudo tee --append \/etc\/apt\/sources.list\n<\/pre>\n<p><b>3.  Run <code>apt-get update<\/code><\/b><\/p>\n<pre class=\"crayon:false\">\nsudo apt-get update\n<\/pre>\n<p><b>4.  Install swift-2.2!<\/b><\/p>\n<pre class=\"crayon:false\">\napt-get install swift-2.2\n<\/pre>\n<h3>Trying it Out<\/h3>\n<p>Again, a warning!  There is no Swift package manager in this build yet.  You can however compile basic applications, including those requiring <code>Glibc<\/code> and <code>Foundation<\/code>.<\/p>\n<pre class=\"crayon:false\">\nroot@beaglebone:~# more helloWorld.swift \nprint(\"Hello, world!\")\n\nfor i in 1...10 {\n  print(i)\n}\nroot@beaglebone:~# swiftc helloWorld.swift \nroot@beaglebone:~# .\/helloWorld \nHello, world!\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n<\/pre>\n<p>or, try out <code>swiftcat.swift<\/code> which uses <code>Glibc<\/code>.<\/p>\n<pre class=\"lang:swift\">\nimport Glibc\n\nguard Process.arguments.count == 2 else {\n  print(\"Usage:  swiftcat FILENAME\")\n  exit(-1)\n}\n\nlet filename = Process.arguments[1]\n\nlet BUFSIZE = 1024\nvar pp      = popen(\"cat \" + filename, \"r\")\nvar buf     = [CChar](count:BUFSIZE, repeatedValue:CChar(0))\n\nwhile fgets(&buf, Int32(BUFSIZE), pp) != nil {\n  print(String.fromCString(buf)!, terminator:\"\")\n}\n\nexit(0)\n<\/pre>\n<p>With the latest <code>0ubuntu11<\/code> release, <code>Foundation<\/code> is supported too!<br \/>\n<code>countdown.swift<\/code><\/p>\n<pre class=\"lang:swift\">         \nimport Foundation        \nimport Glibc         \nlet thread = NSThread(){         \n  print(\"Entering thread\")       \n  for i in (1...10).reverse() {      \n   print(\"\\(i)...\", terminator:\"\")       \n   fflush(stdout)        \n   sleep(1)      \n  }      \n  print(\"\\nExiting thread\")          \n  print(\"Done\")      \n  exit(0)        \n}        \nthread.start()       \nselect(0, nil, nil, nil, nil)        \n<\/pre>\n<h3>Stay Tuned!<\/h3>\n<p>Folks are working hard to bring Swift to our favorite ARM platforms.  Updates will be posted to this article as well as to our @iachievedit Twitter account.<\/p>\n<h3>For those using Raspbian<\/h3>\n<p><b>Editor&#8217;s Note:<\/b>  This has been tested on at least one Raspberry Pi 3.  YMMV.<\/p>\n<p>For some reason <code>clang-3.6<\/code> isn&#8217;t readily available on Raspbian systems.  If you find yourself in the situation of having clang-3.7 or later and want to use the <code>swift-2.2<\/code> package, you can use these steps.  Yes, this is a bit of trickery.<\/p>\n<p>Before starting, go ahead and install <code>clang-3.7<\/code> (or whichever clang version you are using), as well as <code>libicu-dev<\/code>:  <code>sudo apt-get install clang-3.7 libicu-dev<\/code>.<\/p>\n<p>Then,<\/p>\n<ol>\n<li>Add the iAchieved.it LLC repository key (step #1 above)<\/li>\n<li>Add the Jessie repository.<\/li>\n<\/ol>\n<pre class=\"crayon:false\">\necho \"deb [arch=armhf] http:\/\/iachievedit-repos.s3.amazonaws.com\/ jessie main\" | sudo tee --append \/etc\/apt\/sources.list\n<\/pre>\n<ol>\n<li>Download the <code>.deb<\/code> file with <code>aptitude download swift-2.2<\/code>.  The downloaded file will include something like <code>1%3a2.2-0ubuntu11_armhf<\/code> in it. <\/li>\n<li>Perform the following steps (from <a href=\"http:\/\/serverfault.com\/a\/383958\">Serverfault<\/a>):<\/li>\n<\/ol>\n<pre class=\"crayon:false\">\n$ ar x swift-2.2_1%3a2.2-0ubuntu11_armhf.deb\n$ tar xzf control.tar.gz\n# Edit control in a text editor and replace clang-3.6 with clang-3.7\n$ tar c control | gzip -c > control.tar.gz\n$ ar rcs swift-2.2-new.deb debian-binary control.tar.gz data.tar.xz # Note the order is important\n<\/pre>\n<p>Then, install the new package file:  <code>sudo dpkg -i swift-2.2-new.deb<\/code>.  Good luck!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>June 18, 2016 Update! If you&#8217;re looking for Swift 3.0 on Raspberry Pi 2 or 3, come see this post. Disclaimer! Swift on ARM systems is very much at an alpha stage at the moment! The package below does not contain a working Swift package manager Foundation implementation REPL 12\/27\/15 Update: The REPL is now [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2877,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,5],"tags":[35],"class_list":["post-2197","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-swift","tag-rapsberry-pi-3"],"_links":{"self":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/2197"}],"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=2197"}],"version-history":[{"count":27,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/2197\/revisions"}],"predecessor-version":[{"id":3049,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/2197\/revisions\/3049"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/media\/2877"}],"wp:attachment":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/media?parent=2197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/categories?post=2197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/tags?post=2197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}