cabal icon indicating copy to clipboard operation
cabal copied to clipboard

pkgsUseSharedLibrary logic is incorrect

Open mpickering opened this issue 1 year ago • 1 comments
trafficstars

Consider the which determines whether we should build shared libraries.

      pkgsUseSharedLibrary :: Set PackageId
      pkgsUseSharedLibrary = 
        packagesWithLibDepsDownwardClosedProperty needsSharedLib
        where
          needsSharedLib pkg =
            fromMaybe
              compilerShouldUseSharedLibByDefault
              (liftM2 (||) pkgSharedLib pkgDynExe)
            where
              pkgid = packageId pkg
              pkgSharedLib = perPkgOptionMaybe pkgid packageConfigSharedLib
              pkgDynExe = perPkgOptionMaybe pkgid packageConfigDynExe

In English the intended logic is:

If we have enabled shared libraries or dynamic executables then we need shared libraries for all dependencies.

but, a common mistake:

(liftM2 (||) pkgSharedLib pkgDynExe)

instead says, if we explicitly request shared libraries and also explicitly configure whether we want dynamic executables then

It should instead use the monoid instance:

getMax <$> ((Max <$> pkgSharedLib) <> (Max <$> pkgDynExe))

mpickering avatar May 23 '24 13:05 mpickering

This failure is currently manifested in the way that if you write --disable-shared then --enable-shared is still passed to ./Setup.

If you pass both --disable-shared and --disable-executable-dynamic then you don't build a shared object.

mpickering avatar May 23 '24 14:05 mpickering

Now fixed.

mpickering avatar Aug 28 '24 08:08 mpickering