Distribution.Simple.GHC

Cabal-2.2.0.1: A framework for packaging Haskell software

Copyright | Isaac Jones 2003-2007
License | BSD3
Maintainer | cabal-devel@haskell.org
Portability | portable
Safe Haskell | None
Language | Haskell2010

Distribution.Simple.GHC

Contents

- Constructing GHC environment files
- Version-specific implementation quirks

Description

This is a fairly large module. It contains most of the GHC-specific code for configuring, building and installing packages. It also exports a function for finding out what packages are already installed. Configuring involves finding the `ghc` and `ghc-pkg` programs, finding what language extensions this version of ghc supports and returning a `Compiler` value.

`getInstalledPackages` involves calling the `ghc-pkg` program to find out what packages are installed.

Building is somewhat complex as there is quite a bit of information to take into account. We have to build libs and programs, possibly for profiling and shared libs. We have to support building libraries that will be usable by GHCi and also ghc's `-split-objs` feature. We have to compile any C files using ghc. Linking, especially for `split-objs` is remarkably complex, partly because there tend to be 1,000's of `.o` files and this can often be more than we can pass to the `ld` or `ar` programs in one go.

Installing for libs and exes involves finding the right files and copying them to the right places. One of the more tricky things about this module is remembering the layout of files in the build directory (which is not explicitly documented) and thus what search dirs are used for various kinds of files.

Synopsis

- getGhcInfo :: Verbosity -> ConfiguredProgram -> IO [(String, String)]
- configure :: Verbosity -> Maybe FilePath -> Maybe FilePath -> ProgramDb -> IO (Compiler, Maybe Platform, ProgramDb)
- getInstalledPackages :: Verbosity -> Compiler -> PackageDBStack -> ProgramDb -> IO InstalledPackageIndex
- getInstalledPackagesMonitorFiles :: Verbosity -> Platform -> ProgramDb -> [PackageDB] -> IO [FilePath]
- getPackageDBContents :: Verbosity -> PackageDB -> ProgramDb -> IO InstalledPackageIndex
- buildLib :: Verbosity -> Flag (Maybe Int) -> PackageDescription -> LocalBuildInfo -> Library -> ComponentLocalBuildInfo -> IO ()
- buildFLib :: Verbosity -> Flag (Maybe Int) -> PackageDescription -> LocalBuildInfo -> ForeignLib -> ComponentLocalBuildInfo -> IO ()
- buildExe :: Verbosity -> Flag (Maybe Int) -> PackageDescription -> LocalBuildInfo -> Executable -> ComponentLocalBuildInfo -> IO ()
- replLib :: Verbosity -> Flag (Maybe Int) -> PackageDescription -> LocalBuildInfo -> Library -> ComponentLocalBuildInfo -> IO ()
- replFLib :: Verbosity -> Flag (Maybe Int) -> PackageDescription -> LocalBuildInfo -> ForeignLib -> ComponentLocalBuildInfo -> IO ()
- replExe :: Verbosity -> Flag (Maybe Int) -> PackageDescription -> LocalBuildInfo -> Executable -> ComponentLocalBuildInfo -> IO ()
- startInterpreter :: Verbosity -> ProgramDb -> Compiler -> Platform -> PackageDBStack -> IO ()
- installLib :: Verbosity -> LocalBuildInfo -> FilePath -> FilePath -> FilePath -> PackageDescription -> Library -> ComponentLocalBuildInfo -> IO ()
- installFLib :: Verbosity -> LocalBuildInfo -> FilePath -> FilePath -> PackageDescription -> ForeignLib -> IO ()
- installExe :: Verbosity -> LocalBuildInfo -> FilePath -> FilePath -> (FilePath, FilePath) -> PackageDescription -> Executable -> IO ()
- libAbiHash :: Verbosity -> PackageDescription -> LocalBuildInfo -> Library -> ComponentLocalBuildInfo -> IO String
- hcPkgInfo :: ProgramDb -> HcPkgInfo
- registerPackage :: Verbosity -> ProgramDb -> PackageDBStack -> InstalledPackageInfo -> RegisterOptions -> IO ()
- componentGhcOptions :: Verbosity -> LocalBuildInfo -> BuildInfo -> ComponentLocalBuildInfo -> FilePath -> GhcOptions
- componentCcGhcOptions :: Verbosity -> LocalBuildInfo -> BuildInfo -> ComponentLocalBuildInfo -> FilePath -> FilePath -> GhcOptions
- getLibDir :: Verbosity -> LocalBuildInfo -> IO FilePath
- isDynamic :: Compiler -> Bool
- getGlobalPackageDB :: Verbosity -> ConfiguredProgram -> IO FilePath
- pkgRoot :: Verbosity -> LocalBuildInfo -> PackageDB -> IO FilePath
- data GhcEnvironmentFileEntry
  - = GhcEnvFileComment String
  - | GhcEnvFilePackageId UnitId
  - | GhcEnvFilePackageDb PackageDB
  - | GhcEnvFileClearPackageDbStack
