Testing druntime modifications
by Leandro Lucarella on 2008- 11- 30 03:51 (updated on 2008- 11- 30 03:51)- with 0 comment(s)
Now that we can compile druntime, we should be able to compile some programs that use our fresh, modified, druntime library.
Since DMD 2.021, druntime is built into phobos, so if we want to test some code we need to rebuild phobos too, to include our new druntime.
Since I'm particularly interested in the GC, let's say we want to use the GC stub implementation (instead of the basic default).
We can add a simple "init" message to see that something is actually happening. For example, open src/gc/stub/gc.d and add this import:
private import core.sys.posix.unistd: write;
Then, in the gc_init() function add this line:
write(1, "init\n".ptr, 5);
Now, we must tell druntime we want to use the stub GC implementation. Edit dmd-posix.mak, search for DIR_GC variable and change it from basic to stub:
DIR_GC=gc/stub
Great, now recompile druntime.
Finally, go to your DMD installation, and edit src/phobos/linux.mak. Search for the DRUNTIME variable and set it to the path to your newly generated libdruntime.a (look in the druntime lib directory). For me it's something like:
DRUNTIME=/home/luca/tesis/druntime/lib/libdruntime.a
Now recompile phobos. I have to do this, because my DMD compiler is named dmd2:
make -f linux.mak DMD=dmd2
Now you can compile some trivial D program (compile it in the src druntime directory so its dmd.conf is used to search for the libraries and imports) and see how "init" get printed when the program starts. For example:
druntime/src$ cat hello.d import core.sys.posix.unistd: write; void main() { write(1, "hello!\n".ptr, 7); } druntime/src$ dmd2 -L-L/home/luca/tesis/dmd2/lib hello.d druntime/src$ ./hello init hello!
Note that I passed my DMD compiler's lib path so it can properly find the newly created libphobos2.a.
druntime build system
by Leandro Lucarella on 2008- 11- 26 02:28 (updated on 2008- 11- 26 02:28)- with 0 comment(s)
I have to be honest on this one. I'm not crazy about the druntime build system. I know there are a lot of other more important thing to work on, but I can't help myself, and if I'm not comfortable with the build system, I get too much distracted, so I have no choice but to try to improve it a little =)
First, I don't like the HOME environment variable override hack in build-dmd.sh (I won't talk about the Windows build because I don't have Windows, so I can't test it).
So I've made a simple patch to tackle this. It just adds a dmd.conf configuration file in each directory owning a makefile. I think it's a fair price to pay adding this extra files to be hable to just use make and get rid of the build-dmd.sh script.
I've added a ticket on this and another related ticket with a patch too.
Getting started with druntime
by Leandro Lucarella on 2008- 11- 25 02:27 (updated on 2008- 11- 25 02:27)- with 0 comment(s)
I've added a brief draft about how to get started in the druntime wiki, which I plan to expand a little in the future.
I hope somebody find it useful.
BTW, the -version=Posix fix is now included in the main repo.
My druntime repository
by Leandro Lucarella on 2008- 11- 24 02:17 (updated on 2008- 11- 24 02:17)- with 0 comment(s)
I've finally published my own git druntime repository. It has both branches, the one for D2 (the svn trunk, called master in my repo) and the one for D1 (D1.0 in svn, d1 in my repo).
For now, there are only changes in the master branch.
Hacking druntime
by Leandro Lucarella on 2008- 11- 22 16:38 (updated on 2009- 03- 28 20:17)- with 0 comment(s)
I've been reading the source code of the druntime, and it's time to get my hands dirty and do some real work.
First I have to do to start hacking it is build it and start trying things out. There is no documentation at all yet, so I finally bothered Sean Kelly and asked him how to get started.
Here is what I had to do to get druntime compiled:
First of all, I'll introduce my environment and tools. I'll use DMD because there's no other option for now (druntime doesn't have support for GDC, but Sean says it's coming soon, and LDC will not be included until the support it's added to Tango runtime).
The trunk in the druntime repository is for D2, but there is a branch for D1 too.
I use Debian (so you'll see some apt stuff here) and I love git, and there's is no way I will go back to subversion. Fortunately there is git-svn, so that's what I'm gonna use =)
Now, what I did step by step.
Get the git goodies:
sudo aptitude install git-core git-svn
Make a directory where to put all the D-related stuff:
mkdir ~/d cd ~/d
Get D2 (bleeding edge version) and unpack it:
wget http://ftp.digitalmars.com/dmd.2.026.zip unzip dmd.2.020.zip # "install" the D2 compiler rm -fr dm dmd/linux/bin/{sc.ini,readme.txt,*.{exe,dll,hlp}} # cut the fat chmod a+x dmd/linux/bin/{dmd,rdmd,dumpobj,obj2asm} # make binaries executable mv dmd dmd2 # reserve the dmd directory for D1 compiler
Make it accessible, for example:
echo '#!/bin/sh' > ~/bin/dmd2 # reserve dmd name for the D1 compiler echo 'exec ~/d/dmd2/linux/bin/dmd "$@"' >> ~/bin/dmd2 chmod a+x ~/bin/dmd2
Get D1 and install it too:
wget http://ftp.digitalmars.com/dmd.1.041.zip unzip dmd.1.036.zip rm -fr dm dmd/linux/bin/{sc.ini,readme.txt,*.{exe,dll,hlp}} chmod a+x dmd/linux/bin/{dmd,rdmd,dumpobj,obj2asm} echo '#!/bin/sh' > ~/bin/dmd echo 'exec ~/d/dmd/linux/bin/dmd "$@"' >> ~/bin/dmd chmod a+x ~/bin/dmd
Get druntime for D1 and D2 as separated repositories (you can get all in one git repository using git branches but since I'll work on both at the same time I prefer to use two separated repositories):
git svn clone http://svn.dsource.org/projects/druntime/branches/D1.0 \ druntime git svn clone http://svn.dsource.org/projects/druntime/trunk druntime2
Build druntime for D1:
cd druntime bash build-dmd.sh cd -
Build druntime for D2.
This one is a little trickier. The trunk version have some changes for a feature that is not yet released (this being changed from a pointer to a reference for structs). Fortunately this is well isolated in a single commit, so reverting this change is really easy, first, get the abbreviated hash for the commit 44:
cd druntime2 git log --grep='trunk@44' --pretty=format:%h
This should give you a small string (mine is cae2326). Now, revert that change:
git revert cae2326
Done! You now have that change reverted, we can remove this new commit later when the new version of DMD that implements the this change appear.
But this is not all. Then I find a problem about redefining the Posix version:
Error: version identifier 'Posix' is reserved and cannot be set
To fix this you just have to remove the -version=Posix from build-dmd.sh.
But there is still one more problem, but this is because I have renamed the bianries to have both dmd and dmd2. The compiler we have to use to build things is called dmd2 for me, but build-dmd.sh don't override properly the DC environment variable when calling make, so dmd is used instead.
This is a simple and quick fix:
diff --git a/src/build-dmd.sh b/src/build-dmd.sh old mode 100644 new mode 100755 index d6be599..8f3b163 --- a/src/build-dmd.sh +++ b/src/build-dmd.sh @@ -11,9 +11,10 @@ goerror(){ exit 1 } -make clean -fdmd-posix.mak || goerror -make lib doc install -fdmd-posix.mak || goerror -make clean -fdmd-posix.mak || goerror +test -z "$DC" && DC=dmd +make DC=$DC clean -fdmd-posix.mak || goerror +make DC=$DC lib doc install -fdmd-posix.mak || goerror +make DC=$DC clean -fdmd-posix.mak || goerror chmod 644 ../import/*.di || goerror export HOME=$OLDHOME
(to apply the patch just copy&paste it to fix.patch and then do git apply fix.patch; that should do the trick)
Now you can do something like this to build druntime for D2:
export DC=dmd2 bash build-dmd.sh
That's it for now. I'll be publishing my druntime (git) repository soon with this changes (and probably submitting some patches to upstream) so stay tuned ;)