HOME -> Swift on Linux

How to Build Swift on Ubuntu 14.04 from Source

December 14, 2015

After a partial success trying to build Swift 2.2 on CentOS 7.1, I decided to attempt the same on Ubuntu 14.04, a platform where I could successfully use the Apple-provided binaries. See http://www.swiftprogrammer.info/swift_centos_1.html about my attempts on CentOS 7.1.

For this build I used an Azure VM D2 instance with 2 cores and 7 GB of RAM. Hopefully the box won't run out of memory...

The dependencies were installed per https://github.com/apple/swift/blob/swift-2.2-SNAPSHOT-2015-12-10-a/README.md. The version being installed is from tag swift-2.2-SNAPSHOT-2015-12-10-a.

Get the Sources

The following directory structure was created. You may, of course, adjust this to your liking. mkdir swift_2.2 cd swift_2.2 Then I obtained the sources from GitHub, similar to what was done for the CentOS 7.1 build, except a more recent tag was used: git clone --branch swift-2.2-SNAPSHOT-2015-12-10-a https://github.com/apple/swift.git swift git clone --branch swift-2.2-SNAPSHOT-2015-12-10-a https://github.com/apple/swift-llvm.git llvm; git clone --branch swift-2.2-SNAPSHOT-2015-12-10-a https://github.com/apple/swift-clang.git clang; git clone --branch swift-2.2-SNAPSHOT-2015-12-10-a https://github.com/apple/swift-lldb.git lldb; git clone https://github.com/apple/swift-cmark.git cmark; git clone --branch swift-2.2-SNAPSHOT-2015-12-10-a https://github.com/apple/swift-llbuild.git llbuild; git clone --branch swift-2.2-SNAPSHOT-2015-12-10-a https://github.com/apple/swift-package-manager.git swiftpm; git clone --branch swift-2.2-SNAPSHOT-2015-12-10-a https://github.com/apple/swift-corelibs-xctest.git; git clone --branch swift-2.2-SNAPSHOT-2015-12-10-a https://github.com/apple/swift-corelibs-foundation.git; git clone --branch release https://github.com/ninja-build/ninja.git;

The Build Process

Clang 3.6 was installed using apt-get install clang-3.6 ln -s /usr/bin/clang-3.6 /usr/bin/clang ln -s /usr/bin/clang++-3.6 /usr/bin/clang++ Thus we could immediately proceed to build LLVM, Clang, Swift, Swift Package Manager, Swift Build, and Foundation: utils/build-script -t -l -b -p --foundation -R This is assuming we are in the swift_2.2/swift directory.

Unlike CentOS 7.1, the build on Ubuntu 14.04 was completed without errors. The tests were built and run with the following results: Expected Passes : 1681 Expected Failures : 92 Unsupported Tests : 576 -- check-swift-linux-x86_64 finished -- --- Finished tests for swift --- .... Then LLDB tests failed with some unexpected successes and aborted.

Let's Try It!

swiftc and swift commands can be used with a trivial Swift file to compile it to a native executable or to run it in interpreter mode.

However, swift REPL and swift build fail with the same errors as on CentOS 7.1. Swift REPL: LLVM ERROR: Compiler-internal integrated REPL unimplemented for this platform; use the LLDB-enhanced REPL instead. Swift build: error: unable to invoke subcommand: /root/swift_2.2/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swift-build (No such file or directory)

Now let's try to use Foundation. This leads to the same errors as on CentOS 7.1. Foundation can be used all right on the same box using the swift executable from Apple's binary distribution.

The swift build problem can be fixed on Ubuntu by adding the following to the path: <wherever your swift lives>/build/Ninja-ReleaseAssert/swiftpm-linux-x86_64/debug This would not work on CentOS 7.1, as the swiftpm directory is empty there.


Thus building Swift 2.2 from source on Ubuntu 14.04 gets us a little further than on CentOS 7.1, but is still only a partial success: So, there is some homework to do here.

Please feel free to contact me with questions or comments.

© 2015 swiftprogrammer.infoAnatoli Peredera