- simpleGhcEnvironmentFile :: PackageDBStack -> [UnitId] -> [GhcEnvironmentFileEntry]
- writeGhcEnvironmentFile :: FilePath -> Platform -> Version -> [GhcEnvironmentFileEntry] -> NoCallStackIO FilePath
- getImplInfo :: Compiler -> GhcImplInfo
- data GhcImplInfo = GhcImplInfo {
  - supportsHaskell2010 :: Bool
  - reportsNoExt :: Bool
  - alwaysNondecIndent :: Bool
  - flagGhciScript :: Bool
  - flagProfAuto :: Bool
  - flagPackageConf :: Bool
  - flagDebugInfo :: Bool
  - supportsDebugLevels :: Bool
  - supportsPkgEnvFiles :: Bool
  - flagWarnMissingHomeModules :: Bool
  }

# Documentation

getGhcInfo :: Verbosity -> ConfiguredProgram -> IO [(String, String)] Source #

configure :: Verbosity -> Maybe FilePath -> Maybe FilePath -> ProgramDb -> IO (Compiler, Maybe Platform, ProgramDb) Source #

getInstalledPackages :: Verbosity -> Compiler -> PackageDBStack -> ProgramDb -> IO InstalledPackageIndex Source #

Given a package DB stack, return all installed packages.

getInstalledPackagesMonitorFiles :: Verbosity -> Platform -> ProgramDb -> [PackageDB] -> IO [FilePath] Source #

getPackageDBContents :: Verbosity -> PackageDB -> ProgramDb -> IO InstalledPackageIndex Source #

Given a single package DB, return all installed packages.

buildLib :: Verbosity -> Flag (Maybe Int) -> PackageDescription -> LocalBuildInfo -> Library -> ComponentLocalBuildInfo -> IO () Source #

buildFLib :: Verbosity -> Flag (Maybe Int) -> PackageDescription -> LocalBuildInfo -> ForeignLib -> ComponentLocalBuildInfo -> IO () Source #

Build a foreign library

buildExe :: Verbosity -> Flag (Maybe Int) -> PackageDescription -> LocalBuildInfo -> Executable -> ComponentLocalBuildInfo -> IO () Source #

Build an executable with GHC.

replLib :: Verbosity -> Flag (Maybe Int) -> PackageDescription -> LocalBuildInfo -> Library -> ComponentLocalBuildInfo -> IO () Source #

replFLib :: Verbosity -> Flag (Maybe Int) -> PackageDescription -> LocalBuildInfo -> ForeignLib -> ComponentLocalBuildInfo -> IO () Source #

Build a foreign library

replExe :: Verbosity -> Flag (Maybe Int) -> PackageDescription -> LocalBuildInfo -> Executable -> ComponentLocalBuildInfo -> IO () Source #

Build an executable with GHC.

startInterpreter :: Verbosity -> ProgramDb -> Compiler -> Platform -> PackageDBStack -> IO () Source #

Start a REPL without loading any source files.

installLib Source #

Arguments

:: Verbosity |
-> LocalBuildInfo |
-> FilePath | install location
-> FilePath | install location for dynamic libraries
-> FilePath | Build location
-> PackageDescription |
-> Library |
-> ComponentLocalBuildInfo |
-> IO () |

Install for ghc, .hi, .a and, if --with-ghci given, .o

installFLib Source #

Arguments

