Pregunta

Is it possbile to write a Cabal configuration file, which contains multiple Library sections?

I found in the documentation the description of Library section and Executables sections, so it seems, that it is impossible to put more Library section in one Cabal configuration file.

But what should I do if I'm developing several Haskell libraries and several executables
simultaneously and want to compile and test them all?

¿Fue útil?

Solución 3

I found out, that my problem can be easly solved with the newest cabal-dev.

If you've got 2 projects: A and B and you want to develop them in parallel, its nice to use cabal-dev install A B - it will build and install them both to the local cabal-dev repository. If you re-run this command, they will be rebuilt and reinstalled if necessary.

According to the documentation - If you want to register new or override existing package on local cabal-dev hackage, you should use cabal-dev add-source, which basically copy the source and allows you to install it like it was available on hackage.

Otros consejos

AFAIK, you can't put more than one library in a cabal file. The name specified in the Name field (at the top level of the cabal file) is used as the name of the library, so there doesn't seem to be a mechanism for specifying names of additional libraries.

In practice, I haven't found this to be a problem. I develop each library in a separate directory, with its own cabal file. Once you run cabal install on a library you've developed, then it can be referenced in the cabal file for your executable (in the Build-Depends section), just the same as a package on Hackage.

So, for example, if you have two libraries with cabal files that look like this:

Name:              my-library-1
. . .

and

Name:              my-library-2
. . .

Then the cabal file for your executable can reference them like this:

Name:              my-program
. . .
Executable run-program
Main-Is:          Main.hs
Build-Depends:    my-library1,
                  my-library2,
                  . . .

You can even require specific versions of your libraries. For example:

Build-Depends:    my-library1==1.2.*,
                  my-library2>=1.3

This is possible in Cabal 2 with internal libraries, so called "convenience" libraries: https://github.com/haskell/cabal/pull/3022. This will not let you install these libraries though, they are just allowed to be composed into the final executables and public library exposed by a .cabal file. If you want to build multiple things in progress, you should use a cabal.project file - http://blog.ezyang.com/2016/05/announcing-cabal-new-build-nix-style-local-builds/ has some information on this.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top