Difference between revisions of "Building under Windows"

From D Wiki
Jump to: navigation, search
m (Where to go from here: fix typo)
(Clarify build steps: add notes, keep commands up to date)
Line 1: Line 1:
 
== Prerequisites ==
 
== Prerequisites ==
  
On Windows, you will need [https://git-scm.com/ Git for Windows], [http://ftp.digitalmars.com/dmc.zip the DigitalMars C++ compiler], and, for 64-bit or 32-bit COFF builds, the [https://www.microsoft.com/en-us/download/details.aspx?id=8279 Microsoft Windows SDK].
+
On Windows, you will need [https://git-scm.com/ Git for Windows], [http://dlang.org/download.html#dmd D compiler], [http://ftp.digitalmars.com/dmc.zip the DigitalMars C++ compiler], and, for 64-bit or 32-bit COFF builds, the [https://www.microsoft.com/en-us/download/details.aspx?id=8279 Microsoft Windows SDK].
 +
 
 +
Assuming that {{code|make}}, {{code|dmc}} and {{code|dmd}} from digital mars are in your path and your sources are checked out into {{code|C:\D\dmd2\src}} which has the following structure:
 +
<syntaxhighlight lang=dos>
 +
C:\D\dmd2\src\dmd
 +
C:\D\dmd2\src\druntime
 +
C:\D\dmd2\src\phobos
 +
C:\D\dmd2\src\tools
 +
</syntaxhighlight>
  
 
== Building D ==
 
== Building D ==
Line 11: Line 19:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Assuming your sources are checked out {{code|C:\D}}, and that {{code|make}} from digital mars is in your path, you can do the following to build them:
+
=== Building DMD ===
  
 +
To build DMD compiler you should run the following commands ({{code|win32.mak}} file expects that {{code|HOST_DC}} variable is set to {{code|dmd}}):
 
<syntaxhighlight lang=dos>
 
<syntaxhighlight lang=dos>
 
set DM_HOME=C:\D
 
set DM_HOME=C:\D
 
cd %DM_HOME%\dmd2\src\dmd\src
 
cd %DM_HOME%\dmd2\src\dmd\src
 +
set HOST_DC=dmd
 
make -fwin32.mak release
 
make -fwin32.mak release
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 21: Line 31:
 
From there, it is suggested to move the built binaries into your {{code|%DM_HOME%\windows\bin}} directory, and add that to your path:
 
From there, it is suggested to move the built binaries into your {{code|%DM_HOME%\windows\bin}} directory, and add that to your path:
 
<syntaxhighlight lang=dos>
 
<syntaxhighlight lang=dos>
 +
mkdir %DM_HOME%\dmd2\windows\bin
 
copy *.exe %DM_HOME%\dmd2\windows\bin
 
copy *.exe %DM_HOME%\dmd2\windows\bin
set path=%path%;%DM_HOME%\dmd2\windows\bin
+
set path=%DM_HOME%\dmd2\windows\bin;%path%
 
</syntaxhighlight>
 
</syntaxhighlight>
  
From there, you have to create a {{code|sc.ini}} in your {{code|DMD.exe}} directory. It is suggested to just copy paste the one provided in the packaged {{Latest DMD Version Raw}}, instead of writing your own.
+
From there, you have to create a {{code|sc.ini}} in your {{code|%DM_HOME%\dmd2\windows\bin}} directory (where {{code|dmd.exe}} is). It is suggested to just copy paste the one provided in the packaged {{Latest DMD Version Raw}}, instead of writing your own, like:
 +
<syntaxhighlight lang=dos>
 +
copy "C:\Program Files\D\dmd2\windows\bin\sc.ini" %DM_HOME%\dmd2\windows\bin
 +
</syntaxhighlight>
  
Now build druntime:
+
=== Building D runtime ===
 +
 
 +
Make sure that you are using {{code|dmd}} compiled in previous step because older compiler might not compile the latest druntime code.
 +
 
 +
To build D runtime you should run the following commands:
 
<syntaxhighlight lang=dos>
 
<syntaxhighlight lang=dos>
 
cd %DM_HOME%\dmd2\src\druntime
 
cd %DM_HOME%\dmd2\src\druntime
Line 33: Line 51:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
And phobos:
+
=== Building Phobos ===
 +
 
 +
Make sure that you are using {{code|dmd}} compiled in previous step because older compiler might not compile the latest phobos code.
 +
 
 +
To build Phobos you should run the following commands:
 
<syntaxhighlight lang=dos>
 
<syntaxhighlight lang=dos>
 
cd %DM_HOME%\dmd2\src\phobos
 
cd %DM_HOME%\dmd2\src\phobos
Line 39: Line 61:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
You should copy the phobos lib into your {{code|windows\lib}} folder:
+
You should copy phobos lib into your {{code|%DM_HOME%\windows\lib}} folder:
 
<syntaxhighlight lang=dos>
 
<syntaxhighlight lang=dos>
 +
mkdir %DM_HOME%\dmd2\windows\lib
 
copy phobos.lib %DM_HOME%\dmd2\windows\lib
 
copy phobos.lib %DM_HOME%\dmd2\windows\lib
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Optionally, you can build rdmd from source if you have checked out {{code|tools}} in your sources:
+
=== Building rdmd ===
 +
 
 +
Optionally, you can build rdmd from source if you have checked out {{code|tools}} in your sources. Some additional libs might be required for build and can simply be copy pasted from the {{Latest DMD Version Raw}} package without overwriting your {{code|phobos.lib}}.
 +
 
 +
To build rdmd you should run the following commands:
 
<syntaxhighlight lang=dos>
 
<syntaxhighlight lang=dos>
 
cd %DM_HOME%\dmd2\src\tools
 
cd %DM_HOME%\dmd2\src\tools
make -fwin32.mak rdmd.exe
+
make -fwin32.mak rdmd
copy *.exe %DM_HOME%\dmd2\windows\bin
+
</syntaxhighlight>
 +
 
 +
You should copy rdmd into your {{code|%DM_HOME%\windows\bin}} folder:
 +
<syntaxhighlight lang=dos>
 +
mkdir %DM_HOME%\dmd2\windows\lib
 +
copy generated\windows\32\*.exe %DM_HOME%\dmd2\windows\bin
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
=== Thirdparty libraries ===
  
 
The last step is getting the additional libs. curl for D2 can be found at the bottom of the download section of dlang.org: [[http://dlang.org/download.html download]].
 
The last step is getting the additional libs. curl for D2 can be found at the bottom of the download section of dlang.org: [[http://dlang.org/download.html download]].
  
Additional libs that are necessary can simply be copy pasted from the {{Latest DMD Version Raw}} package (without overwriting your {{code|phobos.lib}})
+
Additional libs that are necessary can simply be copy pasted from the {{Latest DMD Version Raw}} package (without overwriting your {{code|phobos.lib}}).
 +
 
 +
=== Verifying ===
  
 
The very last step is to verify that everything works by unittesting phobos:
 
The very last step is to verify that everything works by unittesting phobos:
 
 
<syntaxhighlight lang=dos>
 
<syntaxhighlight lang=dos>
 
cd %DM_HOME%\dmd2\src\phobos
 
cd %DM_HOME%\dmd2\src\phobos

Revision as of 02:13, 2 November 2016

Prerequisites

On Windows, you will need Git for Windows, D compiler, the DigitalMars C++ compiler, and, for 64-bit or 32-bit COFF builds, the Microsoft Windows SDK.

Assuming that make, dmc and dmd from digital mars are in your path and your sources are checked out into C:\D\dmd2\src which has the following structure:

C:\D\dmd2\src\dmd
C:\D\dmd2\src\druntime
C:\D\dmd2\src\phobos
C:\D\dmd2\src\tools

Building D

The following instructions work for win32. May or may not work with win64. This scheme is a suggestion. These instructions should work when building from a clean repository, however, this repository contains autogenerated code that may be left behind after switching branches so running a git clean after switching branches is a good idea:

git clean -xfd

Building DMD

To build DMD compiler you should run the following commands (win32.mak file expects that HOST_DC variable is set to dmd):

set DM_HOME=C:\D
cd %DM_HOME%\dmd2\src\dmd\src
set HOST_DC=dmd
make -fwin32.mak release

From there, it is suggested to move the built binaries into your %DM_HOME%\windows\bin directory, and add that to your path:

mkdir %DM_HOME%\dmd2\windows\bin
copy *.exe %DM_HOME%\dmd2\windows\bin
set path=%DM_HOME%\dmd2\windows\bin;%path%

From there, you have to create a sc.ini in your %DM_HOME%\dmd2\windows\bin directory (where dmd.exe is). It is suggested to just copy paste the one provided in the packaged 2.100.0, instead of writing your own, like:

copy "C:\Program Files\D\dmd2\windows\bin\sc.ini" %DM_HOME%\dmd2\windows\bin

Building D runtime

Make sure that you are using dmd compiled in previous step because older compiler might not compile the latest druntime code.

To build D runtime you should run the following commands:

cd %DM_HOME%\dmd2\src\druntime
make -fwin32.mak

Building Phobos

Make sure that you are using dmd compiled in previous step because older compiler might not compile the latest phobos code.

To build Phobos you should run the following commands:

cd %DM_HOME%\dmd2\src\phobos
make -fwin32.mak

You should copy phobos lib into your %DM_HOME%\windows\lib folder:

mkdir %DM_HOME%\dmd2\windows\lib
copy phobos.lib %DM_HOME%\dmd2\windows\lib

Building rdmd

Optionally, you can build rdmd from source if you have checked out tools in your sources. Some additional libs might be required for build and can simply be copy pasted from the 2.100.0 package without overwriting your phobos.lib.

To build rdmd you should run the following commands:

cd %DM_HOME%\dmd2\src\tools
make -fwin32.mak rdmd

You should copy rdmd into your %DM_HOME%\windows\bin folder:

mkdir %DM_HOME%\dmd2\windows\lib
copy generated\windows\32\*.exe %DM_HOME%\dmd2\windows\bin

Thirdparty libraries

The last step is getting the additional libs. curl for D2 can be found at the bottom of the download section of dlang.org: [download].

Additional libs that are necessary can simply be copy pasted from the 2.100.0 package (without overwriting your phobos.lib).

Verifying

The very last step is to verify that everything works by unittesting phobos:

cd %DM_HOME%\dmd2\src\phobos
make -fwin32.mak unittest

Common Windows issues

Missing MASM386

If when building druntime you get errors about missing MASM386, it's due to a required assembling of a file called minit.asm. However the druntime repository includes a prebuilt minit.obj file so you shouldn't need to assemble it again. As a workaround for the make error create an empty masm386.bat file and put it in a directory that's in your PATH.

It's also recommended that you use the cmd.exe terminal. Others, like PowerShell, are known to experience issues with legacy tools.

Intermediate files lead to several errors

The three main components (dmd, druntime, phobos) should always be built together with matching versions. The intermediate files generated by a previous build can lead to a failure so it's advisable to run

make -fwin32.mak clean

on each component before starting the process.

Where to go from here

If you want to contribute to a D project, please continue with the starting as a contributor guide. If you want to contribute to Phobos, you may also read the contributing to Phobos guide.