APT Repositories for Swift 3.0

swift-og

Swift 3.0

Swift 3.0

Swift 2.2 has branched off of master onto a swift-2.2 branch. At that point the master branch of the Swift repositories became the development branch for version 3.0 of the language. The instructions for cloning all of the source code required for a complete Swift build has changed for 3.0. Rather than cloning each repository one at a time you can:

# mkdir swift-build
# cd swift-build
# git clone https://github.com/apple/swift.git 
# ./swift/utils/update-checkout --clone

The update-checkout script in the swift repository is capable of cloning all of the repositories required for a build and placing them into a .tar.gz archive file.

We use the “build and package” preset to not only build all of the required targets, but to package them nicely into a .tar.gz archive file. This is accomplished through a script (available in our package-swift repo) called package.sh:

The key thing in this script is detecting the Ubuntu release (lsb_release -rs) and using the buildbot_linux_${LSB_RELEASE} preset to build and package everything to the ${PACKAGE} .tar.gz file.

apt-get

Downloading a .tar.gz from Apple is nice. Using apt-get on an Ubuntu distribution is even better. To make it is easy to get started with Swift on Linux, we’ve provided an Ubuntu repository that you can obtain the latest Swift packages from.

At the moment we’re providing both swift-3.0 and swift-2.2 packages, and they should not be considered compatible. As of April 25, 2016, we’ve moved the installation of the Swift 3.0 binary from /usr/bin/ into /opt/swift/swift-3.0, so you will need to update your path after installing the 3.0 package. Editor’s note: For the rationale behind moving from of /usr/bin/ to /opt/swift, see this thread on the swift-dev mailing list.

With the restrictions and limitations out of the way, let’s get on with looking at how to get Swift 3.0!

1. Add the repository key

wget -qO- http://dev.iachieved.it/iachievedit.gpg.key | sudo apt-key add -

2. Add the appropriate repository to sources.list

Ubuntu 14.04 (Trusty Tahr)

echo "deb http://iachievedit-repos.s3.amazonaws.com/ trusty main" | sudo tee --append /etc/apt/sources.list

Ubuntu 15.10 (Wily Werewolf)

echo "deb http://iachievedit-repos.s3.amazonaws.com/ wily main" | sudo tee --append /etc/apt/sources.list

Ubuntu 16.04 (Xenial Xerus)

echo "deb http://iachievedit-repos.s3.amazonaws.com/ xenial main" | sudo tee --append /etc/apt/sources.list

3. Run apt-get update

sudo apt-get update

4. Install swift-3.0!

apt-get install swift-3.0

5. Update that PATH!

export PATH=/opt/swift/swift-3.0/usr/bin:$PATH

Even better, update your .bashrc, .zshrc, etc. script and permanently add /opt/swift/swift-3.0/usr/bin to your PATH.

6. Try it out

git clone https://github.com/apple/example-package-dealer
cd example-packager-dealer
swift build
Compiling Swift Module 'FisherYates' (1 sources)
Linking Library:  .build/debug/FisherYates.a
Compiling Swift Module 'PlayingCard' (3 sources)
Linking Library:  .build/debug/PlayingCard.a
Compiling Swift Module 'DeckOfPlayingCards' (1 sources)
Linking Library:  .build/debug/DeckOfPlayingCards.a
Compiling Swift Module 'Dealer' (1 sources)
Linking Executable:  .build/debug/Dealer

Run it!

.build/debug/Dealer

FAQ

Q. Did Apple build these binaries?
A. No, I built them on my personal server using the instructions I posted here.

Q. What git revisions are included in the build?
A. You can use apt-cache show swift-3.0 to see this information. For example:

# apt-cache show swift-3.0
Package: swift-3.0
Status: install ok installed
Priority: optional
Section: development
Installed-Size: 281773
Maintainer: iachievedit (support@iachieved.it)
Architecture: amd64
Version: 1:3.0-0ubuntu2
Depends: clang (>= 3.6), libicu-dev
Conflicts: swift-2.2
Description: Open Source Swift
 This is a packaged version of Open Source Swift 3.0 built from
 the following git revisions of the Apple Github repositories:
       Clang:  c18bb21a04
        LLVM:  0d07a5d3d5
       Swift:  8aa4dadf92
  Foundation:  dc4fa2d80b
Description-md5: 08508c39657c159d064917af87d8d411
Homepage: http://dev.iachieved.it/iachievedit/swift

The source tree is untouched for each build.

Q. Do you test the binaries before you upload them?
A. The Swift build process tests the resulting binaries, and I then do run some basic tests and compile my own applications, but there is currently no separate exhaustive test suite.

Q. Are you releasing builds on a set schedule?
A. Not really, though I may try to stay in sync with the releases from Apple. The idea was to get something out for folks to experiment with and start coding Swift on Linux.

Q. How do these builds relate to the Swift 3.0 preview releases?
A. They don’t! I build and upload Swift 3.0 frequently, and they quickly diverge from the preview releases. Consider these packages experimental.

Q. Where is everything installed?
A. Everything gets put in /opt/swift/swift-3.0/usr.

Q. How do I decipher the package version number?
A. This was my first take on what I thought should be an appropriate package version number. Breaking it down, 3.0-0ubuntu2~trusty1 should be:

  • 3.0 is the version of Swift that is packaged
  • -0ubuntu2 indicates that this is the 2nd package for Ubuntu, with the 0 indicating that there is no upstream Debian package upon which this package was based
  • ~trusty1 indicates that this package is for Trusty Tahr

I think I got that right, but if you feel otherwise please do drop me a line at admin@iachieved.it.

How Does This Work?

I used these awesome instructions on how to host a Debian package repository on Amazon S3. I tried to set up a Launchpad PPA, but quite frankly, got tired of trying to wade through all the metadata required to put together a simple package. I’m sure for hosting distribution repositories it’s all required, but for this it felt like overkill. The folks that develop fpm also have some choice things to say about it.

The packaging scripts we use to build everything and upload to the repository can be found Github. For Swift 3.0 make sure and look at the swift-3.0 branch.

Swift 2.2

If you’re looking for Swift 2.2 Ubuntu packages, see our instructions here.

5 comments

  1. Chris HattonReply

    Running Wily 15.10; installed your swift-2.2 package which worked well, then removed and installed swift-3.0. The motivation for switching was to make use of swift-test.
    Attempting to invoke swift build from cmake gives:

    /usr/bin/swift-build: error while loading shared libraries: libswiftCore.so: cannot open shared object file: No such file or directory

    but the file is present at:

    /usr/lib/swift/linux/libswiftCore.so

    If I manually add /usr/lib/swift/linux/ to the system shared library search path using /etc/ld.so.conf and ldconfig to reload; it works. While I don’t know the challenges involved; I would have thought achieving this automatically would be the goal of packaging, so I thought I’d let you know. Cheers.

  2. SonneReply

    I’m using swift-DEVELOPMENT-SNAPSHOT-2016-03-16-a-ubuntu14.04. I was also missing libswiftCore.so during compile time, so I fixed it by solution provided by Chris Hatton here. Thanks!

    It seems that swift build binary is making wrong path on this snapshot.

    • Ken BurgettReply

      I am having the same error as the two previous messages. I don’t know anything about ldconfig, so a small script doing what is described above would be very much appreciated.

  3. AlexReply

    Hm… not understand yet, what brunch do you building for package? Master or swift-3.0-branch?
    I has build like *.deb for Debian =)

    • Joe Post authorReply

      The

      is brand new and I need to update my scripts to switch to using it. Stay tuned!

Leave a Reply

Your email address will not be published. Required fields are marked *