1 Title: Hacking druntime
2 Tags: en, d, dgc, druntime, patch, howto
4 I've been reading the source code of the druntime_, and it's time to get my
5 hands dirty and do some real work.
7 First I have to do to start hacking it is build it and start trying things out.
8 There is no documentation at all yet, so I finally bothered `Sean Kelly`_ and
9 asked him how to get started.
11 Here is what I had to do to get druntime_ compiled:
13 First of all, I'll introduce my environment and tools. I'll use DMD_ because
14 there's no other option for now (druntime_ doesn't have support for GDC_, but
15 Sean says it's coming soon, and LDC will not be included until the support it's
16 added to Tango_ runtime).
18 The trunk__ in the druntime_ repository__ is for D2, but there is a `branch for
21 __ http://www.dsource.org/projects/druntime/browser/trunk
22 __ http://svn.dsource.org/projects/druntime/
23 __ http://www.dsource.org/projects/druntime/browser/branches/D1.0
25 I use Debian_ (so you'll see some ``apt`` stuff here) and I love git_, and
26 there's is no way I will go back to subversion_. Fortunately there is
27 `git-svn`_, so that's what I'm gonna use =)
29 Now, what I did step by step.
31 #. Get the git_ goodies::
33 sudo aptitude install git-core git-svn
35 #. Make a directory where to put all the D-related stuff::
40 #. Get D2 (bleeding edge version) and unpack it::
42 wget http://ftp.digitalmars.com/dmd.2.026.zip
43 unzip dmd.2.020.zip # "install" the D2 compiler
44 rm -fr dm dmd/linux/bin/{sc.ini,readme.txt,*.{exe,dll,hlp}} # cut the fat
45 chmod a+x dmd/linux/bin/{dmd,rdmd,dumpobj,obj2asm} # make binaries executable
46 mv dmd dmd2 # reserve the dmd directory for D1 compiler
48 #. Make it accessible, for example::
50 echo '#!/bin/sh' > ~/bin/dmd2 # reserve dmd name for the D1 compiler
51 echo 'exec ~/d/dmd2/linux/bin/dmd "$@"' >> ~/bin/dmd2
54 #. Get D1 and *install* it too::
56 wget http://ftp.digitalmars.com/dmd.1.041.zip
58 rm -fr dm dmd/linux/bin/{sc.ini,readme.txt,*.{exe,dll,hlp}}
59 chmod a+x dmd/linux/bin/{dmd,rdmd,dumpobj,obj2asm}
60 echo '#!/bin/sh' > ~/bin/dmd
61 echo 'exec ~/d/dmd/linux/bin/dmd "$@"' >> ~/bin/dmd
64 #. Get druntime_ for D1 and D2 as separated repositories (you can get all in
65 one git repository using git branches but since I'll work on both at the
66 same time I prefer to use two separated repositories)::
68 git svn clone http://svn.dsource.org/projects/druntime/branches/D1.0 \
70 git svn clone http://svn.dsource.org/projects/druntime/trunk druntime2
72 #. Build druntime_ for D1::
78 #. Build druntime_ for D2.
80 This one is a little trickier. The trunk version have some changes for
81 a feature that is not yet released (``this`` being changed from a pointer to
82 a reference for structs). Fortunately this is well isolated in a single
83 commit, so reverting this change is really easy, first, get the abbreviated
84 hash for the commit 44::
87 git log --grep='trunk@44' --pretty=format:%h
89 This should give you a small string (mine is ``cae2326``). Now, revert that
94 Done! You now have that change reverted, we can remove this new commit later
95 when the new version of DMD that implements the ``this`` change appear.
97 But this is not all. Then I find a problem about redefining the ``Posix
100 Error: version identifier 'Posix' is reserved and cannot be set
102 To fix this you just have to remove the ``-version=Posix`` from
105 But there is still one more problem, but this is because I have renamed the
106 bianries to have both ``dmd`` and ``dmd2``. The compiler we have to use to
107 build things is called ``dmd2`` for me, but ``build-dmd.sh`` don't override
108 properly the ``DC`` environment variable when calling ``make``, so ``dmd``
111 This is a simple and quick fix::
113 diff --git a/src/build-dmd.sh b/src/build-dmd.sh
116 index d6be599..8f3b163
117 --- a/src/build-dmd.sh
118 +++ b/src/build-dmd.sh
119 @@ -11,9 +11,10 @@ goerror(){
123 -make clean -fdmd-posix.mak || goerror
124 -make lib doc install -fdmd-posix.mak || goerror
125 -make clean -fdmd-posix.mak || goerror
126 +test -z "$DC" && DC=dmd
127 +make DC=$DC clean -fdmd-posix.mak || goerror
128 +make DC=$DC lib doc install -fdmd-posix.mak || goerror
129 +make DC=$DC clean -fdmd-posix.mak || goerror
130 chmod 644 ../import/*.di || goerror
134 (to apply the patch just copy&paste it to ``fix.patch`` and then do ``git
135 apply fix.patch``; that should do the trick)
137 Now you can do something like this to build druntime_ for D2::
142 That's it for now. I'll be publishing my druntime_ (git) repository soon with
143 this changes (and probably submitting some patches to upstream) so stay tuned
146 .. _druntime: http://www.dsource.org/projects/druntime/wiki
147 .. _`Sean Kelly`: http://www.dsource.org/projects/tango/wiki/SeanK
148 .. _DMD: http://www.digitalmars.com/d/1.0/dmd-linux.html
149 .. _GDC: http://dgcc.sourceforge.net/
150 .. _Tango: http://www.dsource.org/projects/tango/wiki/
151 .. _Debian: http://www.debian.org/
152 .. _git: http://git.or.cz/
153 .. _subversion: http://subversion.tigris.org/
154 .. _git-svn: http://www.kernel.org/pub/software/scm/git/docs/git-svn.html
156 .. vim: set expandtab shiftwidth=2 :