From 0acdad3add84e44244349ff578a5c2d8c6b47434 Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Fri, 24 May 2024 13:30:20 +0100 Subject: [PATCH] Fix predicate which determines whether to build a shared library 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 to build a shared libary. 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 build a shared library. It should instead use the monoid instance: getMax <$> ((Max <$> pkgSharedLib) <> (Max <$> pkgDynExe)) which captures the original logic. 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. Fixes #10050 --- .../src/Distribution/Client/ProjectPlanning.hs | 3 ++- changelog.d/issue-10050 | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 changelog.d/issue-10050 diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning.hs b/cabal-install/src/Distribution/Client/ProjectPlanning.hs index ea4fae8ab8c..92b6f0fbdcf 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanning.hs @@ -219,6 +219,7 @@ import Distribution.Solver.Types.ProjectConfigPath import System.FilePath import Text.PrettyPrint (colon, comma, fsep, hang, punctuate, quotes, text, vcat, ($$)) import qualified Text.PrettyPrint as Disp +import Data.Semigroup -- | Check that an 'ElaboratedConfiguredPackage' actually makes -- sense under some 'ElaboratedSharedConfig'. @@ -2365,7 +2366,7 @@ elaborateInstallPlan needsSharedLib pkg = fromMaybe compilerShouldUseSharedLibByDefault - (liftM2 (||) pkgSharedLib pkgDynExe) + (getMax <$> ((Max <$> pkgSharedLib) <> (Max <$> pkgDynExe))) where pkgid = packageId pkg pkgSharedLib = perPkgOptionMaybe pkgid packageConfigSharedLib diff --git a/changelog.d/issue-10050 b/changelog.d/issue-10050 new file mode 100644 index 00000000000..9d2ef211aea --- /dev/null +++ b/changelog.d/issue-10050 @@ -0,0 +1,10 @@ +synopsis: Fix behaviour of --disable-shared +packages: cabal-install +prs: #10054 +issues: #10050 + +description: Previously `--disable-shared` was not applied unless `--disable-executable-dynamic` was +also explicitly configured. + +Now `--disable-shared` will turn off building shared libraries irrespective of whether +`--disable-executable-dynamic` is specified.