Development/Tasks/Packaging/Policies/Haskell

From Mandriva Community Wiki

Jump to: navigation, search


Contents


Haskell packaging

Cabal

Haskell modules are normally provides with the Cabal packaging system. This allow to any devellopers to:

  • manage compilation
  • manage modules dependencies
  • install the module
  • produce script to register the module in the compiler database
  • build tarball

So, all haskell module normally have a common scheme about their build

The haskell Cabal

Hackage Database

Haskell devellopers are encouraged to upload their module on the hackage database. Only packages matchings Cabal rules can be upload, moreover some extra checks are performed to ensure the quality of the packages.

Packaging

Package name

The package name must match the module name prefixed by haskell-.

Macros

For many packages, rpm specfile will be similar as they use all the same build system.

So it is really easy to have rpm macros and make the packaging task easy. The package haskell-macros provides a set of macros to help to make rpm packages:

macro usage
%_cabal_build perform the complete build of the haskell module (configure, build, haddock), typically used in %build section
%_cabal_install perform the the installation into the %buildroot (copy), typically use in %install section
%_cabal_check run the test suite of the module, typically use in %check section
%_cabal_genscripts create the register.sh and unregister.sh use to register the module on the system
%_cabal_scriptlets this macros is an alias for post install scriptlets, using files created by %_cabal_genscripts

All theses macros assume the cabal startup script provides is named Setup.hs, sometimes it is named Setup.lhs. To override the default value, just redefine %_cabal_setup to the program filename provided with the module:

%define _cabal_setup Setup.lhs

Dependencies

Haskell module have their own dependencies, and it is important to not break it, otherwise you will not be able to use it.

But it is impossible to find theses dependencies from the file installed in the %buildroot.

However the cabal system provides a way to find to find them. So we'll have to provide in the rpm additionnals files only to keep a track of rpm dependencies. haskell-macros provides two rpm macros to do the bad work:

macro usage
%_cabal_rpm_gen_deps to run at the end of %install step, will create a set of files containing our rpm dependencies according cabal information
%_cabal_rpm_files add this macros in the %files section containing modules files (.hi and .o)

Rpm dependencies are created by cabalrpmdeps.

A complete example

specfile of hslogger

%define module filepath

Name: haskell-%{module}
Version: 0.11
Release: %mkrel 4
Summary: Library for manipulating FilePath's in a cross platform way.
Group: Development/Other
License: BSD3
Url: http://www-users.cs.york.ac.uk/~ndm/projects/libraries.php
Source: http://www.cs.york.ac.uk/fp/release/%{module}-0.11.tar.bz2
BuildRoot: %_tmppath/%name-%version-%release-root
BuildRequires: haskell-macros
BuildRequires: ghc

%description
Library for manipulating FilePath's in a cross platform way.

%prep
%setup -q -n %{module}

%build
%_cabal_build

%_cabal_genscripts

%check
%_cabal_check

%install
%_cabal_install

rm -fr %{buildroot}/%_datadir/*/doc/

%_cabal_rpm_gen_deps

%_cabal_scriptlets

%files
%defattr(-,root,root)
%doc dist/doc/html
%_libdir/*
%_cabal_rpm_files

%clean
rm -fr %buildroot

Comment about this specfile

  • This specfile use cabal, but is not conform to the hackage specification (the tarball is named module_version, not module-version, the builddir is "module", not "module-version"
  • We trash %{buildroot}/%_datadir/*/doc/ to provides files a %doc from the dist/ directory.

Comments

Limits

  • Only ghc is really supported currently
  • What about biarch ? Is it really usefull ?

To do

One of big improvement would be to support other compilers than ghc, but we are faced to a problem: how to properly build the module for all available compilers ? What are those compilers (not all exist on all architectures).

Related tools

There some projects to write spec files from cabal information. This is a good idea because .cabal files contains everything we need, including buildrequires. Unfortunatelly, no one will match our scheme, but as it is quite easy to, I do plan to do it (Cabal rpm is a start, but should match hackage namespaec policy).

Personal tools