@@ -98,31 +98,38 @@ data SessionLoadingOptions = SessionLoadingOptions
9898 -- return the path for storing generated GHC artifacts,
9999 -- or 'Nothing' to respect the cradle setting
100100 , getCacheDirs :: String -> [String ] -> IO CacheDirs
101+ -- | Return the GHC lib dir to use for the 'unsafeGlobalDynFlags'
102+ , getInitialGhcLibDir :: IO (Maybe LibDir )
101103 }
102104
103105defaultLoadingOptions :: SessionLoadingOptions
104106defaultLoadingOptions = SessionLoadingOptions
105107 {findCradle = HieBios. findCradle
106108 ,loadCradle = HieBios. loadCradle
107109 ,getCacheDirs = getCacheDirsDefault
110+ ,getInitialGhcLibDir = getInitialGhcLibDirDefault
108111 }
109112
110- -- | Sets `unsafeGlobalDynFlags` on using the hie-bios cradle and returns the GHC libdir
111- setInitialDynFlags :: IO (Maybe LibDir )
112- setInitialDynFlags = do
113+ getInitialGhcLibDirDefault :: IO (Maybe LibDir )
114+ getInitialGhcLibDirDefault = do
113115 dir <- IO. getCurrentDirectory
114116 hieYaml <- runMaybeT $ yamlConfig dir
115117 cradle <- maybe (loadImplicitHieCradle $ addTrailingPathSeparator dir) HieBios. loadCradle hieYaml
116118 hPutStrLn stderr $ " setInitialDynFlags cradle: " ++ show cradle
117119 libDirRes <- getRuntimeGhcLibDir cradle
118- libdir <- case libDirRes of
120+ case libDirRes of
119121 CradleSuccess libdir -> pure $ Just $ LibDir libdir
120122 CradleFail err -> do
121123 hPutStrLn stderr $ " Couldn't load cradle for libdir: " ++ show (err,dir,hieYaml,cradle)
122124 pure Nothing
123125 CradleNone -> do
124126 hPutStrLn stderr $ " Couldn't load cradle (CradleNone)"
125127 pure Nothing
128+
129+ -- | Sets `unsafeGlobalDynFlags` on using the hie-bios cradle and returns the GHC libdir
130+ setInitialDynFlags :: SessionLoadingOptions -> IO (Maybe LibDir )
131+ setInitialDynFlags SessionLoadingOptions {.. } = do
132+ libdir <- getInitialGhcLibDir
126133 dynFlags <- mapM dynFlagsForPrinting libdir
127134 mapM_ setUnsafeGlobalDynFlags dynFlags
128135 pure libdir
0 commit comments