Difference between revisions of "Building LDC on MinGW x86"

From D Wiki
Jump to: navigation, search
(MinGW tls patch now in SVN)
m (Update usable MinGW-w64 versions.)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
This page is a step-by-step guide to setting up a development environment for LDC based on MinGW.
 
This page is a step-by-step guide to setting up a development environment for LDC based on MinGW.
 +
 +
'''Note:''' These instructions were last verified to work on date '''04 February 2014''', using LDC commit '''704ab30001582dc67084e6ea8967e61e8112d595'''.
  
 
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.
 
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.
+
Note that the below instructions refer to precise package versions and file system paths. The intention behind this is to record a known-good configuration. Newer releases or differing paths will probably work as well ''if you know what you are doing''.
 
 
You will probably also want to adapt the paths to your environment.
 
  
# 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).
+
# Get a ''recent'' build of '''MinGW-w64''' for i686 (i.e. 32 bit) targets, with DWARF2-style exception handling ('''-dw2'''). A fresh build is required because support for the ''SECREL32'' relocation type needed to implement TLS was only recently added to GNU <tt>as</tt>, and TLS support in the MinGW runtime was broken:
#* Download and extract [http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/gcc-dw2-4.7-release/i686-w64-mingw32-gcc-dw2-4.7.2-release-win32_rubenvb.7z/download i686-w64-mingw32-gcc-dw2-4.7.2-release-win32_rubenvb.7z], renaming the top folder to <tt>C:\MinGW</tt> (or something similar).
+
#* Download and extract [http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/gcc-4.8-dw2-release/i686-w64-mingw32-gcc-dw2-4.8.0-win32_rubenvb.7z/download i686-w64-mingw32-gcc-dw2-4.8.0-win32_rubenvb.7z], renaming the top folder to <tt>C:\MinGW</tt>.
#* Download the [http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/update/i686-w64-mingw32-mingw-w64-update-trunk-20130115_rubenvb.7z/download i686-w64-mingw32-mingw-w64-update-trunk-20130115_rubenvb.7z] update package and extract it over the previous directory.
+
#* You can also use newer builds of '''MinGW-w64''' for i686. E.g. [http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.9.1/threads-posix/dwarf/i686-4.9.1-release-posix-dwarf-rt_v3-rev1.7z/download i686-4.9.1-release-posix-dwarf-rt_v3-rev1] is known to work. Download the [http://sourceforge.net/projects/mingw-w64/files/latest/download?source=files installer] and choose a gcc version, architecture i686, posix threads and dwarf exceptions. If this fails then you can find the files [http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/ here].
# Download and extract MSYS (e.g. [http://sourceforge.net/projects/mingwbuilds/files/external-binary-packages/msys%2B7za%2Bwget%2Bsvn%2Bgit%2Bmercurial%2Bcvs-rev9.7z/download 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 [http://sourceforge.net/projects/console/ Console2]).
+
# Install MSYS and the usual tools like Git:
# Install CMake (e.g. using the Windows installer from http://www.cmake.org/cmake/resources/software.html), make sure it is on your MSYS <tt>$PATH</tt>.
+
#* Download [http://sourceforge.net/projects/mingwbuilds/files/external-binary-packages/msys%2B7za%2Bwget%2Bsvn%2Bgit%2Bmercurial%2Bcvs-rev13.7z/download msys+7za+wget+svn+git+mercurial+cvs-rev13.7z] from the MinGW-Builds project, extract it to <tt>C:\MinGW</tt>, add <tt>C:\MinGW\  /mingw</tt> to <tt>C:\MinGW\msys\etc\fstab</tt>.
#* ''Optional: Install [http://martine.github.com/ninja/ Ninja] somewhere on your MSYS <tt>$PATH</tt> 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 <tt>make (install)</tt> instead of the <tt>ninja</tt> commands.''
+
#* Ensure that C:\MinGW is in your PATH and make sure you're using the GCC version downloaded above by checking the output of <tt>gcc.exe --version</tt>.
# Fetch the MinGW CRT sources from SVN (<tt>svn co https://mingw-w64.svn.sourceforge.net/svnroot/mingw-w64/trunk/mingw-w64-crt</tt>). They contain a patch to fix TLS support. Build it (<tt>./configure && make</tt>) and copy the resulting files in ''lib32'' (at least ''libmingw32.a'') to ''C:\MinGW\i686-w64-mingw32\lib''.
+
#* For your own sanity, you might want to use something like [http://sourceforge.net/projects/console/ Console2] to handle the MinGW shell (set the shell to <tt>C:\MinGW\msys\bin\bash.exe --login -i</tt>).
 +
# Install CMake 2.8.11 using the Windows installer from http://www.cmake.org/cmake/resources/software.html, making sure it is on your MSYS <tt>$PATH</tt> (e.g. by letting the installer put it on your <tt>%PATH%</tt>).
 +
#* ''Optional: Install [http://martine.github.com/ninja/ Ninja] ([https://github.com/martine/ninja/releases binaries]) somewhere on your MSYS <tt>$PATH</tt> for shorter compile times, especially on incremental builds. If you don't want to use Ninja, simply change the CMake generator to Makefiles (<tt>-G"MSYS Makefiles"</tt>) and use <tt>make (install)</tt> instead of the <tt>ninja</tt> commands.''
 
