Difference between revisions of "Building and hacking LDC on Windows using MSVC"

From D Wiki
Jump to: navigation, search
m (Building LDC)
(Update for VS 2015, libconfig 1.5 (on GitHub now too), dmd-testsuite...)
Line 6: Line 6:
  
 
* Windows x64, of course!
 
* Windows x64, of course!
* Install Visual Studio (e.g. [http://www.visualstudio.com/en-us/downloads/download-visual-studio-vs#DownloadFamilies_2 Visual Studio 2013 Express for Windows Desktop])
+
* Visual Studio (e.g. [https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx VS Community 2015])
* [http://python.org/download/ Python 2.7.x or Python 3.3.x] (I use 3.3.0)
+
* [http://git-scm.com/download/win git 1.8+] (I use [https://code.google.com/r/chen2008cj-gitclone/source/browse/PortableGit-1.8.1.2-preview20130201.7z PortableGit])
* [http://git-scm.com/download/win git 1.8.x] (I use 1.9.4.msysgit.2 installed with option "Run Git from the Windows Command Prompt")
+
* [http://python.org/download/ Python 2.7.x or Python 3.3.x] (I use [http://portablepython.com/wiki/Download/ Portable Python])
* [http://cmake.org/cmake/resources/software.html CMake 2.8.x] (I use 3.0.2 installed with option "Add cmake to the system PATH for all users")
+
* [http://www.cmake.org/download/ CMake 2.8+]
* a tool to extract .tgz files, e.g. [http://7-zip.org/ 7-Zip]
+
* [https://github.com/martine/ninja/releases Ninja], a neat little and fast build system
 +
* [http://wiki.dlang.org/Curl_on_Windows Curl library] (just use a precompiled one)
 +
** Put curl.lib in a LIB/LIBPATH directory (e.g., <tt>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\amd64</tt>)...
 +
** ... and curl.dll in a PATH directory (e.g., <tt>C:\LDC\LDC-x64\bin</tt>).
  
=== Required source downloads ===
+
=== Shell script ===
  
* [http://hyperrealm.com/libconfig/ libconfig] (Just use latest release 1.4.9.)
+
I use a little batch file to set up my LDC build environment. It's located in the root of my LDC environment: <tt>C:\LDC\shell.cmd</tt>.
 +
It sets up the <tt>PATH</tt> environment variable (I've installed the portable tools into <tt>C:\LDC\Tools</tt>) and then spawns a new <tt>VS 2015 x64 Native Tools Command Prompt</tt> with a below-normal process priority, so that my system stays responsive while building.
 +
I use a shortcut on my desktop to this batch file. Please adjust it to your needs (and note that <tt>%~dp0</tt> is the directory containing the script, i.e., <tt>C:\LDC\</tt>).
 +
 
 +
<pre>
 +
@echo off
 +
set PATH=%~dp0LDC-x64\bin;%~dp0LLVM-x64\bin;%~dp0Tools\Ninja 1.6.0;%~dp0Tools\make-3.81\bin;%~dp0Tools\PortableGit-1.8.1.2-preview20130201\bin;%~dp0Tools\cmake-3.3.0-win32-x86\bin;%~dp0Tools\Portable Python 2.7.5.1\App;%PATH%
 +
if not exist "%TERM%" set TERM=msys
 +
start /belownormal %comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
 +
</pre>
  
 
=== Environment check ===
 
=== Environment check ===
  
After installing the software, you can open a &quot;VS2013 x64 Native Tools Command Prompt&quot;.
+
Open a shell by executing the batch file.
* Running <tt>cmake --version</tt> should display the banner from cmake.
 
* Running <tt>git --version</tt> should display the banner from git.
 
* Running <tt>msbuild /version</tt> should display the banner from msbuild.
 
* Running <tt>&lt;Python install path&gt;\python --version</tt> should display the banner from python.
 
  
My working directory is <tt>C:\ldcenv</tt>. Every step starts in this directory. Please feel free to adjust this to your needs.
+
* Running <tt>cl</tt> should display the banner from the MS compiler.
 +
* Running <tt>git --version</tt> should display the banner from git.
 +
* Running <tt>python --version</tt> should display the banner from python.
 +
* Running <tt>cmake --version</tt> should display the banner from cmake.
 +
* Running <tt>ninja --version</tt> should display the ninja version.
  
 
=== Build LLVM ===
 
=== Build LLVM ===
  
To build LLVM from the command line, just execute the following steps:
+
To build LLVM from the command line, just execute the following steps (from <tt>C:\LDC</tt>):
  
 
<ul>
 
<ul>
<li><tt>git clone http://llvm.org/git/llvm.git llvm</tt></li>
+
<li>Get the source: <tt>git clone http://llvm.org/git/llvm.git llvm</tt></li>
<li><tt>md build-llvm-x64</tt></li>
+
<li>Create a build directory: <tt>md build-llvm-x64</tt></li>
<li><tt>cd build-llvm-x64</tt></li>
+
<li>Change into it: <tt>cd build-llvm-x64</tt></li>
<li><p>Use a command like this:</p>
+
<li><p>Use a command like this (in one line) to create the Ninja build files:</p>
<pre>cmake -G &quot;Visual Studio 12 Win64&quot; -DCMAKE_INSTALL_PREFIX=&quot;C:\Program Files\LLVM-x64&quot; -DCMAKE_BUILD_TYPE=&quot;RelWithDebInfo&quot;
+
<pre>cmake -G Ninja -DCMAKE_INSTALL_PREFIX=&quot;C:\LDC\LLVM-x64&quot; -DCMAKE_BUILD_TYPE=&quot;RelWithDebInfo&quot;
       -DCMAKE_CXX_FLAGS=&quot;/DWIN32 /MP /W3 /GR- /GS- /Zo&quot; -DPYTHON_EXECUTABLE=&quot;C:\Program Files\Python33\python.exe&quot;
+
       -DPYTHON_EXECUTABLE=&quot;C:\LDC\Tools\Portable Python 2.7.5.1\App\python.exe&quot;
 
       -DLLVM_TARGETS_TO_BUILD=&quot;X86&quot; -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_APPEND_VC_REV=ON ..\llvm</pre></li>
 
       -DLLVM_TARGETS_TO_BUILD=&quot;X86&quot; -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_APPEND_VC_REV=ON ..\llvm</pre></li>
 +
<li>Build LLVM: <tt>ninja</tt></li>
 +
<li>Install it: <tt>ninja install</tt></li>
 
</ul>
 
</ul>
 
Build the INSTALL project in the generated solution: <tt>msbuild INSTALL.vcxproj</tt>
 
  
 
The [http://llvm.org/docs/CMake.html#id10 LLVM page on CMake] documents other variables you can change. The most common is to add more targets. E.g. to build a target for ARM you change the targets to build to <tt>-DLLVM_TARGETS_TO_BUILD=&quot;X86;ARM&quot;</tt>.
 
The [http://llvm.org/docs/CMake.html#id10 LLVM page on CMake] documents other variables you can change. The most common is to add more targets. E.g. to build a target for ARM you change the targets to build to <tt>-DLLVM_TARGETS_TO_BUILD=&quot;X86;ARM&quot;</tt>.
Line 48: Line 60:
 
Simple build instructions for libconfig are missing. You can do the following:
 
Simple build instructions for libconfig are missing. You can do the following:
  
* Extract libconfig source.
+
* <tt>cd C:\LDC</tt>
* Open the libconfig.sln solution
+
* <tt>git clone https://github.com/hyperrealm/libconfig.git libconfig</tt>
* Create a configuration for Win64 Debug
+
* Open the libconfig.sln solution with Visual Studio
* If you like to create a static library then change the configuration type of project <tt>libconfig</tt> to 'Static library'.
+
* Create a solution configuration for 'x64 Debug'
 +
* Change the configuration type of project <tt>libconfig</tt> to 'Static library'.
 
* Build the project <tt>libconfig</tt>
 
* Build the project <tt>libconfig</tt>
  
Alternative you can use a custom <tt>CMakeLists.txt</tt>:
+
Alternatively you can use a custom <tt>CMakeLists.txt</tt>:
  
* Extract libconfig source.
+
* <tt>cd C:\LDC</tt>
* Download CMakeLists.txt from [https://gist.github.com/redstar/d5694a6301c40ceb0720 this gist] and place it into the root folder.
+
* <tt>git clone https://github.com/hyperrealm/libconfig.git libconfig</tt>
* Create a build directory: <tt>md build_libconfig</tt>
+
* Download CMakeLists.txt from [https://gist.github.com/redstar/d5694a6301c40ceb0720 this gist] to <tt>C:\LDC\libconfig</tt>.
* <tt>cd build_libconfig</tt>
+
* Create a build directory: <tt>md build-libconfig-x64</tt>
* Now create the build files:
+
* <tt>cd build-libconfig-x64</tt>
* <tt>cmake ..\libconfig-1.4.9</tt>
+
* <tt>cmake ..\libconfig</tt>
 
* Build the library: <tt>msbuild ALL_BUILD.vcxproj</tt>
 
* Build the library: <tt>msbuild ALL_BUILD.vcxproj</tt>
  
=== Build LDC2 ===
+
=== Build LDC ===
 
 
To build LDC2 from the command line, just execute the following steps:
 
  
 
<ul>
 
<ul>
 +
<li><tt>cd C:\LDC</tt></li>
 
<li><tt>git clone --recursive git://github.com/ldc-developers/ldc.git ldc</tt></li>
 
<li><tt>git clone --recursive git://github.com/ldc-developers/ldc.git ldc</tt></li>
<li><tt>md build-ldc2-x64</tt></li>
+
<li><tt>md build-ldc-x64</tt></li>
<li><tt>cd build-ldc2-x64</tt></li>
+
<li><tt>cd build-ldc-x64</tt></li>
<li><p>Type the next command in one line:</p>
+
<li><p>Use a command like this (in one line):</p>
<pre>cmake -G &quot;Visual Studio 12 Win64&quot; -DCMAKE_INSTALL_PREFIX=&quot;C:\Program Files\LDC&quot; -DCMAKE_BUILD_TYPE=&quot;RelWithDebInfo&quot;
+
<pre>cmake -G &quot;Visual Studio 14 Win64&quot; -DCMAKE_INSTALL_PREFIX=&quot;C:\LDC\LDC-x64&quot; -DCMAKE_BUILD_TYPE=&quot;RelWithDebInfo&quot;
       -DCMAKE_CXX_FLAGS=&quot;/DWIN32 /MP /W2 /GR- /GS- /Zo&quot; -DLLVM_ROOT_DIR=&quot;C:/Program Files/LLVM-x64&quot;
+
       -DLLVM_ROOT_DIR=&quot;C:/LDC/LLVM-x64&quot; -DLIBCONFIG_INCLUDE_DIR=&quot;C:/LDC/libconfig/lib&quot;
      -DLIBCONFIG_INCLUDE_DIR=&quot;C:/ldcenv/libconfig-1.4.9/lib&quot;
+
       -DLIBCONFIG_LIBRARY=&quot;C:/LDC/libconfig/x64/Debug/libconfig.lib&quot; ..\ldc</pre>
       -DLIBCONFIG_LIBRARY=&quot;C:/ldcenv/libconfig-1.4.9/Debug/libconfig.lib&quot; ..\ldc</pre>
+
<p>This assumes that you have a static compiled version of <tt>libconfig.lib</tt>. If you use the DLL version then you need to add <tt>-DLIBCONFIG_DLL=ON</tt>.</p></li>
<p>This assumes that you have a static compiled version of <tt>libconfig.lib</tt>. If you use the DLL version then you have to add <tt>-DLIBCONFIG_DLL=ON</tt>.</p></li>
+
<li>Build LDC and the runtimes: <tt>ninja</tt></li>
 +
<li>If you want to install it: <tt>ninja install</tt></li>
 
</ul>
 
</ul>
  
Build the INSTALL project: <tt>msbuild INSTALL.vcxproj</tt>
+
=== Running the runtime unit tests ===
  
Check that <tt>C:\Program Files\LDC\bin</tt> is in your path and type <tt>ldc2 -version</tt> to check that you can run <tt>LDC2</tt>.
+
* <tt>cd C:\LDC\build-ldc-x64</tt>
 +
* Build the unit tests: <tt>ninja druntime-ldc-unittest druntime-ldc-unittest-debug phobos2-ldc-unittest phobos2-ldc-unittest-debug</tt>
 +
* Run the tests, excluding the dmd-testsuite ones: <tt>ctest -E dmd-testsuite</tt>
  
=== Running the tests ===
+
For troubleshooting be sure to examine the file <tt>C:\LDC\build-ldc-x64\Testing\Temporary\LastTest.log</tt>.
  
The tests can currently NOT be run via <tt>msbuild RUN_TESTS.vcxproj</tt>. So we'll use a neat little build system called [http://martine.github.io/ninja/ Ninja] for this.
+
=== Running the dmd-testsuite tests ===
Note that the dmd-testsuite tests require the <tt>make</tt> tool.
 
  
<ul>
+
dmd-testsuite requires a minimalistic GNU environment. bash, grep etc. are shipped with git. Additionally, we need GNU make and reasonably recent GNU diffutils:
<li>Download the latest Ninja release from [https://github.com/martine/ninja/releases GitHub] (a single .exe) and put it in your PATH.</li>
+
 
<li>Make sure you can link against the [http://wiki.dlang.org/Curl_on_Windows Curl] library (curl.lib in your LIB/LIBPATH, curl.dll in your PATH).</li>
+
* Download [http://gnuwin32.sourceforge.net/packages/make.htm GNU make for Windows]: [http://gnuwin32.sourceforge.net/downlinks/make-bin-zip.php binary] + [http://gnuwin32.sourceforge.net/downlinks/make-dep-zip.php dependencies]
<li>Run CMake just like when building LDC2, but use the <tt>Ninja</tt> generator this time:
+
* Download [http://gnuwin32.sourceforge.net/packages/diffutils.htm GNU diffutils for Windows]: [http://gnuwin32.sourceforge.net/downlinks/diffutils-bin-zip.php binaries] (same dependencies as make)
  <ul>
+
* Extract all 3 ZIP archives into a common root folder, e.g., <tt>C:\LDC\Tools\make</tt>
  <li><tt>md ninja-ldc2-x64</tt></li>
+
* Edit your shell batch script and add the bin subdirectory to your PATH, e.g., <tt>set PATH=%~dp0Tools\make\bin;%PATH%</tt>
  <li><tt>cd ninja-ldc2-x64</tt></li>
+
** Make sure that directory preceeds the git bin directory in the PATH environment variable, so that the newer <tt>diff.exe</tt> from <tt>C:\LDC\Tools\make\bin</tt> is preferred.
  <li><p>Type the next command in one line:</p>
+
* Spawn a new shell and make sure <tt>make --version</tt> prints its banner.
  <pre>cmake -G Ninja -DCMAKE_INSTALL_PREFIX=&quot;C:\Program Files\LDC&quot; -DCMAKE_BUILD_TYPE=&quot;RelWithDebInfo&quot;
+
 
      -DCMAKE_CXX_FLAGS=&quot;/DWIN32 /MP /W2 /GR- /GS- /Zo&quot; -DLLVM_ROOT_DIR=&quot;C:/Program Files/LLVM-x64&quot;
+
Now that we have extended our LDC build environment, we're able to run the dmd-testsuite tests. I prefer to run them manually, outside of ctest.
      -DLIBCONFIG_INCLUDE_DIR=&quot;C:/ldcenv/libconfig-1.4.9/lib&quot;
 
      -DLIBCONFIG_LIBRARY=&quot;C:/ldcenv/libconfig-1.4.9/Debug/libconfig.lib&quot; ..\ldc</pre>
 
  </ul></li>
 
<li>Build LDC and the runtimes: <tt>ninja</tt></li>
 
<li>Build the unit tests: <tt>ninja druntime-ldc-unittest druntime-ldc-unittest-debug phobos2-ldc-unittest phobos2-ldc-unittest-debug</tt></li>
 
<li>Run the tests: <tt>ctest</tt></li>
 
</ul>
 
  
For troubleshooting be sure to examine the file <tt>ninja-ldc2-x64\Testing\Temporary\LastTest.log</tt>.
+
* <tt>cd C:\LDC\ldc\tests\d2\dmd-testsuite</tt>
 +
* If you want to reset the results, delete the folder: <tt>rmdir /S C:\LDC\build-ldc-x64\dmd-testsuite(-debug)</tt>
 +
* Get the command line from <tt>C:\LDC\build-ldc-x64\tests\d2\CTestTestfile.cmake</tt> (e.g., <tt>"make" "-k" "-C" "C:/LDC/ldc/tests/d2/dmd-testsuite" "RESULTS_DIR=C:/LDC/build-ldc-x64/dmd-testsuite-debug" ... "quick"</tt>)
 +
** You may want to redirect stdout and stderr to a log file by appending something like <tt>&nbsp;&gt; C:\LDC\build-ldc-x64\dmd-testsuite.log 2&gt;&amp;1</tt>
 +
* Start the tests.
 +
* Run the tests a second time without resetting the results to get a list of the failures and disabled tests.
  
=== Known bugs ===
+
=== Developing/debugging with Visual Studio ===
  
* Structured Exception Handling is only available for LLVM 3.7 head. Support has still alpha quality and is known to crash your application under certain circumstances. LLVM is getting [http://llvm.org/docs/ExceptionHandling.html#c-exception-handling-using-the-windows-runtime native support for MSVCRT exceptions], so we'll have to wait for that.
+
* <tt>cd C:\LDC</tt>
* You'll probably need to hack your <tt>*.conf.in</tt> configuration file templates and add <tt>-L/LARGEADDRESSAWARE:NO</tt> to your default LDC switches, see [https://github.com/ldc-developers/ldc/issues/442 issue #442].
+
* <tt>md vs-ldc-x64</tt>
* You'll probably also encounter issues like [https://github.com/ldc-developers/ldc/issues/930 #930].
+
* <tt>cd vs-ldc-x64</tt>
* At the time of this writing, LDC is based on D 2.066, and branch <tt>merge-2.067</tt> provides important fixes for MSVC.
+
* Use the cmake command from the Build LDC section, but use the VS generator instead of Ninja this time: <tt>cmake -G "Visual Studio 14 Win64" ...</tt>
 +
* This creates the VS solution <tt>C:\LDC\vs-ldc-x64\ldc.sln</tt>.
  
== Hacking druntime and phobos ==
+
A Visual Studio solution for LLVM can be created the same way.
  
* <tt>ldc.eh2</tt>: Implementation has alpha quality.
+
=== Known bugs/limitations ===
* The MSVC runtime misses support for some C99 functions. See https://github.com/ldc-developers/ldc/issues/761 for an example.
 
** VS 2015 improves Microsoft's C99 support; see [https://github.com/ldc-developers/druntime/pull/29 PR29].
 
  
If you link your modules you have to specify the libraries <tt>phobos-ldc.lib</tt> and <tt>shell32.lib</tt>.
+
* Structured Exception Handling is only available for LLVM 3.7 head. Support in <tt>ldc.eh2</tt> has still alpha quality and is known to crash your application under certain circumstances. LLVM is getting [http://llvm.org/docs/ExceptionHandling.html#c-exception-handling-using-the-windows-runtime native support for MSVCRT exceptions], so we'll have to wait for that.
 +
* At the time of this writing, LDC master is based on D 2.066, and branch <tt>merge-2.067</tt> provides important fixes for MSVC.
 +
** Even more cutting edge, right now anyway, is [https://github.com/kinke/ldc my win64 branch], providing further important fixes (not just for LDC, but all submodules too).
 +
* You'll most likely notice [https://github.com/ldc-developers/ldc/issues/988 issue 988]. :P
 +
* You'll probably also encounter issues like [https://github.com/ldc-developers/ldc/issues/930 #930].
 +
* Visual Studio 2015 is greatly encouraged due to improved C99 support; see [https://github.com/ldc-developers/druntime/pull/29 PR29].
  
 
== Example ==
 
== Example ==

Revision as of 02:43, 9 August 2015

LDC on Windows is work in progress. This page documents how to compile LDC2 on Windows x64. It also provides hints on druntime and phobos.

Building LDC

Required software

Shell script

I use a little batch file to set up my LDC build environment. It's located in the root of my LDC environment: C:\LDC\shell.cmd. It sets up the PATH environment variable (I've installed the portable tools into C:\LDC\Tools) and then spawns a new VS 2015 x64 Native Tools Command Prompt with a below-normal process priority, so that my system stays responsive while building. I use a shortcut on my desktop to this batch file. Please adjust it to your needs (and note that %~dp0 is the directory containing the script, i.e., C:\LDC\).

@echo off
set PATH=%~dp0LDC-x64\bin;%~dp0LLVM-x64\bin;%~dp0Tools\Ninja 1.6.0;%~dp0Tools\make-3.81\bin;%~dp0Tools\PortableGit-1.8.1.2-preview20130201\bin;%~dp0Tools\cmake-3.3.0-win32-x86\bin;%~dp0Tools\Portable Python 2.7.5.1\App;%PATH%
if not exist "%TERM%" set TERM=msys
start /belownormal %comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64

Environment check

Open a shell by executing the batch file.

  • Running cl should display the banner from the MS compiler.
  • Running git --version should display the banner from git.
  • Running python --version should display the banner from python.
  • Running cmake --version should display the banner from cmake.
  • Running ninja --version should display the ninja version.

Build LLVM

To build LLVM from the command line, just execute the following steps (from C:\LDC):

  • Get the source: git clone http://llvm.org/git/llvm.git llvm
  • Create a build directory: md build-llvm-x64
  • Change into it: cd build-llvm-x64
  • Use a command like this (in one line) to create the Ninja build files:

    cmake -G Ninja -DCMAKE_INSTALL_PREFIX="C:\LDC\LLVM-x64" -DCMAKE_BUILD_TYPE="RelWithDebInfo"
          -DPYTHON_EXECUTABLE="C:\LDC\Tools\Portable Python 2.7.5.1\App\python.exe"
          -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_APPEND_VC_REV=ON ..\llvm
  • Build LLVM: ninja
  • Install it: ninja install

The LLVM page on CMake documents other variables you can change. The most common is to add more targets. E.g. to build a target for ARM you change the targets to build to -DLLVM_TARGETS_TO_BUILD="X86;ARM".

Build libconfig

Simple build instructions for libconfig are missing. You can do the following:

  • cd C:\LDC
  • git clone https://github.com/hyperrealm/libconfig.git libconfig
  • Open the libconfig.sln solution with Visual Studio
  • Create a solution configuration for 'x64 Debug'
  • Change the configuration type of project libconfig to 'Static library'.
  • Build the project libconfig

Alternatively you can use a custom CMakeLists.txt:

  • cd C:\LDC
  • git clone https://github.com/hyperrealm/libconfig.git libconfig
  • Download CMakeLists.txt from this gist to C:\LDC\libconfig.
  • Create a build directory: md build-libconfig-x64
  • cd build-libconfig-x64
  • cmake ..\libconfig
  • Build the library: msbuild ALL_BUILD.vcxproj

Build LDC

  • cd C:\LDC
  • git clone --recursive git://github.com/ldc-developers/ldc.git ldc
  • md build-ldc-x64
  • cd build-ldc-x64
  • Use a command like this (in one line):

    cmake -G "Visual Studio 14 Win64" -DCMAKE_INSTALL_PREFIX="C:\LDC\LDC-x64" -DCMAKE_BUILD_TYPE="RelWithDebInfo"
          -DLLVM_ROOT_DIR="C:/LDC/LLVM-x64" -DLIBCONFIG_INCLUDE_DIR="C:/LDC/libconfig/lib"
          -DLIBCONFIG_LIBRARY="C:/LDC/libconfig/x64/Debug/libconfig.lib" ..\ldc

    This assumes that you have a static compiled version of libconfig.lib. If you use the DLL version then you need to add -DLIBCONFIG_DLL=ON.

  • Build LDC and the runtimes: ninja
  • If you want to install it: ninja install

Running the runtime unit tests

  • cd C:\LDC\build-ldc-x64
  • Build the unit tests: ninja druntime-ldc-unittest druntime-ldc-unittest-debug phobos2-ldc-unittest phobos2-ldc-unittest-debug
  • Run the tests, excluding the dmd-testsuite ones: ctest -E dmd-testsuite

For troubleshooting be sure to examine the file C:\LDC\build-ldc-x64\Testing\Temporary\LastTest.log.

Running the dmd-testsuite tests

dmd-testsuite requires a minimalistic GNU environment. bash, grep etc. are shipped with git. Additionally, we need GNU make and reasonably recent GNU diffutils:

  • Download GNU make for Windows: binary + dependencies
  • Download GNU diffutils for Windows: binaries (same dependencies as make)
  • Extract all 3 ZIP archives into a common root folder, e.g., C:\LDC\Tools\make
  • Edit your shell batch script and add the bin subdirectory to your PATH, e.g., set PATH=%~dp0Tools\make\bin;%PATH%
    • Make sure that directory preceeds the git bin directory in the PATH environment variable, so that the newer diff.exe from C:\LDC\Tools\make\bin is preferred.
  • Spawn a new shell and make sure make --version prints its banner.

Now that we have extended our LDC build environment, we're able to run the dmd-testsuite tests. I prefer to run them manually, outside of ctest.

  • cd C:\LDC\ldc\tests\d2\dmd-testsuite
  • If you want to reset the results, delete the folder: rmdir /S C:\LDC\build-ldc-x64\dmd-testsuite(-debug)
  • Get the command line from C:\LDC\build-ldc-x64\tests\d2\CTestTestfile.cmake (e.g., "make" "-k" "-C" "C:/LDC/ldc/tests/d2/dmd-testsuite" "RESULTS_DIR=C:/LDC/build-ldc-x64/dmd-testsuite-debug" ... "quick")
    • You may want to redirect stdout and stderr to a log file by appending something like  > C:\LDC\build-ldc-x64\dmd-testsuite.log 2>&1
  • Start the tests.
  • Run the tests a second time without resetting the results to get a list of the failures and disabled tests.

Developing/debugging with Visual Studio

  • cd C:\LDC
  • md vs-ldc-x64
  • cd vs-ldc-x64
  • Use the cmake command from the Build LDC section, but use the VS generator instead of Ninja this time: cmake -G "Visual Studio 14 Win64" ...
  • This creates the VS solution C:\LDC\vs-ldc-x64\ldc.sln.

A Visual Studio solution for LLVM can be created the same way.

Known bugs/limitations

  • Structured Exception Handling is only available for LLVM 3.7 head. Support in ldc.eh2 has still alpha quality and is known to crash your application under certain circumstances. LLVM is getting native support for MSVCRT exceptions, so we'll have to wait for that.
  • At the time of this writing, LDC master is based on D 2.066, and branch merge-2.067 provides important fixes for MSVC.
    • Even more cutting edge, right now anyway, is my win64 branch, providing further important fixes (not just for LDC, but all submodules too).
  • You'll most likely notice issue 988. :P
  • You'll probably also encounter issues like #930.
  • Visual Studio 2015 is greatly encouraged due to improved C99 support; see PR29.

Example

The simple D program hello.d

import std.stdio;

int main()
{
    writefln("Hello LDC2");
    return 0;
}

can be compiled and linked with the commands:

ldc2 -c hello.d
link hello2.obj phobos-ldc.lib shell32.lib

or simply with: ldc2 hello.d

The resulting hello.exe produces the expected output.



Windows MSVC