haskell-packages

Haskell suite library for package management and integration with Cabal

http://documentup.com/haskell-suite/haskell-packages

Version on this page:0.4
LTS Haskell 9.21:0.5
Stackage Nightly 2017-07-25:0.5
Latest on Hackage:0.6.2

See all snapshots haskell-packages appears in

MIT licensed by Roman Cheplyaka
Maintained by Roman Cheplyaka
This version can be pinned in stack with:haskell-packages-0.4@sha256:f38d24e4d1b501a650f1251e2bcb5e189bbf7efad08266600670f10e91326f4d,1654

There are two cases when you may need haskell-packages: if you are writing a Haskell compiler (or any tool that processes Haskell source code, such as a static analyzer), or if you want to integrate with an existing Haskell compiler that uses haskell-packages.

Writing a compiler

If you are writing a compiler, you typically want to integrate it with Cabal, to be able to build ordinary Haskell packages.

If you go the hard way, this involves:

  1. Parsing command line parameters. Sounds easy — just take a list of files to compile. In reality you also need to handle package ids and package dbs, CPP options (-DFOO=1), language extension flags (-XRankNTypes) etc.

    To integrate with Cabal, you also need to tell it the list of installed packages, supported languages and extensions etc.

  2. Actual integration with Cabal means understanding how Cabal works and hard-coding support for your compiler. And then getting it accepted and waiting for the next Cabal release.

    You may pretend that you are GHC or other compiler that is already supported by Cabal. It might work, but often it won’t, for various reasons. Also, GHC’s command line protocol is quite complex.

  3. Package management. You need to implement a package db mechanism, which would let you to keep track of installed packages. Then you’d have to implement a ghc-pkg-like tool to manage those databases, for both Cabal and your users.

Or, you can simply use this library!

It already has command line options parsing, Cabal support, and package management. All you need to do is to provide the function to do actual compilation and tell a couple of other things about your compiler. See the Distribution.HaskellSuite.Compiler module for details.

Using other compilers

Some compilers produce artifacts that you may want to use. A good example is the hs-gen-iface compiler from haskell-names which generates an interface for each module — the set of all named entities (functions, types, classes) that are exported by that module. This information can be then used either by other compilers, or by tools like IDEs.

Assuming the compiler uses haskell-packages and exports its database type, it’s very easy to use its artifacts. See Distribution.HaskellSuite.Packages for package resolution and Distribution.HaskellSuite.Modules for module resolution.

Usage

First, make sure that you have cabal-install from git:

git clone [email protected]:haskell/cabal.git
cd cabal
(cd Cabal && cabal install)
(cd cabal-install && cabal install)

To compile a Haskell package using a haskell-packages tool:

cabal install --haskell-suite -w $TOOL

where $TOOL may be either a full path to the compiler, or just an executable name if it’s in $PATH.

Maintainers

Roman Cheplyaka is the primary maintainer.

Adam Bergmark is the backup maintainer. Please get in touch with him if the primary maintainer cannot be reached.

Changes

Changes

Version 0.4

Update to Cabal-1.24. Update to aeson-0.11.0.0.

Version 0.3

Update to Cabal-1.22.

Change the format of on-disk JSON interface files.

Version 0.2.4.4

Put upper bound on Cabal

Version 0.2.4.3

Update to optparse-applicative 0.11

Version 0.2.4.2

Update to optparse-applicative 0.10

Version 0.2.4.1

Fix a bug with empty CPP defines (such as -DFOO)

Version 0.2.4

  • Add customMain
  • Fix a bug where only one of multiple output files with the same base name but different extensions would be copied on installation

Version 0.2.3.4

Depend on either instead of EitherT

Version 0.2.3.3

The fixed version of 0.2.3.2. (The released tarball for 0.2.3.2 contained some unintended changes.)

Version 0.2.3.2

Drop upper version bound on aeson.

Version 0.2.3.1

  • Upgrade to optparse-applicative 0.6
  • Provide the --help option for subcommands

Version 0.2.3

Relax Cabal dependency constraint to include Cabal-1.14

Version 0.2.2

Add mtl instances (MonadState, MonadReader etc.) for the ModuleT transformer.

Version 0.2.1

Dummy release to force rebuild on hackage (now that haskell-src-exts 1.14 is released).

Version 0.2

  • Compiler now accepts the --package-name argument, to specify the name of the package being compiled. CompileFn is changed accordingly.
  • Add support for relative paths in package databases.