:: Verbosity |
-> LocalBuildInfo |
-> FilePath | install location
-> FilePath | Build location
-> PackageDescription |
-> ForeignLib |
-> IO () |

Install foreign library for GHC.

installExe Source #

Arguments

:: Verbosity |
-> LocalBuildInfo |
-> FilePath | Where to copy the files to
-> FilePath | Build location
-> (FilePath, FilePath) | Executable (prefix,suffix)
-> PackageDescription |
-> Executable |
-> IO () |

Install executables for GHC.

libAbiHash :: Verbosity -> PackageDescription -> LocalBuildInfo -> Library -> ComponentLocalBuildInfo -> IO String Source #

Extracts a String representing a hash of the ABI of a built library. It can fail if the library has not yet been built.

hcPkgInfo :: ProgramDb -> HcPkgInfo Source #

registerPackage :: Verbosity -> ProgramDb -> PackageDBStack -> InstalledPackageInfo -> RegisterOptions -> IO () Source #

componentGhcOptions :: Verbosity -> LocalBuildInfo -> BuildInfo -> ComponentLocalBuildInfo -> FilePath -> GhcOptions Source #

componentCcGhcOptions :: Verbosity -> LocalBuildInfo -> BuildInfo -> ComponentLocalBuildInfo -> FilePath -> FilePath -> GhcOptions Source #

getLibDir :: Verbosity -> LocalBuildInfo -> IO FilePath Source #

isDynamic :: Compiler -> Bool Source #

getGlobalPackageDB :: Verbosity -> ConfiguredProgram -> IO FilePath Source #

Return the `FilePath` to the global GHC package database.

pkgRoot :: Verbosity -> LocalBuildInfo -> PackageDB -> IO FilePath Source #

# Constructing GHC environment files

data GhcEnvironmentFileEntry Source #

The kinds of entries we can stick in a `.ghc.environment` file.

Constructors

GhcEnvFileComment String |
    -- a comment
GhcEnvFilePackageId UnitId |
    package-id foo-1.0-4fe301a...
GhcEnvFilePackageDb PackageDB | `global-package-db`, `user-package-db` or `package-db blahpackage.conf.d`
GhcEnvFileClearPackageDbStack |
    clear-package-db

simpleGhcEnvironmentFile :: PackageDBStack -> [UnitId] -> [GhcEnvironmentFileEntry] Source #

Make entries for a GHC environment file based on a `PackageDBStack` and a bunch of package (unit) ids.

If you need to do anything more complicated then either use this as a basis and add more entries, or just make all the entries directly.

writeGhcEnvironmentFile Source #

Arguments

:: FilePath | directory in which to put it
-> Platform | the GHC target platform
-> Version | the GHC version
-> [GhcEnvironmentFileEntry] | the content
-> NoCallStackIO FilePath |

Write a `.ghc.environment-$arch-$os-$ver` file in the given directory.

The `Platform` and GHC `Version` are needed as part of the file name.

Returns the name of the file written.

# Version-specific implementation quirks

getImplInfo :: Compiler -> GhcImplInfo Source #

data GhcImplInfo Source #

Information about features and quirks of a GHC-based implementation.

Compiler flavors based on GHC behave similarly enough that some of the support code for them is shared. Every implementation has its own peculiarities, that may or may not be a direct result of the underlying GHC version. This record keeps track of these differences.

All shared code (i.e. everything not in the Distribution.Simple.FLAVOR module) should use implementation info rather than version numbers to test for supported features.

Constructors

GhcImplInfo |
Fields supportsHaskell2010 :: Bool XHaskell2010 and -XHaskell98 flags reportsNoExt :: Bool -supported-languages gives Ext and NoExt alwaysNondecIndent :: Bool NondecreasingIndentation is always on flagGhciScript :: Bool ghci-script flag supported flagProfAuto :: Bool new style -fprof-auto* flags flagPackageConf :: Bool use package-conf instead of package-db flagDebugInfo :: Bool g flag supported supportsDebugLevels :: Bool supports numeric `-g` levels supportsPkgEnvFiles :: Bool picks up `.ghc.environment` files flagWarnMissingHomeModules :: Bool Wmissing-home-modules is supported