cabal-helper: Give Haskell development tools access to Cabal project environment

[ apache, distribution, library ] [ Propose Tags ]

The purpose of the cabal-helper library is to give Haskell development tools access to the same environment which build tools such as cabal and stack normally provide to the compiler.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
dev

Build development components

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.0.1, 0.2.0.0, 0.3.0.0, 0.3.1.0, 0.3.2.0, 0.3.2.1, 0.3.3.0, 0.3.4.0, 0.3.5.0, 0.3.6.0, 0.3.7.0, 0.3.8.0, 0.3.9.0, 0.4.0.0, 0.5.0.0, 0.5.1.0, 0.5.2.0, 0.5.3.0, 0.6.0.0, 0.6.1.0, 0.6.2.0, 0.6.3.0, 0.6.3.1, 0.7.0.1, 0.7.1.0, 0.7.2.0, 0.7.3.0, 0.8.0.0, 0.8.0.1, 0.8.0.2, 0.8.1.0, 0.8.1.1, 0.8.1.2, 0.8.2.0, 1.0.0.0, 1.1.0.0 (info)
Dependencies base (>=4.9.1.0 && <5), bytestring (>=0.10.8.1 && <0.11), Cabal (>=1.24.2.0 && <1.26 || >=2.0 && <2.5 || >=3.0 && <3.4), cabal-plan (>=0.5.0.0 && <0.8), clock (>=0.7.2 && <0.9), containers (>=0.5.7.1 && <1), directory (>=1.3.0.0 && <1.4), filepath (>=1.4.1.1 && <1.5), ghc-prim, mtl (>=2.0 && <2.3), process (>=1.4.3.0 && <1.7), semigroupoids (>=5.2 && <5.4), semigroups (>=0.18 && <0.19), SHA (>=1.6.4.4 && <1.7), template-haskell (>=2.11.1.0 && <2.17), temporary (>=1.2.1 && <1.4), text (>=1.0.0.0 && <1.3), time (>=1.6.0.1 && <1.10), transformers (>=0.5.2.0 && <0.6), unix (>=2.7.2.1 && <2.8), unix-compat (>=0.4.3.1 && <0.6), utf8-string (>=1.0.1.1 && <1.1), Win32 (>=2.5.4.1 && <2.9) [details]
License Apache-2.0
Author Daniel Gröber <cabal-helper@dxld.at>
Maintainer cabal-helper@dxld.at
Revised Revision 1 made by DanielG at 2020-06-25T13:57:08Z
Category Distribution
Source repo head: git clone https://github.com/DanielG/cabal-helper.git
Uploaded by DanielG at 2020-05-02T17:31:01Z
Distributions
Reverse Dependencies 3 direct, 3 indirect [details]
Executables cabal-helper-main
Downloads 45817 total (57 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-05-02 [all 1 reports]

Readme for cabal-helper-1.1.0.0

[back to package description]

The cabal-helper library

build status

The purpose of the cabal-helper library is to give Haskell development tools access to the same environment which build tools such as cabal and stack normally provide to the compiler.

Introduction

In the Haskell ecosystem the most widely used build system is the Cabal library, not to be confused with the cabal build tool which is usually refered to by it's package-name: cabal-install to disambiguate.

All contemporary meta build tools such as cabal and stack as well as some custom Haskell build systems use the Cabal library as their foundation. For example the Glasgow Haskell Compiler's bespoke GNU Make based build system also utilises the Cabal library at its core.

We capitalize on this fact by using build information Cabal writes to disk as the common denominator between all Haskell build tools. This allows us to easily support a variety of build tools without incuring significant additional complexity.

Technical Background

Haskell Packages and Setup.hs

Essentially all Haskell packages implement "The Haskell Cabal" (pdf) packaging specification. The Cabal library and cabal-install build tool are named after this specification. Yes we really love confusing naming in Haskell land.

The specification revolves around this Setup.hs script file you might have seen before. Basically the idea is a Haskell source package consists of, at the very least, a Setup.hs file, which is a Haskell program that provides a well defined command-line interface for configuring, building and installing it. Haskell developers can use build tools, such as cabal, which interface with Setup.hs and provide functionality on top it.

Note that even though originally packages were meant to be free to implement the Setup.hs interface however they like, this hasn't been supported by build tools for a long time. In practice use of the Cabal library in Setup.hs is mandatory.

Now, the first step of building a package in "The Haskell Cabal" is to call Setup.hs's configure command:

$ runhaskell Setup.hs configure

When invoking Setup.hs the default behaviour of the Cabal library is to first read the <pkg-name>.cabal configuration file to determine how the project is structured and what dependencies it has. In the case of configure it will then probe the system it's running on about:

  • the list of available Haskell packages,
  • system package dependencies (using pkg-config) and
  • Haskell compiler type, version and supported language extensions (among other things).

Finally Haskell package dependency resolution is also run.

Cabal then writes all the gathered information on the concrete configuration of the package into a file called setup-config. Subsequent steps, such asrunhaskell Setup.hs build, will then read this state file instead of <package-name>.cabal to avoid having to probe the system or run dependency resolution again.

It is this file that cabal-helper is primarily concerned with reading and presenting in a usable manner. Reading this file essentially means that all the complicated work has already been done for us and we can get straight to running the compiler.

Multi-package projects

So far so good. That's pretty much the end of the story for the traditional cabal build commands but what about cabal new-build and Stack I hear you asking?

Well, essentially both new-build and Stack simply build on top of the traditional Setup.hs interface. So the setup-config file is still there in all it's glory, we just have to deal with more than one of it since both build-tools support multiple packages and Setup.hs only knows how to deal with a single package at a time.

To support this cabal-helper has grown a representation of what a project is in it's API starting with the 1.0 series. We currently support both new-build and Stack. The API is designed to allow extending support to custom build systems such as GHC's but we have not done this yet.

The "Helper" in cabal-helper

In the API docs you will find frequent mentions of "the helper executable" so I'll explain what that is here because it is quite fundamental to how things work in the codebase.

The fundamental problem cabal-helper solves is the fact that in order to access the data Cabal stores in the setup-config file we have to link against lib:Cabal. However the binary format of this file is unstable and there is no backwards compatibility mechanism in the library. So to read a setup-config file produced by a certain version of Cabal we have to link against exactly that version.

Not only that but usally the cabal commandline tool controls which Cabal library version is used, so we really just have to deal with whatever we get.

To solve this problem the cabal-helper library builds a small executable at runtime who's only purpose is to link against lib:Cabal, read the contents of setup-config and present the data there in a Cabal version independent format for consumption by the cabal-helper library.

Recently some work was merged into cabal to have Setup.hs to do this natively (https://github.com/haskell/cabal/pull/5954), we're planning to use this eventually to replace our "helper".

IRC

If you have any problems, suggestions, comments swing by #ghc-mod (web client) on Freenode. If you're reporting a bug please also create an issue here so we have a way to contact you if you don't have time to stay.

Do hang around for a while if no one answers and repeat your question if you still haven't gotten any answer after a day or so. You're most likely to get an answer during the day in GMT+1.