Difference between revisions of "Cabal"

From HaskellWiki
Jump to navigation Jump to search
m (Timewasting prettying :))
(→‎Information for package users: Added a link to "An Introduction to Cabal sandboxes")
(23 intermediate revisions by 8 users not shown)
Line 4: Line 4:
 
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. Using the Setup.lhs listed below and following the directions listed above (the second link) I was able to use Visual Haskell to build a dll which I could load into Visual Basic for testing.
 
  +
*[[Cabal/Survival | A short and transient survival guide for Cabal users]]
  +
*[[Cabal/How to install a Cabal package | How to install a Cabal package]]
  +
*[http://coldwa.st/e/blog/2013-08-20-Cabal-sandbox.html An Introduction to Cabal sandboxes]
  +
*[[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
  +
*[[CabalFind]] - finding Cabal packages on the web (now superseded by [http://hackage.haskell.org/ Hackage])
  +
* [http://www.vex.net/~trebla/haskell/sicp.xhtml Storage and Identification of Cabalized Packages]
  +
* [http://hackage.haskell.org/package/cabal-dev cabal-dev], a tool for managing development builds of Haskell projects. It supports maintaining sandboxed cabal-install repositories, and sandboxed ghc package databases. See [http://www.reddit.com/r/haskell/comments/f3ykj/psa_use_cabaldev_to_solve_dependency_problems/ PSA: Use cabal-dev to solve dependency problems] for an extensive description.
  +
* Blog article: [http://ivanmiljenovic.wordpress.com/2010/03/15/repeat-after-me-cabal-is-not-a-package-manager/ Repeat after me: “Cabal is not a Package Manager”]
  +
* [http://www.mew.org/~kazu/proj/cab/en/ cab], a maintenance command of Haskell cabal packages
   
  +
== Information for package developers ==
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. Another possible addition is specifying a static dll. Check the ghc manual above.
 
  +
*[[How to write a Haskell program]]
 
  +
*[http://wewantarock.wordpress.com/2010/11/03/building-a-shared-library-in-cabal/ Building a shared library in Cabal]
<haskell>
 
  +
*[[Cabal/Developer-FAQ|FAQ: Frequently Asked Questions of package authors]]
#! /usr/bin/runghc
 
  +
*[[Cabal/How to install a Cabal package remotely | How to install a Cabal package remotely]]
 
  +
*[[Upgrading packages]]
> import Distribution.Simple
 
  +
*[[Package versioning policy]]
> import Distribution.Simple.LocalBuildInfo
 
  +
*[[Creating Debian packages from Cabal package]]
> import Distribution.PackageDescription
 
  +
*[http://neilmitchell.blogspot.com/2008/02/adding-data-files-using-cabal.html Adding data files using Cabal]
> import System.Cmd
 
  +
*[http://www.moonloop.net/haskell/docs/cbs-custom.html Cabal Setup file examples]
> import System.Directory
 
  +
*[[Cabal-make]] - automation based on makefiles
> import Data.List
 
  +
*[http://blog.ezyang.com/2010/06/setting-up-cabal-the-ffi-and-c2hs/ Setting up Cabal, the FFI and c2hs]
>
 
>
 
> 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 dll = dllFile pkg
 
> let cpDllCmd = "cp " ++ dll ++ " " ++ (name pkg) ++ "\\" ++ dll
 
> putStrLn cpDllCmd
 
> system cpDllCmd
 
> 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>
 
   
 
[[Category:Tools]]
 
[[Category:Tools]]
  +
[[Category:Cabal]]

Revision as of 20:08, 27 December 2013

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