Compiling with gdc vs. gdmd

Daniel Green venix1 at gmail.com
Tue Apr 3 09:21:43 PDT 2012


My votes on waf.  So I think I'll share my experiences with it.

Several years ago I wanted a cross platform solution to handling project 
builds.  I had been using eclipse/CodeBlocks which worked OK for simple 
project but the lack of binary libraries for D and Windows combined made 
me desire something else.

When I first discovered waf, I recall it being explicitly stated the 
idea was to have a small binary that lives with the package.  The 
purpose was that every project could include it and no matter how many 
Waf releases later it will still compile.  That philosophy sort of goes 
against the idea of packaging it, as any project that uses it should 
contain it's own copy.

Over the years I found it does it's job quite well.  I've been using it 
exclusively for larger D projects and I keep the binary as part of the 
repository.

Other than it being a python script, which attempts to be platform 
neutral by design.  My favorite feature is the automatic dependency 
feature.  Working with Windows, D in particular, means I have to build 
both the C/C++ library as well as the D glue code.

I find it simple enough, since waf is python, to replicate the build 
process of other software that I can compile the library and then use 
the uselib feature to have it used by my final executable.  When dealing 
with external dependencies, it's even possible to store just the waf 
build script and download the library source separately.  If you wanted 
to get fancy you could make waf download it instead.

I've even made it do something crazy like using D compiler specific to 
it's project for compiling the source.  That was as trivial as doing 
this at the top of the file.

os.environ["PATH"] = "C:/GDC-Tango/mingw/bin"
os.environ["CPATH"] = "C:/GDC-Tango/mingw/include"


With that said, I do find the lack actual use documentation annoying. 
It took me about an hour to figure out how the new uselib system worked. 
  But it seems to be improving.  I tend to copy my own scripts and strip 
it down to the core commands when I need one.

I'll even include a sample wscript file.  This is what I use when 
starting a new project with waf.  This is essentially a Makefile and 
doesn't utilize any of the advanced api.

-- Dummy wscript --
#waf configure
#waf build

import os, sys

top = '.'
out = 'build'

src_files = [
     'src.d',
]

def options(opt):
     # build options go here
     pass

def configure(conf):
     #conf.check_tool('dmd')
     conf.check_tool('gdc')
     conf.check_tool('gcc')

     # Windows support
     if sys.platform == 'win32':
         conf.env.DFLAGS_WIN32       = ['-v2', '-m32', 
'-fversion=EnableVararg']
         conf.env.LINKFLAGS_WIN32    = ['-v2', '-m32']
         conf.env.LIB_WIN32          = ['user32', 'gdi32']

     if sys.platform == 'linux2':
         conf.env.LIB_LINUX2 = ['dl', 'GL']

def build(bld):
# Search external dir for wscript or wscript_build
#    bld.add_subdirs('subdir')

     example = bld.new_task_gen(
         features        = 'd dprogram',
         source          = ['main.d' + src_files],
         target          = 'example',
         importpaths     = '.',
         # I don't think theirs an equivalent yet.
         #defines        = ['WINDOWS=1'], # Equivalent?
         dflags          = '-fversion=Static -g -v',
         libpaths        = '',
         libs            = '',
         use             = 'libsubdir derelict',
         uselib          = 'TANGO WIN32 LINUX2',
     )



More information about the D.gnu mailing list