Nice title, huh?
Descent plugin is being cooler and cooler, but you've probably seen it on
videos.
One of the things that was driving me mad and kept me away from descent was compilation process.
Java guys probably know apache ant build system (and if they don't they definitely should). I'm going to describe here, how to force eclipse to use descent plugin's ant tasks to build D projects. I'm using this at least for a few months now and I prefer it much more over rebuild method described on Descent page, I was wondering why this method is not described there.
First there are some basic informations, how to install descent with eclipse 3.4, how to set-up a project, the rest is about ant usage.
Eclipse/Descent basic stuff
I'm using Eclipse ganymede since it's better than its predecessors. First quick installation for all the lazy bastards out there:
- Go and grab eclipse, I've downloaded IDE for Java Developers since it has ant plugins ready to use.
(If you have eclipse installed already, you probably could just install apache ant stuff in software updates). - Unpack and start eclipse, choose workspace, go to Help -> Software updates, Available software
choose Add site and enter descent's site: http://downloads.dsource.org/projects/descent/update-site and OK, it should appear in the middle table, select it and Install, - After few clicks and minutes Descent should be installed and Eclipse will ask you for the start, do so
- When it'll start again close the welcome screen, and first of all, turn on D-perspective (Window->Open perspective->Other->D), if it's not there it means you haven't installed descent plugin properly
- Next we'll add tango to user libraries to make project configuration simpler. Go to Window->Preferences, choose D->Build path->User libraries, choose New and enter meaningful name (tango? :>), choose Add directory and select directory with your tango lib (I got it under /opt/dmd/include/d),
- Go to General->Editors->Text editor->Spelling, and disable spelling engine, otherwise you'll get most of the code red-underlined :]
- Choose File->New->Project, select D project, enter name (I've used DSample) and you can click Finish,
- Right click on your project, choose New->module, enter module name (I've used sample.d) (for simplicity everything will be in default package,
- Now in editor window type 'main' and press Ctrl+Space (you'll love this shortcut ;)), editor should show suggestions, after hiting Enter you'll have basic main function,
- If you try typing 'Std' [Ctrl+Space], you'll see there are no fancy proposals, right-mouse-click on your project, choose Build Path->Add Libraries, choose User Libraries, select tango (added in step 5) and click finish,
- Now after typing 'Std' [Ctrl+Space] you should see some proposals
Descent + ant, honey
One night I was playing with descent jar files and I've noticed interesting jar inside descent.core.
Open up your favourite terminal and extract needed jar.
- mkdir -p ~/.ant/lib
- cd ~/.ant/lib
- unzip ECLISPE_DIR/plugins/descent.core_0.5.3.20081231.jar ant_tasks/descent-ant.jar
ECLIPSE_DIR above is of course your eclipse installation dir (~/eclipse in my case :])
Now go back to eclipse, Window->Preferences, Ant->Runtime (Classpath), click Add External JARs and
add your ~/.ant/lib/descent-ant.jar archive.
Next go to Tasks menu we'll add two tasks:
I've entered name "descent.D", choose descent-ant.jar from drop-down list, and click on:
"/descent/ant/tasks" and choose "D.class"
Now do the same using "descent.DBldNum" and choose "DModuleBuildNumber.class" file.
We're going to create ant build file, but before that let's create build.properites file
that will held some basic data in easily editable format.
Press Ctrl+N, choose General->File, and enter build.properties as it's name.
Here is content of my properties file:
- compiler.dir = /opt
- compiler.type = dmd-linux
- src.dir = .
- dest.dir = bin
compiler.dir is a path to compiler (without dmd/bin/dmd, descent appends it)
Press Ctrl+N and in filter box type xml, and chose XML, click next, and enter build.xml as a filename,
Using bottom tabs choose Source instead of Design
I've created following build.xml (I'm not pasting it here, since
this would be quite senseless, but you can take a look at it at codepad.org.
Build file is specific for linux, if I remember correctly my build.xml under windows was simpler than that one.
As you see most of the file is definition of compile macro which takes one parameter (bldtrg). (EDIT: you can find list of all possible parameters for descent.D task here)
Let's forget about that macro for a moment and take a look down at possible targets:
- <target name="build-number">
- <descent.DBldNum file="${src.dir}/sample_bn.d" fqn="sample_bn" />
- </target>
- <target name="compile" depends="build-number" description="Compiles sample">
- <compile bldtrg="sample"/>
- </target>
This looks quite clean don't you think?
Now you could right-mouse-click on the build.xml file, choose Run-as ->Ant build file but this is uber-lame.
Instead go to Window->Show View->Other and select Ant. I like to keep this window in lower-wight corner.
Double click on any listed target will execute it (along with dependencies).
I have binded Ctrl+Shift+Q A to Show View (View: Ant), this way I can fast switch to ant window :).
What's cool about it is that you can have multiple build targets (one can build few executables) and have all of them visible
and easily accessible.
I'm not going to encourage anybody to use ant, but it's really cool tool, take a while to peek into ant's documentation, especially ant tasks.
gim.org.pl is down








