Setting up a proper D working environment
We all know that D is not yet a very mature platform (although it is making steps quickly into the right direction). Because of that, it is not that easy to setup a working (or development) environment. Here are my efforts to clarify the situation. The difficulty in reaching this goal lies mainly in the incompatibilities between libraries and compiler versions (or implemented features).
I will try to show how I managed to install a (more or less) complete working environment for D under Linux using either DMD or GDC. These two compilers each have their pros and cons: DMD is more stable and has the latest features integrated, while GDC is completely open source. By “complete” I mean the following packages were installed and running smoothly (I won’t loose time to justify why I wanted each one - they simply make sense to have, pretty much all the time - in no particular order):
1. DSSS 0.71 (D Shared Software System) - link.
2. DMD 1.018 - link / GDC 0.24 / rev.146 (GCC 4.1.2) - link.
3. Tango rev.2500 (The modern standard library for D) - link.
4. Tangobos rev.15 (Phobos and Tango compatibility layer) - link.
5. Mango rev.1037 (Network programming library) - link.
6. DDL rev.285 (Dynamic run-time linking of executables) - link.
7. DDBI rev.59 (D DataBase Interface) - link.
Nota bene:
- You need curl, wget, svn and gcc build tools for these tutorials and scripts to work.
- There are some commands that download files from the internet. These files will be upgraded in time naturally so there’s no guarantee that this will work without some tweaking required. However, I also provided two scripts (see download link at the beginning of each chapter) that do not install any packages using the “dsss net install” and will only install exactly the versions mentioned above (to ensure that they work)! I’ll try to keep them updated. So if you choose to follow the tutorial manually, be prepared to tweak the code a little.
- Respect the order of the operations below!
- This document assumes that the “sudo” command works on your system and that you have “sudo” rights for your own user.
- I have tried to use the bundled packages from the Tango website (that come with DSSS, DMD/GDC and Tango bundled) but the whole thing is not that simple and to add further tools to the system was almost impossible.
- You need an Internet connection for this to work.
- These command should be taken as guidelines, they may differ for your system.
- Both scripts ran perfectly on two of my Ubuntu Feisty 7.04 systems.
So, without further blabber, let’s get right to the point:
Chapter One
DMD 1.018 running on
Ubuntu Linux 7.04 (Feisty Fawn)
Download the automated script for this chapter (recommended!).
This is by no means easy. Be prepared to follow these instructions well!
1. Create a new host directory
Explanation: This is important because the best way to install D is to do so in a relatively isolated manner (meaning not in /usr/local/bin or something similar). That way, if you go wrong somewhere it will be very easy to retry: just delete the host directory and start from the beginning. Also, this way you do not have to work as root, at any time during development, which is highly recommended.
In my case, I created the “usr” directory in my home directory (this will be filled with a directory structure similar to that of “/usr”):
> cd /home/valeriupalos > mkdir usr > cd usr
From now on everything should take place inside this directory. If something goes wrong, you can delete it and restart from the top.
2. Install DSSS
DSSS must be the first one to install. So download it (the DMD version):
> wget "http://svn.dsource.org/projects/dsss/downloads/0.71/
dsss-0.71-dmd-gnuWlinux-x86.tar.gz"
and then unpack it’s contents right in the current directory (and delete the archive):
> tar -zxvf dsss-0.71-dmd-gnuWlinux-x86.tar.gz > mv dsss-0.71-dmd-gnuWlinux-x86/* . > rmdir dsss-0.71-dmd-gnuWlinux-x86/ > rm dsss-0.71-dmd-gnuWlinux-x86.tar.gz
Then you must add the “/home/valeriupalos/usr/bin” path to your system-wide PATH variable:
> PATH=/home/valeriupalos/usr/bin:$PATH > export PATH
Now if you run “echo $PATH” you sould get something like the following:
> echo $PATH /home/valeriupalos/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin: /usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games
The first part is what we wanted. You must also append this commend at the end of an autoload script (which is being run by the system at startup) so that the addition is permanent; this is usually “~/.bash_profile”:
> echo "PATH=/home/valeriupalos/usr/bin:$PATH" >> ~/.bash_profile > echo "export PATH" >> ~/.bash_profile
And voila! You can now run “dsss” at the command line and see if it runs.
3. Install DMD
DMD should now install beautifully using dsss like this:
> dsss net install dmd
It will ask you to choose between a set of (probably two) mirrors (this will only happen once). Just choose the first one (or whatever). At the end of the process DMD will be installed (run “dmd” and see if it works).
4. Install Tango
Tango should install perfectly fine using dsss. Just run:
> dsss net install tango
It will ask you to type “yes” to confirm you want to do this because this process will overwrite the integrated Phobos library completely. At the end of the process Tango will be installed.
5. Install DDBI
DDBI should install perfectly fine using dsss. Just run:
> dsss net install ddbi
That’s it.
6. Install Tangobos
Tangobos must be installed manually since there is no repository for it under DSSS. So download it from the SVN into the share subdirectory (this is where we will put all manually installed packages from now on):
> cd share > svn co "http://svn.dsource.org/projects/tangobos/trunk/" tangobos
…then build and install it using dsss and return to the share subdirectory:
> cd tangobos > dsss build > dsss install > cd ..
and that’s it. Tangobos is installed and ready to fill the gap between Phobos and Tango! This is very important for installing DDL utilities but also for other packages as well.
7. Install Mango
To install Mango we must do it manually because there is a small modification we need to make to it’s code (because of some changes made in the installed version Tango). So first we download it from the SVN:
> svn co "http://svn.dsource.org/projects/mango/trunk/" mango
… and then we make the change
> cd mango/xml/rpc > mv Client.d Client.d.old > sed 's/client.disconnect;$/client.close;/' Client.d.old > Client.d > cd ../..
Lastly we make the install using dsss and return to “share”:
> dsss build > dsss install > cd ..
At the end of the process Mango will be installed.
8. Install DDL and utilities
To install DDL you must first install the DDL import files and then the DDL utilities (which assist in the creation of run-time libraries). So first download it from the SVN repo (you should be in the “share” subdirectory):
> cd tangobos > dsss build > dsss install > cd ..
At this point there need to be done a small modification to the DDL source so that it will work with the Tango library through the Tangobos compatibility layer. This must be done in the “ddl/ddl/insitu” subdirectory, in the file “InSituLibBinary.d” at the begining (line 27, change “etc.zlib” to “std.zlib”):
> cd ./ddl/ddl/insitu > mv InSituLibBinary.d InSituLibBinary.d.old > sed 's/etc.zlib/std.zlib/' InSituLibBinary.d.old >InSituLibBinary.d > cd ../../..
After this you must copy the required import files to the D import path used by DSSS (remember that you should be in the “share” subdirectory):
> cp -r ddl/ddl ../include/d > cp -r ddl/etc ../include/d > cp -r ddl/meta ../include/d > cp -r ddl/utils ../include/d
Now we have to compile the DDL utils. We want to use DSSS for this so we open the required “dsss.conf” file inside the “share/ddl/utils” using a text editor:
> cd ./ddl/utils > gedit dsss.conf
…and copy the following text into it:
[bless.d] target=bless [insitu.d] target=insitu [ddlinfo.d] target=ddlinfo
…then save and close. Now we can build and install the tools using DSSS:
> dsss build > dsss install
And now the DDL package and utilities should be installed properly on your system. You can call one of the utilities (like “insitu”) from the command line to see if they work.
That’s it for this one!
Chapter Two
GDC 0.24 (snapshot) running on
Ubuntu Linux 7.04 (Feisty Fawn)
Download the automated script for this chapter (recommended!).
The installation explanation repeates some of the texts written at Chapter One (above) so that you don’t have to scroll your brains out just to get a piece of little info that was there and isn’t here!
1. Create a new host directory
Explanation: This is important because the best way to install D is to do so in a relatively isolated manner (meaning not in /usr/local/bin or something similar). That way, is you go wrong somewhere it will be very easy to retry: just delete the host directory and start from the beginning. Also, this way you do not have to work as root, at any time during development, which is highly recommended.
In my case, I created the “usr” directory in my home directory (this will be filled with a directory structure similar to that of “/usr”):
> cd /home/valeriupalos > mkdir usr > cd usr
From now on everything should take place inside this directory. If something goes wrong, you can delete it and restart from the top.
2. Install DSSS
DSSS must be the first one to install. So download it (the GDC version):
> wget "http://svn.dsource.org/projects/dsss/downloads/0.71/
dsss-0.71-gdc-gnuWlinux-x86.tar.gz"
…and then unpack it’s contents right in the current directory (and delete the archive):
> tar -zxvf dsss-0.71-gdc-gnuWlinux-x86.tar.gz > mv dsss-0.71-gdc-gnuWlinux-x86/* . > rmdir dsss-0.71-gdc-gnuWlinux-x86/ > rm dsss-0.71-gdc-gnuWlinux-x86.tar.gz
Then you must add the “/home/valeriupalos/usr/bin” path to your system-wide PATH variable:
> PATH=/home/valeriupalos/usr/bin:$PATH > export PATH
Now if you run “echo $PATH” you sould get something like the following:
> echo $PATH /home/valeriupalos/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin: /usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games
The first part is what we wanted. You must also append this commend at the end of an autoload script (which is being run by the system at startup) so that the addition is permanent; this is usually “~/.bash_profile”:
> echo "PATH=/home/valeriupalos/usr/bin:$PATH" >> ~/.bash_profile > echo "export PATH" >> ~/.bash_profile
And voila! You can now run “dsss” at the command line and see if it runs.
3. Install GDC
Pay attention here! To install GDC the way we need (so that it will allow us to install all other packages) you must first download and unpack the GCC 4.1.2 core source. To do this you can run the commands below (you can choose another GCC mirror and replace the address for GCC download to increase the speed). First we have to move in the “share” subdirectory:
> cd share > wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.1.2/gcc-core-4.1.2.tar.bz2 > tar -jxvf gcc-core-4.1.2.tar.bz2 > rm gcc-core-4.1.2.tar.bz2
Then we need to download the GDC source from the SVN repository, right in the “gcc” subdirectory of the GCC core:
> svn co https://dgcc.svn.sourceforge.net/svnroot/dgcc/trunk
gcc-4.1.2/gcc
Now we have to make some patching work on the GDC part:
> cd gcc-4.1.2 > ./gcc/d/setup-gcc.sh
And now we have to configure and build the whole thing. Make sure that the “--prefix” directory is exactly the one created at point 1, and without any expansion characters (i.e. without any tilde “~”). Just use the full path:
> ./configure --prefix=/home/valeriupalos/usr --enable-languages=d > make > make install
… now go watch a movie or something. This will take a while.
WARNING!!!
On many systems there was a real problem with this compilation. If compilation fails at the “make” command with the following output (the red part is important) then this is your case (it does happen on Ubuntu 7.04), if not just skip this whole warning. Here’s the output:... checking If /home/valeriupalos/usr/share/gcc-4.1.2/ host-i686-pc-linux-gnu/gcc/gdc -B/home/valeriupalos/ usr/share/gcc-4.1.2/host-i686-pc-linux-gnu/gcc/ -B/home/valeriupalos/usr/i686-pc-linux-gnu/bin/ -B/home/valeriupalos/usr/i686-pc-linux-gnu/lib/ -isystem /home/valeriupalos/usr/i686-pc-linux-gnu/ include -isystem /home/valeriupalos/usr/ i686-pc-linux-gnu/sys-include can compile D sources... /home/valeriupalos/usr/share/gcc-4.1.2/ host-i686-pc-linux-gnu/gcc/cc1d: libgcc_s.so.1: version `GCC_4.2.0′ not found (required by /usr/lib/libstdc++.so.6) no configure: error: can’t compile D sources! make[1]: *** [configure-target-libphobos] Error 1 make[1]: Leaving directory `/home/valeriupalos/usr/share/gcc-4.1.2′ make: *** [all] Error 2This problem is worse than you think, but it has a solution and it really works well. The problem is that the gcc has compiled a version of “libgcc_s.so.1″ which does not include some symbols required by your system’s “libstdc++.so.6″ library (I don’t know why this is, because in fact they really should be compatible). The trick is to copy into our gcc compilation the “libgcc_s.so.1″ file that your system uses, which is usually located under the top level directory named “/lib” (if not just do a system-wide search for it). All this happens inside the subdirectory that is coloured with green in the output above (might differ slightly for you). So here it is:
> cd ./host-i686-pc-linux-gnu/gcc > cp /lib/libgcc_s.so.1 .After we copy it, we must tell our gcc not to re-compile this file by slightly changing the “Makefile” for this library (at line 525 change “LIBGCC = libgcc.a” to just “LIBGCC = “).
> mv Makefile Makefile.old > sed 's/LIBGCC = libgcc.a/LIBGCC = /' Makefile.old > Makefile > cd ../..Now re-run the make process (it will continue from where it left off), and then go back to our “usr” directory:
> make > make install > cd ../..And now it should be okay to continue.
END OF WARNING!!!
At this point GDC is installed, but not completely. Though the “make install” command did copy the compiled import files to the needed destination, it copied them in a subdirectory called “/home/valeriupalos/usr/include/d/4.1.2″ and we need them straight into “/home/valeriupalos/usr/include/d”. So we have fix that (but still keep “4.1.2″ as a symlink because our GDC compilation actually does use it too):
> cd ./include/d > mv 4.1.2/* . > rmdir 4.1.2 > ln -s . 4.1.2 > cd ../..
And finally, the GDC is installed (Thank God!). Note that if you want you can now delete the “…/share/gcc-4.1.2″ subdirectory (it gets pretty big).
4. Install Tango
To install Tango on top of our GDC we first download and unpack it:
> cd share > svn co "http://svn.dsource.org/projects/tango/trunk/" tango
Then we apply the patch for GDC 0.24 and we make a small modification to the “dsss.conf” file (erase the “exclude = tango/net/cluster” line):
> cd tango > patch -p0 < patches/GDC-0.24-SVN-r139.diff > mv dsss.conf dsss.conf.old > sed 's/exclude = tango\/net\/cluster//' dsss.conf.old > dsss.conf
Now we must build and install the tango core like so:
> cd lib > ./build-gdc.sh > ./install-gdc.sh > cd ..
The we use dsss to build and install tango itself:
> dsss build > dsss install > cd ..
Tango should now be installed, but not completely. What’s left is for the rebuild tool (what dsss uses behind the scenes) to be configured to link Tango files correctly so that following programs will be properly linked to Tango objects. To do this, we edit the “/home/valeriupalos/usr/etc/rebuild/default” file to use the “gdc-posix-tango” profile instead of just “gdc-posix” (return to”…/usr/share” afterwards):
> cd ../etc/rebuild > mv default default.old > sed 's/gdc-posix$/gdc-posix-tango/' default.old > default > cd ../../share
And that’s it!
5. Install DDBI
DDBI should install perfectly fine using dsss. Just run:
> dsss net install ddbi
It will ask you to choose between a set of (probably two) mirrors (this will only happen once). Just choose the first one (or whatever). That’s it.
6. Install Mango
To install Mango we must do it manually because there is a small modification we need to make to it’s code (because of some changes made in the installed version Tango). So first we download it from the SVN:
> svn co "http://svn.dsource.org/projects/mango/trunk/" mango
… and then we make the change
> cd mango/xml/rpc > mv Client.d Client.d.old > sed 's/client.disconnect;$/client.close;/' Client.d.old > Client.d > cd ../..
Lastly we make the install using dsss and return to “share”:
> dsss build > dsss install > cd ..
At the end of the process Mango will be installed.
7. Install Tangobos
Tangobos must be installed manually since there is no repository for it under DSSS. So download it from the SVN into the share subdirectory (this is where we will unpack all manually installed packages from now on):
> svn co "http://svn.dsource.org/projects/tangobos/trunk/" tangobos
…then build and install it using dsss and return to the share subdirectory:
> cd tangobos > dsss build > dsss install > cd ..
and that’s it. Tangobos is installed and ready to fill the gap between Phobos and Tango! This is very important for installing DDL utilities but also for other packages as well.
8. Install DDL and utilities
To install DDL you must first install the DDL import files and then the DDL utilities (which assist in the creation of run-time libraries). So first download it from the SVN repo (you should be in the “share” subdirectory):
> svn co "http://svn.dsource.org/projects/ddl/trunk/" ddl
At this point there need to be done a small modification to the DDL source so that it will work with the Tango library through the Tangobos compatibility layer. This must be done in the “ddl/ddl/insitu” subdirectory, in the file “InSituLibBinary.d” at the begining (line 27, change “etc.zlib” to “std.zlib”):
> cd ./ddl/ddl/insitu > mv InSituLibBinary.d InSituLibBinary.d.old > sed 's/etc\.zlib/std\.zlib/' InSituLibBinary.d.old >InSituLibBinary.d > cd ../..
Now a series of patches must be made to the DDL code for it to work with our GDC and Tangobos:
> mv ./ddl/DDLException.d ./ddl/DDLException.d.old
> sed 's/fmt,_arguments,_argptr/fmt,_arguments,cast(void*)_argptr/'
./ddl/DDLException.d.old > ./ddl/DDLException.d
> mv ./ddl/omf/OMFException.d ./ddl/omf/OMFException.d.old
> sed 's/fmt,_arguments,_argptr/fmt,_arguments,cast(void*)_argptr/'
./ddl/omf/OMFException.d.old > ./ddl/omf/OMFException.d
> cd ..
After this you must copy the required import files to the D import path used by DSSS (remember that you should be in the “share” subdirectory):
> cp -r ddl/ddl ../include/d > cp -r ddl/etc ../include/d > cp -r ddl/meta ../include/d > cp -r ddl/utils ../include/d
Now we have to compile the DDL utils. We want to use DSSS for this so we open the required “dsss.conf” file inside the “share/ddl/utils” using a text editor:
> cd ./ddl/utils > gedit dsss.conf
…and copy the following text into it:
[bless.d] target=bless [insitu.d] target=insitu [ddlinfo.d] target=ddlinfo
…then save and close. Now we can build and install the tools using DSSS:
> dsss build > dsss install
And now the DDL package and utilities should be installed properly on your system. You can call one of the utilities (like “insitu”) from the command line to see if they work.
That’s it for this one too!
So, there you are, installation walkthroughs for both DMD and GDC under Linux. I’m pretty certain that this can be done on Windows as well but I’m exausted. If there are any completions you might add to this please post them here. Maybe you can help me improve on the automated scripts by testing (or making them work) on your system(s). Thanks!
Hope this helps, I got really tired writing it (my eyes hurt)! Going to sleeeep…..
Enjoyed this post?, why not subscribe to the RSS feed!
August 26th, 2007 at 9:45 am
[…] decided (after writing the last post on this subject) that it is much more feasible to simply continue working on my install scripts […]