haskell / haskell/cabal

Support standalone foreign libraries on Linux

Open
#4,827 9 comments 9 reactions 0 assignees View on GitHub
Cabal: stanza/foreign-library type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

If `option: standalone` is used in a `foreign-library` stanza on Linux, Cabal reports "We cannot build standalone libraries on Linux." However, it is possible to do so; all that's necessary is that the package's dependencies (including the RTS) are built with `-fPIC`. Although a default GHC build doesn't do this, it's not too difficult to build a GHC that uses position-independent boot libraries (especially on Nix). I've used this technique combined with the `ghc-options` functionality in stack (to ensure non-boot Haskell dependencies are built with `-fPIC`) to build Haskell code into C libraries that are shipped to other teams in a commercial setting.

In most settings I've dealt with it's all but necessary to statically link Haskell foreign libraries against Haskell dependencies; the whole point of doing this is to wrap up all the Haskell goodies as cleanly as possible for consumers working in other environments. Supporting standalone libraries on Linux, combined with a solution to #4042, would allow me to eliminate a lot of custom build machinery.

I haven't looked at the plumbing around the `foreign-library` stanza, but I'd imagine it wouldn't be too difficult to do the right thing on Linux assuming the boot libraries available to the GHC in use are position-independent. If they aren't position-independent (and they won't be by default), it'd be nice for cabal-install to detect this somehow and fail before the linker shows the user something much scarier looking.

The `foreign-library` feature is really exciting. It makes it a lot easier to use Haskell as a part of larger systems.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.