Difference between revisions of "Building under Posix"

From D Wiki
Jump to: navigation, search
(linux-libc-dev:i386 is needed to prevent complaints about a missing asm/errno.h)
m (Remove partial phrase 'On Windows, you will need')
Line 41: Line 41:
  
 
To make <tt>dmd</tt> builds faster in the future, you need to obviate the need for bootstrapping. Install <tt>dmd</tt> from the [http://dlang.org/download.html download page] or simply put the freshly built <tt>dmd</tt> binary in a place accessible through <tt>$PATH</tt> (a popular choice is <tt>~/bin</tt>).
 
To make <tt>dmd</tt> builds faster in the future, you need to obviate the need for bootstrapping. Install <tt>dmd</tt> from the [http://dlang.org/download.html download page] or simply put the freshly built <tt>dmd</tt> binary in a place accessible through <tt>$PATH</tt> (a popular choice is <tt>~/bin</tt>).
 
On Windows, you will need
 
  
 
==== Fetch and build <tt>druntime</tt> ====
 
==== Fetch and build <tt>druntime</tt> ====

Revision as of 03:02, 15 October 2016

Prerequisites

To build D on POSIX, you will need to have make, g++, libcurl4-openssl-dev, and git installed on your system, as well as a working GitHub account. To install the appropriate dependencies on e.g. Ubuntu:

sudo apt-get install curl git make g++ libcurl4-openssl-dev

On OS X with Homebrew:

$ xcode-select --install
$ brew install git openssl

To build the 32-bit phobos on a 64-bit machine, some 32-bit packages are also needed:

sudo apt-get install gcc-multilib libc6-dev-i386 linux-libc-dev:i386 libcurl4-gnutls-dev:i386

Other versions and variations of libcurl may work as well.

Building D

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/dlang/dmd

After this step completes successfully, the directory ~/code/dmd should be up and filled with good stuff.

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).

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 (note that it requires a properly built dmd, so make sure the above steps have completed successfully). To fetch and build druntime, issue these commands:

cd ~/code
git clone https://github.com/dlang/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. This library is made available to your applications through Phobos, so you must follow the next step to reflect any changes to druntime in your application.

Fetch and build phobos

Most D programs use D's standard library phobos. To get and build it, make sure you first fetch and build the latest dmd and druntime. Then:

cd ~/code
git clone https://github.com/dlang/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.

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.