Building LDC on MinGW x86

From D Wiki
Revision as of 02:14, 15 February 2013 by Klickverbot (talk | contribs)
Jump to: navigation, search

This page is a step-by-step guide to setting up a development environment for LDC based on MinGW.

The resulting compiler will create 32 bit executables. Due to the different exception handling models, it is not currently possible to use LDC to target 64 bit Windows/MinGW. Running the 32 bit compiler on a 64 bit Windows system is entirely possible, however.

Note that several links below refer to snapshot builds of different packages. They were the most recent ones available at the time of writing, but newer ones might work just as well.

You will probably also want to adapt the paths to your environment.

  1. Get a recent build of MinGW-w64 for i686 (i.e. 32 bit) targets, with DWARF2-style exception handling. A fresh build is required because support for the SECREL32 relocation type needed to implement TLS was only recently added to GNU as (tested: 2.23.51.20120920).
  2. Download and extract MSYS (e.g. msys+7za+wget+svn+git+mercurial+cvs-rev9.7z from the MinGW-Builds project), open a MSYS shell (for your own sanity, you might want to use something like Console2).
  3. Install CMake (e.g. using the Windows installer from http://www.cmake.org/cmake/resources/software.html), make sure it is on your MSYS $PATH.
    • Optional: Install Ninja somewhere on your MSYS $PATH for shorter compile times, especially on incremental builds. If you don't want to use Ninja, simply change the CMake generator to Makefiles and use make (install) instead of the ninja commands.
  4. Fetch the MinGW CRT sources from SVN (svn co https://mingw-w64.svn.sourceforge.net/svnroot/mingw-w64/trunk/mingw-w64-crt), apply the TLS offset patch and build it (./configure && make), copy the resulting files in lib32 (at least libmingw32.a) to C:\MinGW\i686-w64-mingw32\lib.
  5. LLVM:
    • Fetch the LLVM 3.2 source: Either use the release tarball or checkout the release_32 branch of the SVN/Git (http://llvm.org/git/llvm.git) repository. Don't use SVN trunk (3.3svn), it currently (r174855) has bugs that break compilation with debug info enabled in -singleobj mode.
    • Apply the MinGW TLS support patch. The changes will hopefully arrive in trunk soon.
    • Build and install it: cd /n/Build/Work/llvm-3.2p1-release && cmake /c/Build/Source/llvm/ -G Ninja -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_INSTALL_PREFIX=/n/Build/Intermediate/llvm-3.2p1-release -DCMAKE_BUILD_TYPE=Release && ninja && ninja install.
  6. Fetch the libconfig++ tarball and install it (./configure; make; make install). Don't try an out-of-source build, directory seperator issues tend to break the Makefiles.
  7. LDC:
    • Clone the repository: git clone --recursive https://github.com/ldc-developers/ldc.git
    • Build it: cmake /c/Build/Source/ldc/ -G Ninja -DLLVM_ROOT_DIR='/n/Build/Intermediate/llvm-3.2p1-release' -DLIBCONFIG++_INCLUDE_DIR=/local/include -DLIBCONFIG++_LIBRARY=/local/lib/libconfig++.dll.a
  8. Additional dependencies:
    • You will probably want to install libcurl in order to use std.net.curl (including as part of the test suite): Just fetch the latest source release, extract it, and run ./configure --prefix=/mingw && make && make install. Installing to /mingw is not strictly necessary, but will save you from manually specifying the path anywhere.