[Haskell-cafe] Cabal, lib and exe in one

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Tue May 1 19:33:18 EDT 2007

On Tue, 2007-05-01 at 22:29 +0100, Magnus Therning wrote:

> >So if foo.hs is in test-src and Foo/Bar.hs is in src then I think you
> >just need:
> >
> >hs-source-dirs: test-src, src
> No, that's not enough, I also have to add the following lines to make
> the executable compile and link:
>   extensions: ForeignFunctionInterface
>   c-sources: csrc/ptrace.c
> That is, I end up compiling the library a second time!  Can't I get the
> executable to link against the library that was just created?

> I was just expecting to not have to repeat myself in the cabal file.
> Not such a strange thing to expect from a build system, I think :-)

Yes this is an interesting question about what it means to have programs
in the same cabal package as an executable.

Currently having a executable and a library inside a cabal package is
not the same thing as having a library package and separate package that
contains only that executable. The difference is that when the
executable is in the same cabal package it merely has access to the same
modules, it doesn't 'depend' on that library package exactly. So for
example it can access modules which are not exposed by the library and
indeed it can compile those same modules with completely different build
flags. So currently those modules will be built twice.

It's not clear to me that this is the right meaning, or indeed that we
should allow multiple entries in a single .cabal file. I think it might
be better to just have multiple .cabal files (possibly in the same
directory). Then we could be explicit and state that an executable
depends on the library or if we want to use different build flags, or
use modules that are not exposed by the lib then we can do that and only
in that case do we build those modules twice.

> Also, I don't really see what you mean by "that dir can be placed
> anywhere by the user".  That dir is created as part of the build
> process and it's location is, AFAICS, always going to be ./dist/build.

Actually it's location can be set at configure time with --scratchdir=
so that for example you could put it in a temp dir or something. 


More information about the cabal-devel mailing list