Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- data ProjectConfig = ProjectConfig {}
- cppMain :: ProjectConfig -> IO ()
- cppUserHooks :: ProjectConfig -> UserHooks
- hsMain :: ProjectConfig -> IO ()
- hsUserHooks :: ProjectConfig -> UserHooks
Documentation
data ProjectConfig Source #
Configuration parameters for a project using Hoppy.
ProjectConfig | |
|
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 aconfigure
script exists in the C++ gateway root, and calls it if so (without arguments).buildHook
: Runsmake
with no arguments from the C++ gateway root.copyHook
andinstHook
: Runsmake install libdir=$libdir
where$libdir
is the directory into which to install the built shared library.cleanHook
: Removes files created by the generator, then callsmake 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 adist/build/hoppy-cpp-libdir
file. Runs the generator program to generate Haskell sources.preBuild
,preTest
,preCopy
,preInst
,preReg
: Reads the C++ library directory fromdist/build/hoppy-cpp-libdir
and adds it to the library search path (extraLibDirs
).cleanHook
: Removes files created by the generator.