How can I pin a version of a Haskell dependency to a version of an underlying native dependency with Cabal?

旧巷老猫 提交于 2019-12-05 19:32:04

I'm submitting another answer because this uses another idea...

Using a custom Setup.hs with defaultMainWithHooksArgs allows you to inspect and modify the args to the cabal configure command.

This is a Setup.hs which does no modification:

import Distribution.Simple
import Distribution.Simple.Configure
import System.Environment

main = do
  args <- getArgs
  defaultMainWithHooksArgs simpleUserHooks args

If your .cabal file has a flag defined, e.g.:

Flag Foo
  Default:  False

then in the args you will see "--flags=-foo". So the idea is:

  1. Define two flags in the .cabal file - use10 and use11 to select which version of bindings-libzip to use.
  2. In your custom Setup.hs determine which version to use.
  3. Find the "--flags=..." arg and modify it appropriately before passing it along to defaultMainWithHooksArgs.

I think the way to do this is with a custom Setup.hs file (specify build-type: Custom in the .cabal file.)

You can override specific stages of the build process by using a main like this:

main = defaultMainWithHooks $ simpleUserHooks { preConf = myPreConf }

myPreConf :: Args -> ConfigFlags -> IO HookedBuildInfo
myPreConf args configFlags = ...

It is also likely that overriding the confHook is what you want.

Some links:

Examples of custom Setup.hs files overriding confHook:

abcBridge arb-fft cabalmdvrpm darkplaces-text GLFW happybara-webkit-server haskeline HDBC-postgresql helics hlbfgsb hlibsass hpqtypes hruby hsqml hubris illuminate intel-aes keera-posture KiCS-debugger libpq llvm-general morfeusz postgresql-libpq tamarin-prover tamarin-prover-term tamarin-prover-theory tamarin-prover-utils voyeur wxc wxcore

In particular, the hruby Setup.hs looks like it is doing something like what you want to do.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!