hoppy-runtime-0.7.0: C++ FFI generator - Runtime support

Safe HaskellNone
LanguageHaskell2010

Foreign.Hoppy.Setup

Description

Implementations of Cabal setup programs for use in packages of generated bindings.

Much like the default Setup.hs that Cabal recommends for packages,

import Distribution.Simple
main = defaultMain

this module provides simplified configuration of packages for generated bindings. Suppose you have a project named foobar that is composed of Cabal packages named "foobar-generator" for the code generator, "foobar-cpp" for the C++ gateway, and "foobar" for the Haskell gateway. The C++ gateway package can use the following code:

import Foreign.Hoppy.Setup (ProjectConfig (..), cppMain)

main =
  cppMain $
  ProjectConfig
  { generatorExecutableName = "foobar-generator"
  , cppPackageName = "foobar-cpp"
  , cppSourcesDir = "cpp"
  , hsSourcesDir = "src"
  }

The Haskell gateway uses the same code, except calling hsMain instead of cppMain. This causes C++ sources to be generated in foobar-cpp/cpp and (assuming the Haskell gateway is at foobar/) the Haskell sources to be generated in foobar/src.

The gateway packages need to set build-type: Custom in their .cabal files to use these setup files.

Synopsis

Documentation

data ProjectConfig Source #

Configuration parameters for a project using Hoppy.

Constructors

ProjectConfig 

Fields

  • generatorExecutableName :: FilePath

    The name of the executable program in the generator package.

  • cppPackageName :: String

    The name of the C++ gateway package.

  • cppSourcesDir :: FilePath

    The directory into which to generate C++ sources, under the C++ gateway package root.

  • hsSourcesDir :: FilePath

    The directory into which to generate Haskell sources, under the Haskell gateway package root.

  • interfaceName :: Maybe String

    If the generator contains multiple interfaces, then this can be used to select one. If present, it is passed as an argument to --interface when invoking the generator. If absent, the default interface is used.

cppMain :: ProjectConfig -> IO () Source #

A main implementation to be used in the Setup.hs of a C++ gateway package.

cppMain project = defaultMainWithHooks $ cppUserHooks project

cppUserHooks :: ProjectConfig -> UserHooks Source #

Cabal user hooks for a C++ gateway package. When overriding fields in the result, be sure to call the previous hook.

The following hooks are defined:

  • postConf: Runs the generator program to generate C++ sources. Checks if a configure script exists in the C++ gateway root, and calls it if so (without arguments).
  • buildHook: Runs make with no arguments from the C++ gateway root.
  • copyHook and instHook: Runs make install libdir=$libdir where $libdir is the directory into which to install the built shared library.
  • cleanHook: Removes files created by the generator, then calls make clean.

hsMain :: ProjectConfig -> IO () Source #

A main implementation to be used in the Setup.hs of a Haskell gateway package.

hsMain project = defaultMainWithHooks $ hsUserHooks project

hsUserHooks :: ProjectConfig -> UserHooks Source #

Cabal user hooks for a Haskell gateway package. When overriding fields in the result, be sure to call the previous hook.

The following hooks are defined:

  • postConf: Finds the shared library directory for the installed C++ gateway package, and writes this path to a dist/build/hoppy-cpp-libdir file. Runs the generator program to generate Haskell sources.
  • preBuild, preTest, preCopy, preInst, preReg: Reads the C++ library directory from dist/build/hoppy-cpp-libdir and adds it to the library search path (extraLibDirs).
  • cleanHook: Removes files created by the generator.