Building ispc: Linux and Mac OS X

Dmitry Babokin edited this page Nov 10, 2017 · 15 revisions

Building ispc from source on Linux and Mac OS X is relatively straightforward.

You may use docker files as a reference how to build LLVM and ISPC on Ubuntu and Fedora.

First, install the LLVM headers and libraries and the clang compiler on your system. Recommended way to build LLVM is to use alloy.py script from ispc repo. It works on all supported platforms. An alternative, is to build it manually.

Building LLVM using alloy.py script:

  • You need to set LLVM_HOME environment variable to the directory where your llvm build will reside. It's also recommended to set ISPC_HOME environment variable to the path of ispc repository (i.e. where alloy.py is), but it's optional.
  • Make sure that svn is available on your system and has access to the Internet, i.e. all proxy settings are in place. If you prefer git, you'll need to add --git switch to your alloy.py run.
  • Run the script: alloy.py -b --version=5.0 --selfbuild. It will take about an hour on an average quad-core laptop. Note --selfbuild switch is optional, but recommended, as it will ensure that both ispc and llvm libraries are built with the same compiler.

Building LLVM manually:

  • Download the 5.0 release of LLVM from http://llvm.org/releases/download.html and untar it into a directory.
  • Download the 5.0 release of clang from http://llvm.org/releases/download.html and untar it into the llvm-5.0.0.src/tools/ directory. Rename the directory from cfe-5.0.0.src to clang.
  • Create build-5.0 and bin-5.0 directories next to llvm-5.0.0.src.
  • Run cmake from build-5.0 directory with the following options: cmake -DCMAKE_INSTALL_PREFIX=/absolute/path/to/bin-5.0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS=-DLLVM_ENABLE_DUMP -DCMAKE_CXX_FLAGS=-DLLVM_ENABLE_DUMP -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_TARGETS_TO_BUILD=X86 ../llvm-5.0.0.src.
  • Run make, and then make install. You may want to speed up your build with -jN switch, where N is number of parallel jobs to run.
  • Once LLVM is installed, make sure that the bin directory it installs its binaries into is in your PATH. (In particular, the tools llvm-config and clang must be available to build ispc.

You're now ready to build ispc:

  • Make sure your installed version of bison is 2.4 or later. (Unfortunately, the version that ships with macOS is 2.3). Bison can be downloaded from http://www.gnu.org/software/bison/ or installed via third-party package manager (for example, HomeBrew on macOS).
  • Make sure that your installed version of flex is 2.5 or later. (Run flex --version to check.) Flex can be downloaded from http://flex.sourceforge.net/ (or use HomeBrew on macOS).
  • If you are building on RHEL 6.x or CentOS 6.x, and are seeing "/usr/bin/ld: cannot find -lpthread" during link of ispc, you will need to install the glibc-static package.
  • If you are building on RHEL 6.x or CentOS 6.x, and are seeing "/usr/bin/ld: cannot find -lstdc++" during link of ispc, you will need to install the libstdc++-static package.
  • The static repository may need to be explicitly enabled. For example on RHEL 6.x, edit /etc/yum.repos.d/redhat.repo and set enabled = 1 in the [rhel-6-workstation-optional-rpms] section.
  • If you run into the following error: /usr/include/gnu/stubs.h:7:11: fatal error: 'gnu/stubs-32.h' file not found you will need to install the 32-bit version of the glibc-devel package as explained at http://stackoverflow.com/questions/7412548/gnu-stubs-32-h-no-such-file-or-directory.
  • In the ispc source directory, run make
  • You should have an ispc binary in the top-level ispc directory when the build completes.
  • Copy the ispc binary to a directory in your PATH and you're ready to go!

A note regarding versions of LLVM: ispc builds and runs correctly with LLVM 3.6 and later, but support for this release of LLVM will be discontinued. LLVM 5.0 generate better code, so is recommended if possible.

ispc usually builds with recent versions of the LLVM development top-of-tree, though there are occasionally bugs with ToT. It is currently recommended that you build with LLVM 5.0 unless you have a specific reason for using the development branch.