An account of attempts to build the recently-released open source Swift on CentOS 6 (6.7). This required more work than building on CentOS 7: A newer version of GCC, 4.8.2, had to be installed, and some dependencies needed to be built from source.
HOME -> Swift on Linux
Building Swift on CentOS 6.7 from Source
December 26, 2015
Having tried building Swift from source on CentOS 7.1 (see http://www.swiftprogrammer.info/swift_centos_1.html) and Ubuntu 14.04 (http://www.swiftprogrammer.info/swift_ubuntu_2.html), I decided to try this on an older CentOS version, 6.7. I was inspired by this quesion on StackOverflow: http://stackoverflow.com/questions/34234250/building-swift-on-centos/34280446#34280446. This was not as easy as installing on recent Linux versions because
- GCC was too old (4.4.7)
- CMake available from the repository was too old.
- Clang available from the repository was too old (3.4)
- Some required dependencies available from the repository were too old and had to be built from source.
The build was done on a Microsoft Azure standard D2 instance with 2 cores and 7 GB of RAM.
Prerequisites
This tutorial assumes good working knowledge of the Linux command line, including how to install software from the repository or from source code. The first step was to
Build GCC 4.8.2 from Source
This is well described at https://gcc.gnu.org/wiki/InstallingGCC">https://gcc.gnu.org/wiki/InstallingGCC.
GCC 4.8.2 was installed in /opt/gcc-4.8.2/. If you install it elsewhere, the paths in this tutorial will need to be modified accordingly.
Once GCC 4.8.2 was installed, the old version was removed using yum. To enable Clang to use the headers and libraries that came with the new GCC, the following variables were set:
export CPLUS_INCLUDE_PATH=/opt/gcc-4.8.2/include/c++/4.8.2:/opt/gcc-4.8.2/include/c++/4.8.2/x86_64-unknown-linux-gnu
export LIBRARY_PATH=/opt/gcc-4.8.2/lib64:/opt/gcc-4.8.2/lib/gcc/x86_64-unknown-linux-gnu/4.8.2
export LD_LIBRARY_PATH=/usr/local/lib:/opt/gcc-4.8.2/lib64
For the same reason, namely to allow Clang to work properly, the following files were symlinked from /opt/gcc-4.8.2/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/ to /usr/lib64:
crtbegin.o
crtbeginS.o
crtbeginT.o
crtend.o
crtendS.o
crtfastmath.o
crtprec32.o
crtprec64.o
crtprec80.o
/usr/local/lib was added to LD_LIBRARY_PATH to facilitate some dependencies, built from source, that installed their libraries into /usr/local/lib.
And, of course, the location of the new GCC binaries, /opt/gcc-4.8.2/bin/, had to be added to the path. The next step was to
Build CMake from Source
CMake available from the repository is too old, so a newer version needs to be installed. To avoid confusion, it is a good idea to remove, using yum, the older version if it is installed. CMake installation is straightforward. The source is available from https://cmake.org. Please make sure the cmake binary is in your PATH. Building CMake is a good test to see if your newly-installed GCC is functional. Now it's time to
Build Clang from Source
This is well described here: http://www.llvm.org/docs/GettingStarted.html. Please note that you only need LLVM and Clang in this case. Also, you don't have to check the code out of the repository, but instead get the sources from http://www.llvm.org/releases/download.html.
You might also find some useful information at http://www.omniprog.info/cpp.html. Most articles found there deal with more than just building Clang, but nonetheless some information may be helpful.
Make sure the PATH is set up such that your newly-built Clang is used.
Get Dependencies from the Repository
The following dependencies were good enough as installed from the repository using yum. These I had to install:
- git
- libuuid-devel
- libbsd-devel
- libedit-devel
- sqlite-devel
- libxml2-devel
These were already installed, but if your system does not have them, you can install them using yum:
I was able to get away without installing swig, even though it is listed as a dependency on the swift.org site.
Install Dependencies from Source
The following had to be built from source and installed:
- Python 2.7. Make sure to configure it with --enable-shared. I installed it in /usr/local (default).
- ICU 55. It can be downloaded from http://site.icu-project.org/download. I installed it in /usr/local and had to make sure to
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
It is also important to use GCC, not Clang, as the compiler when building ICU! In my case, building with Clang produced this error:/opt/gcc-4.8.2/include/c++/4.8.2/type_traits:269:39: error: use of undeclared identifier '__float128'
Building Swift
Procedure for downloading and building Swift is the same as described in the pages mentioned earlier for Ubuntu 14.04 and CentOS 7.1. The result is basically the same as well:
- The only working functionality is the swift compiler (swiftc) and swift interpreter (swift).
- swift build is not usable.
- Unlike on the other 2 systems, here Foundation could not even be built, but on the other systems it was unusable, even though it was built successfully.
The git tag of the Swift source code I used was swift-2.2-SNAPSHOT-2015-12-10-a.
Please feel free to contact me with questions or comments.
© 2015 swiftprogrammer.infoAnatoli Peredera