]> git.llucax.com Git - personal/website.git/blob - source/blog/posts/2008/11/testing-druntime-modifications.rst
Update resume with The Podcast App
[personal/website.git] / source / blog / posts / 2008 / 11 / testing-druntime-modifications.rst
1 Title: Testing druntime modifications
2 Tags: en, d, dgc, druntime, phobos, howto
3
4 Now that we can compile druntime_, we should be able to compile some programs
5 that use our fresh, modified, druntime_ library.
6
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_.
9
10 __ http://www.digitalmars.com/d/2.0/changelog.html#new2_021
11
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).
14
15 __ http://www.dsource.org/projects/druntime/browser/trunk/src/gc/stub
16 __ http://www.dsource.org/projects/druntime/browser/trunk/src/gc/basic
17
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::
20
21     private import core.sys.posix.unistd: write;
22
23 __ http://www.dsource.org/projects/druntime/browser/trunk/src/gc/stub/gc.d
24
25 Then, in the ``gc_init()`` function add this line::
26
27     write(1, "init\n".ptr, 5);
28
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**
31 to **stub**::
32
33     DIR_GC=gc/stub
34
35 __ http://www.dsource.org/projects/druntime/browser/trunk/src/dmd-posix.mak
36
37 Great, now recompile druntime_.
38
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
42 something like::
43
44     DRUNTIME=/home/luca/tesis/druntime/lib/libdruntime.a
45
46 __ http://www.dsource.org/projects/phobos/browser/trunk/phobos/linux.mak
47
48 Now recompile phobos_. I have to do this, because my DMD compiler is named
49 ``dmd2``::
50
51     make -f linux.mak DMD=dmd2
52
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
56 example::
57
58     druntime/src$ cat hello.d
59
60     import core.sys.posix.unistd: write;
61
62     void main()
63     {
64         write(1, "hello!\n".ptr, 7);
65     }
66
67     druntime/src$ dmd2 -L-L/home/luca/tesis/dmd2/lib hello.d
68     druntime/src$ ./hello
69     init
70     hello!
71
72 Note that I passed my DMD compiler's lib path so it can properly find the newly
73 created ``libphobos2.a``.
74
75
76 .. _druntime: http://www.dsource.org/projects/druntime
77 .. _phobos: http://www.dsource.org/projects/phobos
78
79 .. vim: set et sw=4 sts=4 :