Difference between revisions of "Cabal"

From HaskellWiki
Jump to navigation Jump to search
 
(Remove the most egregiously outdated links (several less outdated links remain))
 
(39 intermediate revisions by 11 users not shown)
Line 1: Line 1:
The Haskell Cabal
+
The Haskell Cabal:
  +
:The '''C'''ommon '''A'''rchitecture for '''B'''uilding '''A'''pplications and '''L'''ibraries
The Common Architecture for Building Applications and Libraries
 
   
 
http://www.haskell.org/cabal/
 
http://www.haskell.org/cabal/
   
  +
== Summary ==
= Building Dlls on Windows with Cabal =
 
  +
* Cabal is a package and build system. Cabal is only involved in the creation of packages and the building of their contents. It does not manage packages.
Cabal does not currently support building dlls on windows out of the box. Some details about why can be found here:
 
  +
* [[Cabal-Install]] installs cabal packages. It is distinct from Cabal (the build system). This often confuses new users. Furthermore, Cabal-Install is not a fully featured package manager. For example, it cannot install non cabal packaged dependencies, it cannot uninstall packages, nor can it automatically upgrade installations.
http://www.haskell.org/ghc/docs/6.4.2/html/users_guide/packages.html
 
http://www.haskell.org/ghc/docs/6.4.2/html/users_guide/win32-dlls.html
 
   
  +
== Information for package users ==
This means that we have to do a bit of hackery to get Cabal to build a dll from a library. As long as we build a single DLL from the entire project the dll should behave as expected.
 
   
  +
*[https://cabal.readthedocs.io/en/latest/index.html Cabal User Guide]
The following Setup.lhs should do the trick for most projects which consist of a single library which needs to be built as a dll. If you need to specify a dll export file you'll need to modify the function <tt>cmd</tt> to take this into account.
 
  +
*[http://dev.stephendiehl.com/hask/#cabal An introduction to cabal-install]
  +
*[[Cabal/FAQ|FAQ: Frequently Asked Questions]]
  +
*[[Cabal-Install]] - tool that greatly simplifies installation of Cabal packages
  +
*[http://hackage.haskell.org/package/cabal-sort Cabal-Sort] - assistance with compilation of multiple cabal packages
  +
*[http://hackage.haskell.org/ Hackage] - the Haskell community's public repository of cabal packages
  +
* Other [https://hackage.haskell.org/packages/search?terms=cabal cabal related packages on hackage]
   
  +
== Information for package developers ==
<haskell>
 
  +
*[[How to write a Haskell program]]
#! /usr/bin/runghc
 
  +
*[https://wewantarock.wordpress.com/2010/11/03/building-a-shared-library-in-cabal/ Building a shared library in Cabal]
  +
*[[Upgrading packages]]
  +
*[[Package versioning policy]]
  +
*[http://neilmitchell.blogspot.com/2008/02/adding-data-files-using-cabal.html Adding data files using Cabal]
  +
*[https://web.archive.org/web/20161108012154/www.moonloop.net/haskell/docs/cbs-custom.html Cabal Setup file examples]
  +
*[http://blog.ezyang.com/2010/06/setting-up-cabal-the-ffi-and-c2hs/ Setting up Cabal, the FFI and c2hs]
   
  +
[[Category:Tools]]
> import Distribution.Simple
 
  +
[[Category:Cabal]]
> import Distribution.Simple.LocalBuildInfo
 
> import Distribution.PackageDescription
 
> import System.Cmd
 
> import System.Directory
 
> import Data.List
 
>
 
>
 
> main = defaultMainWithHooks (defaultUserHooks { postBuild = buildDll })
 
> where
 
> buildDll _ _ pkg info = do putStrLn "Building Dll..."
 
> setCurrentDirectory (buildDir info)
 
> let buildCmd = cmd pkg info
 
> putStrLn buildCmd
 
> system buildCmd
 
> let cpCmd = "cp "++(dllFile pkg)++" "++(name pkg)++"\\"++(dllFile pkg)
 
> putStrLn cpCmd
 
> system cpCmd
 
> ghcExe :: LocalBuildInfo -> String
 
> ghcExe info = "\"" ++ (compilerPath (compiler info)) ++ "\""
 
> mainOFile :: PackageDescription -> String
 
> mainOFile pd = "HS" ++ (name pd) ++ "-" ++ (showVersion (pkgVersion (package pd))) ++ ".o"
 
> cmd :: PackageDescription -> LocalBuildInfo -> String
 
> cmd pd i = (ghcExe i) ++ " --mk-dll -o " ++ (dllFile pd) ++ " " ++ (mainOFile pd) ++ " " ++ (packages i)
 
> packages :: LocalBuildInfo -> String
 
> packages i = foldl1 (\x y -> x ++ " " ++ y) (map showPackage (packageDeps i))
 
> showPackage :: PackageIdentifier -> String
 
> showPackage pi = "-package " ++ showPackageId pi
 
> name :: PackageDescription -> String
 
> name = pkgName . package
 
> dllFile :: PackageDescription -> String
 
> dllFile pd = (name pd) ++ ".dll"
 
</haskell>
 

Latest revision as of 12:34, 2 October 2020

The Haskell Cabal:

The Common Architecture for Building Applications and Libraries

http://www.haskell.org/cabal/

Summary

  • Cabal is a package and build system. Cabal is only involved in the creation of packages and the building of their contents. It does not manage packages.
  • Cabal-Install installs cabal packages. It is distinct from Cabal (the build system). This often confuses new users. Furthermore, Cabal-Install is not a fully featured package manager. For example, it cannot install non cabal packaged dependencies, it cannot uninstall packages, nor can it automatically upgrade installations.

Information for package users

Information for package developers