haskell / haskell/cabal

Shared libraries on OSX not linked with framework dependencies or custom ld flags

Open
#2,715 0 comments 0 reactions 0 assignees View on GitHub
platform: mac type: bug
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

On OSX at least, shared libraries are not linked with frameworks, resulting in dylibs which do not declare dependencies correctly (and cannot be loaded unless the dependency is manually loaded). Additionally, `ld-options` are also ignored for these dylibs.

I think the issue might be https://github.com/haskell/cabal/blob/71edb7d20ced1d00081a0689265455fcd8a9c5c0/Cabal/Distribution/Simple/GHC.hs#L648 where ld options and frameworks are not specified when generating the dylib.

```
cabal-install version 1.22.0.0
using version 1.22.0.0 of the Cabal library
```

Example:

cabal file snippet

```
library
exposed-modules: Test
-- other-modules:
other-extensions: ForeignFunctionInterface
build-depends: base >=4.8 && <4.9
-- hs-source-dirs:
default-language: Haskell2010
ld-options: wtf is this used for
frameworks: CoreFoundation
```

and a Test.hs like this:

```
{-# LANGUAGE ForeignFunctionInterface #-}
module Test where
import Foreign

foreign import ccall "CFRelease" cfRelease :: Ptr a -> IO ()

releaseNull = cfRelease nullPtr
```

The dylib that gets generated turns out to be this:

```
~/t/ghc-framework-test ❯❯❯ otool -L dist/build/libHSghcfr_C05XexetHdH9tTr8o4CTUh-ghc7.10.1.dylib
dist/build/libHSghcfr_C05XexetHdH9tTr8o4CTUh-ghc7.10.1.dylib:
@rpath/libHSghcfr_C05XexetHdH9tTr8o4CTUh-ghc7.10.1.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libHSbase-4.8.0.0-I5BErHzyOm07EBNpKBEeUv-ghc7.10.1.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libHSinteger-gmp-1.0.0.0-2aU3IZNMF9a7mQ0OzsZ0dS-ghc7.10.1.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libHSghc-prim-0.4.0.0-8TmvWUcS1U1IKHT0levwg3-ghc7.10.1.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
```

No mention of CoreFoundation anywhere.

Contributor guide

Open the contributing guide

Research direction

Inspect Cabal/Distribution/Simple/GHC.hs around the referenced line, where the dylib is generated, and compare how framework and ld-options arguments are handled. Reproduce the example with CoreFoundation and the custom ld-options, then use otool -L to verify that the generated dylib declares the framework dependency and reflects the linker options.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell, macos
Domain
build-system, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.