|
|
(79 intermediate revisions by 23 users not shown) |
Line 1: |
Line 1: |
− | If you're looking for a stable version of D, you probably want to download the [http://dlang.org/download.html official releases]. This page is for those who want to try out D on platforms that aren't yet officially supported, those who are adventurous and wish to try out the latest development (unstable!) version of D, and developers who wish to contribute to D development.
| + | #REDIRECT [[Starting as a Contributor#Building from source]] |
− | | |
− | ==Getting the sources==
| |
− | | |
− | ===Official releases===
| |
− | | |
− | The official release of DMD is available from the [http://dlang.org/download.html official download page].
| |
− | | |
− | ===Latest git===
| |
− | | |
− | This is for those who want to test or contribute to the development version of D. The latest source code for the D compiler, runtime library, and standard library are available on [https://github.com/D-Programming-Language GitHub]. To build a working D compiler toolchain, you will need to checkout at least dmd, druntime, and phobos.
| |
− | | |
− | ==Source code structure==
| |
− | | |
− | The D source code assumes a particular directory structure, which you probably would want to adopt so that you don't have to fiddle with the Makefiles all the time.
| |
− | | |
− | ===Posix===
| |
− | | |
− | For Posix, it is assumed that you will have a common root directory where the compiler and library sources will sit under. For example, you can choose the common root directory to be /usr/src/d, then you can checkout the sources under this directory:
| |
− | | |
− | <syntaxhighlight lang=bash>
| |
− | mkdir /usr/src/d
| |
− | cd /usr/src/d
| |
− | git clone git://github.com/D-Programming-Language/dmd.git
| |
− | git clone git://github.com/D-Programming-Language/druntime.git
| |
− | git clone git://github.com/D-Programming-Language/phobos.git
| |
− | </syntaxhighlight>
| |
− | | |
− | '''Note:''' if you're planning to submit [[Pull Requests|pull requests]], you should replace the above URLs with the URLs for your ''fork'' of the official sources, not the official sources themselves.
| |
− | | |
− | You should end up with this directory structure:
| |
− | | |
− | <pre>
| |
− | /usr/src/d/
| |
− | /usr/src/d/dmd
| |
− | /usr/src/d/druntime
| |
− | /usr/src/d/phobos
| |
− | </pre>
| |
− | | |
− | ===Windows===
| |
− | | |
− | For windows, you can follow the first posix steps regarding checking out files from github.
| |
− | | |
− | You can checkout the sources wherever you like. If we call {{code|%DM_HOME%}} the root path, the it is ''recommended'' to have this structure:
| |
− | | |
− | <pre>
| |
− | %DM_HOME%\dmd2\src
| |
− | %DM_HOME%\dmd2\src\dmd
| |
− | %DM_HOME%\dmd2\src\druntime
| |
− | %DM_HOME%\dmd2\src\phobos
| |
− | </pre>
| |
− | | |
− | Additionally, you should extract the digital mars compiler inside {{code|%DM_HOME%}}, alongside {{code|dmd2}}. You should finally create a {{code|windows directory with a {{code|bin}} and {{code|lib}} directory inside it. Your final structure should look like this:
| |
− | | |
− | <pre>
| |
− | %DM_HOME%\dm
| |
− | %DM_HOME%\dmd2\src
| |
− | %DM_HOME%\dmd2\src\dmd
| |
− | %DM_HOME%\dmd2\src\druntime
| |
− | %DM_HOME%\dmd2\src\phobos
| |
− | %DM_HOME%\dmd2\windows
| |
− | %DM_HOME%\dmd2\windows\bin
| |
− | %DM_HOME%\dmd2\windows\lib
| |
− | </pre>
| |
− | | |
− | ==Building the sources==
| |
− | | |
− | ===Posix===
| |
− | | |
− | Assuming your sources are checked out in /usr/src/d, you can do the following to build them:
| |
− | | |
− | <syntaxhighlight lang=bash>
| |
− | cd /usr/src/d/dmd/src
| |
− | make -f posix.mak
| |
− | cd ../../druntime
| |
− | make -f posix.mak
| |
− | cd ../phobos
| |
− | make -f posix.mak
| |
− | </syntaxhighlight>
| |
− | | |
− | Note that the compiler, runtime library, and standard library have to be built in that order, as each depends on the previous one.
| |
− | | |
− | If you're using a 64-bit platform, you may want to append "MODEL=64" to your make commands, as the default makefiles will build for 32-bit:
| |
− | | |
− | <syntaxhighlight lang=bash>
| |
− | cd /usr/src/d/dmd/src
| |
− | make -f posix.mak MODEL=64
| |
− | cd ../../druntime
| |
− | make -f posix.mak MODEL=64
| |
− | cd ../phobos
| |
− | make -f posix.mak MODEL=64
| |
− | </syntaxhighlight>
| |
− | | |
− | Parallel make can drastically speed up compilation times. The -j<integer> option allows you to specify the number of job slots. Number_of_cores + 1 is a often a good choice E.g.:
| |
− | | |
− | <syntaxhighlight lang=bash>
| |
− | make -f posix.mak -j5
| |
− | </syntaxhighlight>
| |
− | | |
− | for a machine with 4 cores.
| |
− | | |
− | After building, you should have a working D compiler in /usr/src/d/dmd/src/dmd. You may need to edit dmd.conf so that the compiler can find druntime and phobos. ('''TBD''': expand on this)
| |
− | | |
− | You should probably also run the unittests to make sure your build is working correctly:
| |
− | | |
− | <syntaxhighlight lang=bash>
| |
− | cd ../druntime
| |
− | make -f posix.mak -j5 unittest
| |
− | cd ../phobos
| |
− | make -f posix.mak -j5 unittest
| |
− | </syntaxhighlight>
| |
− | | |
− | (Running the unittests with -j is recommended if you have a multicore CPU, as some of them may take a while to run.)
| |
− | | |
− | ===Windows===
| |
− | The following instructions work for win32. May or may not work with win64. This scheme is a suggestion.
| |
− | | |
− | 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:
| |
− | | |
− | <syntaxhighlight lang=dos>
| |
− | set DM_HOME=C:\D
| |
− | cd %DM_HOME%\dmd2\src\dmd\src
| |
− | make -fwin32.mak -release
| |
− | </syntaxhighlight>
| |
− | | |
− | 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>
| |
− | copy *.exe %DM_HOME%\dmd2\windows\bin
| |
− | set path=%path%;%DM_HOME%\dmd2\windows\bin
| |
− | </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}}, instead of writing your own.
| |
− | | |
− | Now build druntime:
| |
− | <syntaxhighlight lang=dos>
| |
− | cd %DM_HOME%\dmd2\src\druntime
| |
− | make -fwin32.mak
| |
− | </syntaxhighlight>
| |
− | | |
− | And phobos:
| |
− | <syntaxhighlight lang=dos>
| |
− | cd %DM_HOME%\dmd2\src\phobos
| |
− | make -fwin32.mak
| |
− | </syntaxhighlight>
| |
− | | |
− | You should copy the phobos lib into your {{code|windows\lib}} folder:
| |
− | <syntaxhighlight lang=dos>
| |
− | copy phobos.lib %DM_HOME%\dmd2\windows\lib
| |
− | </syntaxhighlight>
| |
− | | |
− | Optionally, you can build rdmd from source if you have checked out {{code|tools}} in your sources:
| |
− | <syntaxhighlight lang=dos>
| |
− | cd %DM_HOME%\dmd2\src\tools
| |
− | make -fwin32.mak rdmd.exe
| |
− | copy *.exe %DM_HOME%\dmd2\windows\bin
| |
− | </syntaxhighlight>
| |
− | | |
− | 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}} package (without overwriting your {{code|phobos.lib}})
| |
− | | |
− | The very last step is to verify that everything works by unittesting phobos:
| |
− | | |
− | <syntaxhighlight lang=dos>
| |
− | cd %DM_HOME%\dmd2\src\phobos
| |
− | make -fwin32.mak unittest
| |
− | </syntaxhighlight>
| |