I’ve recently been having a deeper look into the D programming language, because writing a JIT on top of .NET turned out to be extremely hard without interfering with the .NET runtime. I didn’t quite want to use C, as that’s too low-level for the stuff I’m doing, and C++ is just broken. D seems to be both languages done right, and so I settled on that.
You can program D perfectly fine with the latest Digital Mars D (DMD) release, but I ended up having to contribute some patches to the standard libraries, and figured I might as well build everything from source.
First, you’re going to need Git, as everything is hosted on GitHub.
Next, do the following clones:
- /usr/src/dmd -> https://github.com/D-Programming-Language/dmd.git
- /usr/src/druntime -> https://github.com/D-Programming-Language/druntime.git
- /usr/src/phobos -> https://github.com/D-Programming-Language/phobos.git
- /usr/src/dtools -> https://github.com/D-Programming-Language/tools.git
In all of the makefiles, the MODEL variable specifies what bitness to build for. Here, I’m going to build for x86-64, so I’ll use 64. To build for x86, just use 32.
To build DMD, do:
cd /usr/src/dmd/src; gmake -f posix.mak MODEL=64;
Everything should Just Work in the compile process. I’m using gmake because the makefiles are designed for GNU Make, and some systems don’t map make to that by default.
Unfortunately, DMD (and related repositories) don’t have any standard install target that we can use, so we’re just going to copy things into the file system. I’m using /usr/local/bin, /usr/local/lib, and /usr/local/include:
cp dmd /usr/local/bin;
Verify that you have a DMD matching your system’s bitness:
dmd;
This should print:
DMD64 D Compiler v2.055
DMD32 should be printed for a 32-bit installation.
You need to add a configuration file for DMD. Add the following to /etc/dmd.conf:
[Environment] DFLAGS=-I/usr/local/include/d2 -L-L/usr/local/lib -L--no-warn-search-mismatch -L--export-dynamic
Now to build the core runtime libraries:
cd /usr/src/druntime; gmake -f posix.mak MODEL=64 DMD=../dmd/src/dmd;
If the build succeeds, we can copy the resulting interface files to our file system:
mkdir /usr/local/include/d2; cp -r import/* /usr/local/include/d2;
Next, we build Phobos, which is the standard library containing facilities for concurrency, regular expressions, I/O, signals, math, text manipulation, and so on:
cd /usr/src/phobos; gmake -f posix.mak MODEL=64 DMD=../dmd/src/dmd;
Again, we copy library and interface files:
cp generated/linux/release/64/libphobos2.a /usr/local/lib; cp -r std /usr/local/include/d2; cp -r etc /usr/local/include/d2;
In the copy command for libphobos2.a, replace 64 with 32 if you built for x86.
With these in place, we should be able to build the additional D utilities:
cd /usr/src/dtools; dmd ddemangle.d; dmd rdmd.d; cp ddemangle /usr/local/bin; cp rdmd /usr/local/bin;
You should now have a fully functional installation of DMD! Feel free to post here if you run into trouble, or have some tip you’d like added to this tutorial.
I’d like to extend a thank you to everyone on #d @ irc.freenode.net for putting up with my questions. You guys are awesome. :)
I tend to use dmd as a local installation – i.e., I just add the bin directory of the binary distribution to my PATH. In order to do that here, I guess I’d either have to hard-code the include/lib paths when compiling dmd, or set those in my .profile along with PATH. Instructions for that kind of build would be appreciated.
I’m not actually sure how to specify the output path of the DMD build; what you could do is point your path to the DMD src directory. That’s not quite pretty, but it’s all I can suggest right now. :(
Oh Joy! I have been wanting to seriously learn D and use it personal projects, but could never get the combination of D2, 64-bit, dmd (not gdc) and phobos to work. This post had the critical bit of know-how for reaching this D programming heaven. Thanks. Now I’m off to do some image processing…
Can’t get this to work… is “cp std /usr/local/include/d2;” supposed to be “cp -r std/* /usr/local/include/d2;”? And what about dmd.conf?
Fixed that plus some other silly typos. Thanks!
a very vanilla example of dmd.conf can be found here:
http://www.d-programming-language.org/dmd-linux.html#dmd_conf
where ever you actually put the phobos and druntime builds you should include paths to those locations in dmd.conf in /etc (or $HOME)
mine looks like this to support the installation described on this page:
; dmd.conf file for dmd
; Names enclosed by %% are searched for in the existing environment
; and inserted. The special name %@P% is replaced with the path
; to this file.
[Environment]
DFLAGS=-I/usr/local/include/d2 -I/usr/local/include/d2/core -I/usr/local/include/d2/std
Oh, thanks for mentioning that! You shouldn’t have to list /std and /core in there, though, as those are picked up automagically as long as the parent directory is listed.