1 Title: Testing druntime modifications
2 Tags: en, d, dgc, druntime, phobos, howto
4 Now that we can compile druntime_, we should be able to compile some programs
5 that use our fresh, modified, druntime_ library.
7 Since `DMD 2.021`__, druntime_ is built into phobos_, so if we want to test
8 some code we need to rebuild phobos_ too, to include our new druntime_.
10 __ http://www.digitalmars.com/d/2.0/changelog.html#new2_021
12 Since I'm particularly interested in the GC, let's say we want to use the GC
13 stub__ implementation (instead of the basic__ default).
15 __ http://www.dsource.org/projects/druntime/browser/trunk/src/gc/stub
16 __ http://www.dsource.org/projects/druntime/browser/trunk/src/gc/basic
18 We can add a simple *"init"* message to see that something is actually
19 happening. For example, open `src/gc/stub/gc.d`__ and add this import::
21 private import core.sys.posix.unistd: write;
23 __ http://www.dsource.org/projects/druntime/browser/trunk/src/gc/stub/gc.d
25 Then, in the ``gc_init()`` function add this line::
27 write(1, "init\n".ptr, 5);
29 Now, we must tell druntime_ we want to use the *stub* GC implementation. Edit
30 `dmd-posix.mak`__, search for ``DIR_GC`` variable and change it from **basic**
35 __ http://www.dsource.org/projects/druntime/browser/trunk/src/dmd-posix.mak
37 Great, now recompile druntime_.
39 Finally, go to your DMD installation, and edit `src/phobos/linux.mak`__. Search
40 for the ``DRUNTIME`` variable and set it to the path to your newly generated
41 ``libdruntime.a`` (look in the druntime_ ``lib`` directory). For me it's
44 DRUNTIME=/home/luca/tesis/druntime/lib/libdruntime.a
46 __ http://www.dsource.org/projects/phobos/browser/trunk/phobos/linux.mak
48 Now recompile phobos_. I have to do this, because my DMD compiler is named
51 make -f linux.mak DMD=dmd2
53 Now you can compile some trivial D program (compile it in the ``src``
54 druntime_ directory so its ``dmd.conf`` is used to search for the libraries
55 and imports) and see how *"init"* get printed when the program starts. For
58 druntime/src$ cat hello.d
60 import core.sys.posix.unistd: write;
64 write(1, "hello!\n".ptr, 7);
67 druntime/src$ dmd2 -L-L/home/luca/tesis/dmd2/lib hello.d
72 Note that I passed my DMD compiler's lib path so it can properly find the newly
73 created ``libphobos2.a``.
76 .. _druntime: http://www.dsource.org/projects/druntime
77 .. _phobos: http://www.dsource.org/projects/phobos
79 .. vim: set et sw=4 sts=4 :