Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will ghc-options of an executable override ghc-options of linked libraries?

Tags:

haskell

I have a main Haskell executable program with a cabal file. There, I specify the ghc-options.

This executable links against other libraries out in the wilderness. Will the ghc-options of the cabal files of these libraries be ignored?

I'm basically wondering whether the executable's ghc-options will be used for the entire enchilada (main executable + libraries).

Additional bounty notes: Please also expand on chi's comment below, namely, what exactly is the difference between ghc-options for compiling vs. linking. Which are which, and which are never needed in libraries? Maybe you can talk about some of the most important ones, such as the -threaded mentioned below.

like image 967
haskellHQ Avatar asked Jul 03 '17 16:07

haskellHQ


1 Answers

Under the normal cabal-install workflow (and the stack workflow built atop it), flags specified in your Cabal file are local to your package, and should not trigger rebuilds. Similarly, options specified with --ghc-options on the command line are local to your package.

To your specific questions about -threaded, this flag has no effect on library code (as cabal-install will tell you), only on executables.

A brief listing of GHC flags is available here. In particular, note that -threaded is listed under Linking options, with a further link to Options affecting linking. From this information, we conclude that -threaded is only meaningful for executables because it signals to GHC that we wish to use the threaded runtime. If your package doesn't provide an executable, it has no need for any runtime, threaded or otherwise.

For a high-level explanation of compiling vs. linking: they are two of the steps between source code and executable. Compilation is the process of producing an object file from source code. Linking is the process of connecting the numerous object files which compose your executable. When you compile an executable, it has no idea that a function, say map exists unless you defined it, so it just compiles under the assumption that it does. The linking step is where we make all those names available and meaningful. In the case of -threaded, we are making the linking process aware of the threaded runtime, which all code calling on the runtime will use.

Since I don't know if you're using the standard cabal workflow, stack, or the new cabal.project workflow, here's a digression to discuss this behavior in the cabal.project case.

This is actually an open bug, right now.

The bug is tracked as issue 3883 on the Cabal GitHub (and somewhat in the related issue 4247).

Relevant to your question, according to current behavior, specifying flags in a ghc-options stanza in a cabal.project file causes those dependencies to be compiled (or recompiled, as the case may be) with those flags.

like image 87
Jack Henahan Avatar answered Oct 09 '22 02:10

Jack Henahan