# LLVM:
 
# LLVM:
#* Fetch the LLVM 3.2 source: Either use the [http://llvm.org/releases/download.html#3.2 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 <tt>-singleobj</tt> mode.
+
#* Fetch the LLVM 3.4 source: Either use the [http://llvm.org/releases/download.html#3.4 release tarball] or checkout the ''release_34'' branch of the SVN/Git (http://llvm.org/git/llvm.git) repository.
#* Apply the [https://gist.github.com/klickverbot/4956435 MinGW TLS support] patch. The changes will hopefully arrive in trunk soon.
+
#* Build and install it: <tt>cd /n/Build/Work/llvm-3.4-release && cmake /c/Build/Source/llvm/ -G Ninja -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_INSTALL_PREFIX=/n/Build/Intermediate/llvm-3.4-release -DCMAKE_BUILD_TYPE=Release && ninja && ninja install</tt>.
#* Build and install it: <tt>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</tt>.
 
 
# Fetch the [http://www.hyperrealm.com/libconfig/libconfig-1.4.9.tar.gz ''libconfig++'' tarball] and install it (<tt>./configure; make; make install</tt>). Don't try an out-of-source build, directory seperator issues tend to break the Makefiles.
 
# Fetch the [http://www.hyperrealm.com/libconfig/libconfig-1.4.9.tar.gz ''libconfig++'' tarball] and install it (<tt>./configure; make; make install</tt>). Don't try an out-of-source build, directory seperator issues tend to break the Makefiles.
 
# LDC:
 
# LDC:
 
#* Clone the repository: <tt>git clone --recursive https://github.com/ldc-developers/ldc.git</tt>
 
#* Clone the repository: <tt>git clone --recursive https://github.com/ldc-developers/ldc.git</tt>
#* Build it: <tt>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</tt>
+
#* Build it: <tt>cmake /c/Build/Source/ldc/ -G Ninja -DLLVM_ROOT_DIR='/n/Build/Intermediate/llvm-3.4-release' -DLIBCONFIG++_INCLUDE_DIR=/local/include -DLIBCONFIG++_LIBRARY=/local/lib/libconfig++.dll.a -DCMAKE_BUILD_TYPE=Release && ninja</tt>
 
# Additional dependencies:
 
# 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 [http://curl.haxx.se/download.html source release], extract it, and run <tt>./configure --prefix=/mingw && make && make install</tt>. Installing to <tt>/mingw</tt> is not strictly necessary, but will save you from manually specifying the path anywhere.
 
#* 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 [http://curl.haxx.se/download.html source release], extract it, and run <tt>./configure --prefix=/mingw && make && make install</tt>. Installing to <tt>/mingw</tt> is not strictly necessary, but will save you from manually specifying the path anywhere.
  
 
[[Category:LDC]]
 
[[Category:LDC]]

Latest revision as of 21:32, 14 November 2014

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

Note: These instructions were last verified to work on date 04 February 2014, using LDC commit 704ab30001582dc67084e6ea8967e61e8112d595.

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 the below instructions refer to precise package versions and file system paths. The intention behind this is to record a known-good configuration. Newer releases or differing paths will probably work as well if you know what you are doing.

  1. Get a recent build of MinGW-w64 for i686 (i.e. 32 bit) targets, with DWARF2-style exception handling (-dw2). A fresh build is required because support for the SECREL32 relocation type needed to implement TLS was only recently added to GNU as, and TLS support in the MinGW runtime was broken:
  2. Install MSYS and the usual tools like Git:
    • Download msys+7za+wget+svn+git+mercurial+cvs-rev13.7z from the MinGW-Builds project, extract it to C:\MinGW, add C:\MinGW\ /mingw to C:\MinGW\msys\etc\fstab.
    • Ensure that C:\MinGW is in your PATH and make sure you're using the GCC version downloaded above by checking the output of gcc.exe --version.
    • For your own sanity, you might want to use something like Console2 to handle the MinGW shell (set the shell to C:\MinGW\msys\bin\bash.exe --login -i).
  3. Install CMake 2.8.11 using the Windows installer from http://www.cmake.org/cmake/resources/software.html, making sure it is on your MSYS $PATH (e.g. by letting the installer put it on your %PATH%).
    • Optional: Install Ninja (binaries) 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 (-G"MSYS Makefiles") and use make (install) instead of the ninja commands.
  4. LLVM:
    • Fetch the LLVM 3.4 source: Either use the release tarball or checkout the release_34 branch of the SVN/Git (http://llvm.org/git/llvm.git) repository.
    • Build and install it: cd /n/Build/Work/llvm-3.4-release && cmake /c/Build/Source/llvm/ -G Ninja -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_INSTALL_PREFIX=/n/Build/Intermediate/llvm-3.4-release -DCMAKE_BUILD_TYPE=Release && ninja && ninja install.
  5. 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.
  6. 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.4-release' -DLIBCONFIG++_INCLUDE_DIR=/local/include -DLIBCONFIG++_LIBRARY=/local/lib/libconfig++.dll.a -DCMAKE_BUILD_TYPE=Release && ninja
  7. 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.