我认为将引导程序可执行文件作为单独的包发布是最简单的解决方案,并且有关于如何将自定义预处理器与 Cabal 集成的说明。
如果您不想这样做,请尝试使您的预处理器成为其中的一部分Setup.hs
(不要忘记将构建类型设置为Custom
!)。您可以在配置步骤中运行预处理器。看看这是怎么wxcore
做到的。
这是一个工作示例(在 之后的样式wxcore
):
Setup.hs
:
import Distribution.Simple
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Setup
import Distribution.PackageDescription
import Control.Monad (forM_)
import System.Directory (copyFile)
import System.FilePath (replaceExtension)
main :: IO ()
main = defaultMainWithHooks simpleUserHooks { confHook = myConfHook }
-- Replace 'copyFile' with more complicated logic.
runMyPreprocessor :: FilePath -> IO ()
runMyPreprocessor abcFile = copyFile abcFile (replaceExtension abcFile ".hs")
myConfHook :: (GenericPackageDescription, HookedBuildInfo) -> ConfigFlags
-> IO LocalBuildInfo
myConfHook (pkgDesc, hbi) flags = do
let extraSrc = extraSrcFiles . packageDescription $ pkgDesc
forM_ extraSrc runMyPreprocessor
confHook simpleUserHooks (pkgDesc, hbi) flags
my-preprocessor.cabal
:
name: my-preprocessor
version: 0.1.0.0
build-type: Custom
cabal-version: >=1.8
extra-source-files: Main.abc
executable my-preprocessor
main-is: Main.hs
build-depends: base < 5
Main.abc
:
module Main
where
main :: IO ()
main = putStrLn "Hello"