| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
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" , cppPackagedSourcesLocation = Nothing , cppSourcesDir =GenerateInAutogenDir"" , hsSourcesDir =GenerateInAutogenDir"" }
The Haskell gateway uses the same code, except calling hsMain instead of
cppMain. This causes all (C++, Haskell) generated sources to be placed in
the "autogen" directories provided by Cabal, which keeps the source
directory clean. See the documentation of the fields of ProjectConfig for
more information on how to set up your project's build process.
The gateway packages need to set build-type: Custom in their .cabal files
to use these setup files.
Synopsis
- data ProjectConfig = ProjectConfig {}
- data GenerateLocation
- combinedMain :: ProjectConfig -> IO ()
- combinedUserHooks :: ProjectConfig -> UserHooks
- cppMain :: ProjectConfig -> IO ()
- cppUserHooks :: ProjectConfig -> UserHooks
- hsMain :: ProjectConfig -> IO ()
- hsUserHooks :: ProjectConfig -> UserHooks
Documentation
data ProjectConfig Source #
Configuration parameters for a project using Hoppy.
Constructors
| ProjectConfig | |
Fields
| |
data GenerateLocation Source #
Where to generate sources for binding packages.
Constructors
| GenerateInAutogenDir FilePath | Generate sources in the package's autogen directory provided by Cabal. This is preferrable as it keeps the source directory clean. Sources are generated below the given |
| GenerateInSourcesDir FilePath | Generate sources in the package's root source directory, i.e. the
directory with the Sources are generated below the given |
combinedMain :: ProjectConfig -> IO () Source #
A main implementation to be used in the Setup.hs of a single Hoppy
binding package that combined both the C++ and Haskell gateway code in one
package.
combinedMain project =defaultMainWithHooks$combinedUserHooksproject
combinedUserHooks :: ProjectConfig -> UserHooks Source #
Cabal user hooks for a combined gateway package. When overriding overriding fields in the result, be sure to call the previous hook.
The following hooks are defined:
postConf: Runs the generator to generate C++ and Haskell sources.
cppMain :: ProjectConfig -> IO () Source #
A main implementation to be used in the Setup.hs of a C++ gateway
package.
cppMain project =defaultMainWithHooks$cppUserHooksproject
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 aconfigurescript exists in the C++ gateway root, and calls it if so (without arguments).buildHook: Runsmakewith no arguments from the C++ gateway root.copyHookandinstHook: Runsmake install libdir=$libdirwhere$libdiris 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$hsUserHooksproject
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-libdirfile. Runs the generator program to generate Haskell sources.preBuild,preTest,preCopy,preInst,preReg: Reads the C++ library directory fromdist/build/hoppy-cpp-libdirand adds it to the library search path (extraLibDirs).cleanHook: Removes files created by the generator.