Starting as a Contributor
This page contains a set of instructions that get anyone from having nothing D-related on their machine, to a full-blown development rig for the reference D compiler `dmd` and one or more of its paraphernalia: core runtime (aka druntime), standard library (aka phobos), website, and tools.
This tutorial is written for a Posix system (Linux, OSX, FreeBSD etc) and assumes you have make, g++, libcurl4-openssl-dev, and git up and running on your system, as well as a working github account. To install the appropriate code on e.g. Ubuntu:
sudo apt-get install make g++ libcurl4-openssl-dev git
1. Fetch dmd from github
Let's start by getting the current development (master) branch of dmd from github. Assume the root directory for everything D-related is ~/code (replace appropriately). This is easily done by running at a command prompt:
cd ~/code git clone https://github.com/D-Programming-Language/dmd
After this step completes successfully, the directory ~/code/dmd should be up and filled with good stuff.
2. Bootstrap dmd
This step is interesting because in order to build dmd, dmd is necessary. Fortunately, the steps of downloading and using a preexisting dmd compiler are automated. All you need to do is run this command:
cd ~/code/dmd make -f posix.mak AUTO_BOOTSTRAP=1
That's going to take a while. To make it faster, passing -j8 accelerates things by running eight processes in parallel. The build produces the compiler binary ~/code/dmd/src/dmd.
To make dmd builds faster in the future, you need to obviate the need for bootstrapping. Install dmd from the download page or simply put the freshly built dmd binary in a place accessible through $PATH (a popular choice is ~/bin).
3. Fetch and build druntime
druntime is the core runtime library for D, needed for building most every D program, including the standard library itself. So it's the next step in the progression. To fetch and build druntime, issue these commands:
cd ~/code git clone https://github.com/D-Programming-Language/druntime cd druntime make -f posix.mak
All that should go pretty fast. The somewhat anticlimactic result of the build is a library called libdruntime.a situated in an OS-dependent directory such as ~/code/druntime/generated/linux/release/64/. Make sure it's there.
4. Fetch and build phobos
Most D programs use D's standard library phobos. To get and build it:
cd ~/code git clone https://github.com/D-Programming-Language/phobos cd phobos make -f posix.mak
The build produces (with similar anticlimacticity) static and shared libraries such as ~/code/phobos/generated/linux/release/64/libphobos2.a and ~/code/phobos/generated/linux/release/64/libphobos2.so.
4.1. Unittest phobos
If you want to work on phobos itself, you need to run unittests—either for the full library, a package, or a module. To unittest the entire library:
make -j16 -f posix.mak unittest
Adjust the parameter passed to -j depending on your machine (beefier machines support larger parameters). This command unittests phobos in both debug and release mode. To only test one of them, add BUILD=debug or BUILD=release to the command line, for example:
make -j16 -f posix.mak BUILD=debug unittest
Specifying BUILD makes unittesting faster so it is recommended in iterative development. Just make sure both debug and release builds are tested before e.g. submitting a pull request.
While changing one specific package or module, it's useful to be able to only unittest that particular entity. The following two commands only unittest (in debug mode) the std.algorithm package and the std.conv module, respectively:
make -j16 -f posix.mak BUILD=debug std/algorithm.test make -j16 -f posix.mak BUILD=debug std/conv.test
Several modules, packages, or mix thereof may be specified for testing in the same command line. For example, this command also tests (and also in debug mode) the std.algorithm package and the std.conv module, with better parallelism:
make -j16 -f posix.mak BUILD=debug std/algorithm.test std/conv.test