Building LDC from source
This page gives an overview of what is required to build and install LDC on most Posix-like systems such as Linux or OS X. For building LDC on Windows, please see the dedicated page.
Contents
Advice
It is hard for us to keep these wiki pages up-to-date. If you run into trouble, have a look at the build scripts for our Continuous Integration platforms: the files .travis.yml (Ubuntu Linux and OSX) and appveyor.yml (Windows) are always up-to-date with the latest build setup.
Prerequisites
- Git (for fetching the source code, if not using a tarball)
- a C++ toolchain (GCC, Clang, …)
- a D compiler (currently LDC and DMD are supported)
- If you don't have a D compiler installed: LDC 0.17 is the last version that does not need a D compiler to be built. Thus for bootstrapping, you can first build 0.17, and then use that to build newer compiler versions. Our testing infrastructure explicitly tests that new LDC versions can be built with 0.17. The git branch is called ltsmaster.
- CMake 2.8+
- LLVM 3.5+
- libconfig++ and its header files (the -devel or -dev package for some Linux distributions, on OSX: sudo port install libconfig-hr)
- libcurl-dev for building the D2 standard library and tests (various versions available, e.g. libcurl4-gnutls-dev on Ubuntu)
- libedit-dev
- zlib-dev (e.g. zlib1g-dev on Ubuntu)
Please check the LLVM page on broken versions of GCC and other tools to make sure your toolchain is not known to be bad.
LLVM
Many Linux distributions already provide recent binary LLVM packages, sometimes in the form of user-curated package repositories (PPA, …). If an recent LLVM pacakge is available, you might prefer to use it, as LLVM is a rather big project to build.
Building LLVM manually
We try to keep LDC up-to-date with LLVM trunk, but a release version of LLVM >= 3.5 is recommended for the least amount of trouble (with LLVM trunk, you will have to recompile LLVM often). Download LLVM 3.7.1 with $ wget http://llvm.org/releases/3.7.1/llvm-3.7.1.src.tar.xz, extract the archive, and then run:
$ ./configure --enable-optimized --disable-assertions --enable-targets=x86 $ make # add -j<n> as appropriate depending on your system $ sudo make install
If you are planning to work on LDC itself, you might want to install a debug build of LLVM instead by using ./configure --enable-assertions. Warning: This leads to a heavy slowdown!
LDC
Now, your system should be ready to build and install LDC from source.
First, clone the LDC GitHub repository:
$ git clone --recursive https://github.com/ldc-developers/ldc.git
If you're behind a company firewall and cloning of the submodules fail, first configure git to use a different protocol, ex https:
$ git config --global url."https://github".insteadOf git://github
If you already have a local copy of the source tree, don’t forget to make sure your submodules are up to date by running git submodule update --init.
Then, just run the following commands as usual (see the list of useful CMake switches below):
cd ldc mkdir build && cd build # arbitrary working directory cmake .. #NOTE: on error Could NOT find LibConfig (missing: LIBCONFIG_INCLUDE_DIR LIBCONFIG_LIBRARY) and using brew, use for eg: CMAKE_PREFIX_PATH=`brew --prefix` cmake .. # see https://github.com/ldc-developers/ldc/issues/952 make # -j<n> as appropriate sudo make install
The last step is optional; instead of installing it to the system, you can also choose to run LDC from the bin/ directory in your CMake working tree.
Useful CMake variables
- LIB_SUFFIX: Some Linux distributions, such as Fedora, expect 64 bit libraries in /usr/lib64 instead of /usr/lib. In this case, the installation directory can be adjusted using -DLIB_SUFFIX=64.
- CMAKE_INSTALL_PREFIX: The installation prefix, /usr/local by default (e.g. -DCMAKE_INSTALL_PREFIX=/opt/ldc).
- INCLUDE_INSTALL_DIR: The location the D modules for druntime and Phobos are installed to.
- RUNTIME_DIR, PHOBOS2_DIR: By default, druntime and Phobos are expected in runtime/ as Git submodules. Should circumstances require it, these paths can be changed by setting the variables accordingly.
- LLVM_ROOT_DIR and LLVM_CONFIG: Allows you to specify the LLVM instance to use. LLVM_CONFIG specifies the path and name of the llvm-config binary to use. By default, it is assumed to be ${LLVM_ROOT_DIR}/bin/llvm-config, otherwise it is searched for on default system paths.
- LIBCONFIG_LIBRARY and LIBCONFIG_INCLUDE_DIR: These variables can be used to specify the location of the libconfig++ library files and the path to the corresponding header files.
Tips
The Makefiles generated by CMake respect the DESTDIR variable for the install target. It is prepended to all the file installation targets. This can be useful for building packages: $ make install DESTDIR=<your root directory>