Difference between revisions of "Building under Windows"
(link back to contributor guide) |
(→Missing sppn.exe or cl.exe: Recommend reinstalling dmc or merging bup.zip to fix problems) |
||
(22 intermediate revisions by 9 users not shown) | |||
Line 1: | Line 1: | ||
− | == | + | == Automation == |
− | + | [https://github.com/CyberShadow/Digger Digger] can checkout and build any D version automatically for you. Only a D compiler is required. Digger will download all required dependencies by itself. | |
+ | |||
+ | <syntaxhighlight lang=bash> | ||
+ | dub fetch digger | ||
+ | dub run digger | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Among many other features, Digger can build older compiler versions or versions with a specific pull request added: | ||
+ | |||
+ | <syntaxhighlight lang=bash> | ||
+ | # build a specific D version | ||
+ | $ dub run digger -- build v2.064.2 | ||
+ | |||
+ | # build for x86-64 | ||
+ | $ dub run digger -- build --model=64 v2.064.2 | ||
+ | |||
+ | # build commit from a point in time | ||
+ | $ dub run digger -- build "@ 3 weeks ago" | ||
+ | |||
+ | # build specified branch from a point in time | ||
+ | $ dub run digger -- build "2.065 @ 3 weeks ago" | ||
+ | |||
+ | # build with an added pull request | ||
+ | $ dub run digger -- build "master + dmd#123" | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == Use Digital Mars make == | ||
+ | This page needs DigitalMars {{code|make}} (not to confuse with GNUMake). DigitalMars is part of the DMD Windows distribution and should be part of your {{code|PATH}}. | ||
+ | |||
+ | If you have GNUMake installed on your system too, use the full path to DigitalMars make: {{code|C:\D\dmd2\windows\bin\make}}. | ||
+ | |||
+ | == Building with Visual Studio == | ||
+ | |||
+ | === Prerequisites === | ||
+ | |||
+ | * [https://visualstudio.microsoft.com/ Visual Studio] | ||
+ | * [https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk Window SDK] | ||
+ | * [https://dlang.org/download.html DMD Windows Installer] | ||
+ | * [https://rainers.github.io/visuald/visuald/StartPage.html VisualD] | ||
+ | |||
+ | === Instructions === | ||
+ | |||
+ | * Run the DMD Windows Installer and make sure that the binaries get added to the PATH (check "Add to Path") | ||
+ | * Install VisualD (can be done via the DMD installer with the "Download VisualD" checkbox) | ||
+ | * Make sure that dmd gets installed to {{code|C:\D\dmd2}} (the default) | ||
+ | |||
+ | === Clone repositories === | ||
+ | |||
+ | Next step is to clone the 3 necessary source repos, dmd, phobos, and tools. | ||
+ | |||
+ | <syntaxhighlight lang=dos> | ||
+ | mkdir C:\Source\D | ||
+ | cd C:\Source\D | ||
+ | git clone https://github.com/dlang/dmd | ||
+ | git clone https://github.com/dlang/phobos | ||
+ | git clone https://github.com/dlang/tools | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Make sure to pick a folder without white spaces or special characters to avoid any potential problems. | ||
+ | |||
+ | === Building DMD === | ||
+ | |||
+ | You should be able to build DMD using the visual studio solution found in: {{code|dmd\src\vcbuild}} | ||
+ | A typical choice is to build the 64-bit debug version (the VisualD options are named 'Release' and 'x64'). | ||
+ | |||
+ | A 'dmd.exe' should have been built and placed in {{code|C:\Source\D\dmd\generated\Windows\Debug\x64}}. | ||
+ | |||
+ | If you want the 32-bit counterparts, you will have to adjust accordingly. | ||
+ | Most notably, using win32.mak Makefiles instead of the win64.mak files. | ||
+ | |||
+ | === Building DRuntime === | ||
+ | |||
+ | Make sure that Visual Studio tools are part of your PATH. One common way is to run 'vcvarsall.bat'. | ||
+ | With Visual Studio 2017 this call is: | ||
+ | |||
+ | <syntaxhighlight lang=dos> | ||
+ | call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64 | ||
+ | </syntaxhighlight > | ||
+ | |||
+ | Now, go into druntime: | ||
+ | |||
+ | <syntaxhighlight lang=dos> | ||
+ | cd C:\source\D\dmd\druntime | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Then compile with DigitalMars make (not to confuse with GNUMake). | ||
+ | |||
+ | <syntaxhighlight lang=dos> | ||
+ | set VCDIR="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC" | ||
+ | make -f win64.mak -j4 "VCDIR=%VCDIR%" target | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | For building on 32-bit with the Visual Studio Runtime, use {{code|MODEL=32mscoff}}. | ||
+ | |||
+ | === Building Phobos === | ||
+ | |||
+ | <syntaxhighlight lang=dos> | ||
+ | cd C:\source\D\phobos | ||
+ | make -f win64.mak -j4 target | ||
+ | </syntaxhighlight> | ||
== Building D == | == Building D == | ||
+ | |||
+ | These instructions use the dmc tool chain. | ||
+ | |||
+ | === Prerequisites === | ||
+ | |||
+ | On Windows, you will need [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 in {{code|C:\D\dmd2\src}} which has the following structure: | ||
+ | <syntaxhighlight lang=dos> | ||
+ | C:\D\dmd2\src\dmd | ||
+ | C:\D\dmd2\src\phobos | ||
+ | C:\D\dmd2\src\tools | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Note: tools is optional. | ||
+ | |||
+ | Alternatively, you may wish to clone the git repositories for each of the above using [https://git-scm.com/ Git for Windows]. | ||
+ | |||
+ | ==== git Configuration ==== | ||
+ | |||
+ | When cloning from the GitHub repositories you may encounter problems if your git configuration on Windows replaces line endings with the Windows variant (i.e. {{code|\r\n}}) instead of leaving it as {{code|\n}}, which is what D repositories require. | ||
+ | |||
+ | To check your settings, run {{code|git config core.autocrlf}}. If it prints {{code|true}}, set it to {{code|false}} with {{code|git config --global core.autocrlf false}}. | ||
+ | |||
+ | === Before you start === | ||
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: | 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: | ||
Line 11: | Line 135: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | === 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 147: | ||
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% | + | set path=%DM_HOME%\dmd2\windows\bin;%path% |
+ | </syntaxhighlight> | ||
+ | |||
+ | 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> | </syntaxhighlight> | ||
− | + | === 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 167: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | ==== Missing sppn.exe or cl.exe ==== | |
+ | |||
+ | * For 32-bit if you don't have sppn.exe then probably dmc is not correctly installed. Download dmc.zip and replace your {{code|dm}} directory. | ||
+ | * If you are using win64.mak, you may need to download bup.zip and merge the {{code|dm}} folders. | ||
+ | Both zip files can be found here: | ||
+ | http://ftp.digitalmars.com/ | ||
+ | |||
+ | === 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 184: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | You should copy | + | 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 | + | 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 | ||
Line 67: | Line 225: | ||
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'''. | 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'''. | ||
+ | |||
+ | === Command prompt === | ||
It's also recommended that you use the cmd.exe terminal. Others, like PowerShell, are known to experience issues with legacy tools. | It's also recommended that you use the cmd.exe terminal. Others, like PowerShell, are known to experience issues with legacy tools. | ||
Line 79: | Line 239: | ||
on each component before starting the process. | on each component before starting the process. | ||
+ | |||
+ | === Using DigitalMars <code>make</code> for running the test suite === | ||
+ | |||
+ | DMD's testsuite can't be run with DigitalMars <code>make</code> - use GNUMake. | ||
+ | Refer to the instructions in [[DMD_development#Running_the_testsuite_on_Windows | Running the test suite on Windows]]. | ||
== Where to go from here == | == Where to go from here == | ||
− | If you want to contribute to a D project, please continue with the [[Starting_as_a_Contributor | + | If you want to contribute to a D project, please continue with the [[Starting_as_a_Contributor| starting as a contributor]] guide. |
If you want to contribute to Phobos, you may also read the [[Contributing to Phobos|contributing to Phobos guide]]. | If you want to contribute to Phobos, you may also read the [[Contributing to Phobos|contributing to Phobos guide]]. | ||
+ | |||
+ | [[Category:Windows]] |
Latest revision as of 18:14, 23 January 2023
Contents
Automation
Digger can checkout and build any D version automatically for you. Only a D compiler is required. Digger will download all required dependencies by itself.
dub fetch digger
dub run digger
Among many other features, Digger can build older compiler versions or versions with a specific pull request added:
# build a specific D version
$ dub run digger -- build v2.064.2
# build for x86-64
$ dub run digger -- build --model=64 v2.064.2
# build commit from a point in time
$ dub run digger -- build "@ 3 weeks ago"
# build specified branch from a point in time
$ dub run digger -- build "2.065 @ 3 weeks ago"
# build with an added pull request
$ dub run digger -- build "master + dmd#123"
Use Digital Mars make
This page needs DigitalMars make (not to confuse with GNUMake). DigitalMars is part of the DMD Windows distribution and should be part of your PATH.
If you have GNUMake installed on your system too, use the full path to DigitalMars make: C:\D\dmd2\windows\bin\make.
Building with Visual Studio
Prerequisites
Instructions
- Run the DMD Windows Installer and make sure that the binaries get added to the PATH (check "Add to Path")
- Install VisualD (can be done via the DMD installer with the "Download VisualD" checkbox)
- Make sure that dmd gets installed to C:\D\dmd2 (the default)
Clone repositories
Next step is to clone the 3 necessary source repos, dmd, phobos, and tools.
mkdir C:\Source\D
cd C:\Source\D
git clone https://github.com/dlang/dmd
git clone https://github.com/dlang/phobos
git clone https://github.com/dlang/tools
Make sure to pick a folder without white spaces or special characters to avoid any potential problems.
Building DMD
You should be able to build DMD using the visual studio solution found in: dmd\src\vcbuild A typical choice is to build the 64-bit debug version (the VisualD options are named 'Release' and 'x64').
A 'dmd.exe' should have been built and placed in C:\Source\D\dmd\generated\Windows\Debug\x64.
If you want the 32-bit counterparts, you will have to adjust accordingly. Most notably, using win32.mak Makefiles instead of the win64.mak files.
Building DRuntime
Make sure that Visual Studio tools are part of your PATH. One common way is to run 'vcvarsall.bat'. With Visual Studio 2017 this call is:
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
Now, go into druntime:
cd C:\source\D\dmd\druntime
Then compile with DigitalMars make (not to confuse with GNUMake).
set VCDIR="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC"
make -f win64.mak -j4 "VCDIR=%VCDIR%" target
For building on 32-bit with the Visual Studio Runtime, use {{{1}}}.
Building Phobos
cd C:\source\D\phobos
make -f win64.mak -j4 target
Building D
These instructions use the dmc tool chain.
Prerequisites
On Windows, you will need 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 in C:\D\dmd2\src which has the following structure:
C:\D\dmd2\src\dmd
C:\D\dmd2\src\phobos
C:\D\dmd2\src\tools
Note: tools is optional.
Alternatively, you may wish to clone the git repositories for each of the above using Git for Windows.
git Configuration
When cloning from the GitHub repositories you may encounter problems if your git configuration on Windows replaces line endings with the Windows variant (i.e. \r\n) instead of leaving it as \n, which is what D repositories require.
To check your settings, run git config core.autocrlf. If it prints true, set it to false with git config --global core.autocrlf false.
Before you start
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.110.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
Missing sppn.exe or cl.exe
- For 32-bit if you don't have sppn.exe then probably dmc is not correctly installed. Download dmc.zip and replace your dm directory.
- If you are using win64.mak, you may need to download bup.zip and merge the dm folders.
Both zip files can be found here: http://ftp.digitalmars.com/
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.110.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.110.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.
Command prompt
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.
Using DigitalMars make
for running the test suite
DMD's testsuite can't be run with DigitalMars make
- use GNUMake.
Refer to the instructions in Running the test suite on Windows.
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.