[Haskell-cafe] Optional C dependencies / build-time feature toggles

Tobias Dammers tdammers at gmail.com
Sun Dec 11 16:53:07 UTC 2016


Hello Cafe,

I have this project here: https://sprinkles.tobiasdammers.nl/ (source on
github: https://github.com/tdammers/sprinkles), and it has a bunch of
runtime dependencies on C libraries. Many of them are only required for
certain use cases, e.g., the libmysqlclient dependency is only relevant
if you want to access MySQL database backends, libfcgi is only required
for hosting as FastCGI (which isn't even the recommended first choice),
etc. Still, in order to build and run Sprinkles, all the dependencies
must be installed, which is of course not ideal.

The pipe dream would be for those dependencies to be optional *at run
time*, such that the application would test for their presence on
startup, or load them dynamically when and if they're needed. However,
I'm also fine with making them compile-time feature toggles, such that
users can enable only the ones they need. Doing some sort of
autotools-style dependency discovery would of course be cool as well
(i.e., only enable mysql support if libmysqlclient is present).

So the broad question is, which of these are realistic, and how would I
go about it?

And, regarding feature toggles, this bit in the Cabal FAQ baffles me a
little:

> Question: I like to let the user enable extended functionality using a
> Cabal flag. Is this the right way?
>
> Answer: Certainly not. Since other packages can distinguish packages
> only according to their name and their version, it is not a good idea
> to allow different APIs for the same package version. Cumbersome as it
> is you have to move extra features to a separate package.

Moving the features to a separate package wouldn't really solve anything
AFAICT, because I'd still have to bring them together somehow.

--
Tobias Dammers - tdammers at gmail.com


More information about the Haskell-Cafe mailing list