How to get minor GHC version from custom Setup.hs

Haskell Cabal is an advanced build system which can produce self contained shared library with few lines.
It’s necessary to list GHC’s runtime system to be able to dlopen the library:

library
  ...
  ghc-options: -threaded
  extra-libraries: HSrts-ghc7.10.2

-threaded is there to use the FFI in a multi-threaded setting which is usually the case.

Name of the library produced by GHC changes from build to build (due to “hash” being attached?)

Shared libraries are commonly used as a plugins. Other naming convention can be implemented at a postBuild hook in custom Setup.hs e.g. by renaming the library.

The tricky part comes when we need to figure out that “hash”.

We could use mkSharedLibName of Distribution.Simple.BuildPaths but that uses System.Info.compilerVersion internally which does not report minor version of GHC (that’s by design)

To address that this quick workaround will suffice for me for now. Get GHC version from Cabal:

...
 Just loc <- findProgramOnSearchPath normal defaultProgramSearchPath (programName ghcProgram)
 Just (Version { versionBranch = [g,h,c] }) <- programFindVersion ghcProgram normal loc
...

And re-write mkSharedLibName using g,h,c instead of CompilerId which is left as an exercise blink

I wonder what that “hash”‘s all about…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s