From 428e0a282b060ef291f626c4d1379c67f62dd28c Mon Sep 17 00:00:00 2001 From: Michal Antkiewicz Date: Fri, 9 Oct 2026 08:05:20 -0400 Subject: [PATCH 1/2] add support for loading dynamic plugins for GHC >= 9.4 --- src/Network/Gitit/Plugins.hs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Network/Gitit/Plugins.hs b/src/Network/Gitit/Plugins.hs index 697854fbd..d3e81756e 100644 --- a/src/Network/Gitit/Plugins.hs +++ b/src/Network/Gitit/Plugins.hs @@ -29,6 +29,11 @@ import System.Log.Logger (logM, Priority(..)) #ifdef _PLUGINS import Data.List (isInfixOf, isPrefixOf) import GHC +#if __GLASGOW_HASKELL__ >= 904 +import Control.Monad.IO.Class (liftIO) +import GHC.Driver.Session (PackageFlag(..), PackageArg(..), ModRenaming(..)) +import GHC.Platform.Ways (Way(WayDyn), addWay, hostIsDynamic) +#endif import GHC.Paths import Unsafe.Coerce @@ -37,7 +42,25 @@ loadPlugin pluginName = do logM "gitit" WARNING ("Loading plugin '" ++ pluginName ++ "'...") runGhc (Just libdir) $ do dflags <- getSessionDynFlags +#if __GLASGOW_HASKELL__ >= 904 + -- Honour package environment files (GHC_ENVIRONMENT or the default + -- environment), which only parseDynamicFlags reads otherwise. + logger <- getLogger + dflags' <- liftIO $ interpretPackageEnv logger dflags + -- Plugins always import Network.Gitit.Interface, so expose gitit even + -- when a package environment hides packages it does not list. + let exposeGitit = ExposePackage "-package gitit" (PackageArg "gitit") + (ModRenaming True []) + dflags'' = dflags' { packageFlags = exposeGitit : packageFlags dflags' } + -- A dynamically linked gitit can only load dynamic code, so look for + -- dynamic interface files and objects, as GHCi does. + setSessionDynFlags $ + if hostIsDynamic + then dflags'' { targetWays_ = addWay WayDyn (targetWays_ dflags'') } + else dflags'' +#else setSessionDynFlags dflags +#endif -- initDynFlags unless ("Network.Gitit.Plugin." `isPrefixOf` pluginName) $ do From 4736627580cd007ff01c67f71612ce14e631d3ad Mon Sep 17 00:00:00 2001 From: Michal Antkiewicz Date: Fri, 9 Oct 2026 13:38:10 -0400 Subject: [PATCH 2/2] Remove CPP for GHC < 9.4 in Plugins.hs gitit now requires ghc >= 9.6, so the conditional code for older GHC versions is no longer needed. Co-Authored-By: Claude Opus 5.5 --- src/Network/Gitit/Plugins.hs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Network/Gitit/Plugins.hs b/src/Network/Gitit/Plugins.hs index d3e81756e..09f08c4cd 100644 --- a/src/Network/Gitit/Plugins.hs +++ b/src/Network/Gitit/Plugins.hs @@ -29,11 +29,9 @@ import System.Log.Logger (logM, Priority(..)) #ifdef _PLUGINS import Data.List (isInfixOf, isPrefixOf) import GHC -#if __GLASGOW_HASKELL__ >= 904 import Control.Monad.IO.Class (liftIO) import GHC.Driver.Session (PackageFlag(..), PackageArg(..), ModRenaming(..)) import GHC.Platform.Ways (Way(WayDyn), addWay, hostIsDynamic) -#endif import GHC.Paths import Unsafe.Coerce @@ -42,7 +40,6 @@ loadPlugin pluginName = do logM "gitit" WARNING ("Loading plugin '" ++ pluginName ++ "'...") runGhc (Just libdir) $ do dflags <- getSessionDynFlags -#if __GLASGOW_HASKELL__ >= 904 -- Honour package environment files (GHC_ENVIRONMENT or the default -- environment), which only parseDynamicFlags reads otherwise. logger <- getLogger @@ -58,17 +55,10 @@ loadPlugin pluginName = do if hostIsDynamic then dflags'' { targetWays_ = addWay WayDyn (targetWays_ dflags'') } else dflags'' -#else - setSessionDynFlags dflags -#endif -- initDynFlags unless ("Network.Gitit.Plugin." `isPrefixOf` pluginName) $ do -#if __GLASGOW_HASKELL__ >= 904 addTarget =<< guessTarget pluginName Nothing Nothing -#else - addTarget =<< guessTarget pluginName Nothing -#endif r <- load LoadAllTargets case r of Failed -> error $ "Error loading plugin: " ++ pluginName