Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
Move Development.IDE.Session into ghcide itself
Browse files Browse the repository at this point in the history
Sublibraries do not seem to play well. Hide this behind the ghc-lib flag
so that the Haskell specific hie-bios stuff can be disabled

Note that we need to put the template-haskell part of this module into a
separate module because of an access exception when compiling with
Stack, GHC 8.10.1 and Windows.
  • Loading branch information
lukel97 committed Jul 20, 2020
1 parent 31ca6c4 commit e1fcb75
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 62 deletions.
2 changes: 2 additions & 0 deletions .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
- Development.IDE.GHC.Util
- Development.IDE.Import.FindImports
- Development.IDE.LSP.Outline
- Development.IDE.Session
- Development.IDE.Session.VersionCheck
- Development.IDE.Spans.Calculate
- Development.IDE.Spans.Documentation
- Development.IDE.Spans.Common
Expand Down
61 changes: 23 additions & 38 deletions ghcide.cabal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cabal-version: 3.0
cabal-version: 1.20
build-type: Simple
category: Development
name: ghcide
Expand Down Expand Up @@ -79,7 +79,14 @@ library
build-depends:
ghc-boot-th,
ghc-boot,
ghc >= 8.4
ghc >= 8.4,
-- These dependencies are used by Development.IDE.Session and are
-- Haskell specific. So don't use them when building with -fghc-lib!
ghc-check,
ghc-paths,
cryptohash-sha1 >=0.11.100 && <0.12,
hie-bios == 0.6.*,
base16-bytestring >=0.1.1 && <0.2
if os(windows)
build-depends:
Win32
Expand Down Expand Up @@ -135,6 +142,16 @@ library
Development.IDE.Plugin
Development.IDE.Plugin.Completions
Development.IDE.Plugin.CodeAction

-- Unfortunately, we cannot use loadSession with ghc-lib since hie-bios uses
-- the real GHC library and the types are incompatible. Furthermore, when
-- building with ghc-lib we need to make this Haskell agnostic, so no
-- hie-bios!
if !flag(ghc-lib)
exposed-modules:
Development.IDE.Session
other-modules:
Development.IDE.Session.VersionCheck
other-modules:
Development.IDE.Core.Compile
Development.IDE.Core.Preprocessor
Expand Down Expand Up @@ -174,41 +191,10 @@ library
Development.IDE.GHC.HieAst
Development.IDE.GHC.HieBin
ghc-options: -Wall -Wno-name-shadowing

library ghcide-session-loader
visibility: public
default-language: Haskell2010
hs-source-dirs: session-loader
exposed-modules:
Development.IDE.Session
ghc-options: -Wall -Wno-name-shadowing
build-depends:
base == 4.*,
aeson,
async,
base16-bytestring >=0.1.1 && <0.2,
bytestring,
containers,
cryptohash-sha1 >=0.11.100 && <0.12,
directory,
extra,
filepath,
ghc,
ghc-check,
ghc-paths,
ghcide,
haskell-lsp,
haskell-lsp-types,
hie-bios >= 0.6.0 && < 0.7,
safe-exceptions,
shake,
text,
time,
unordered-containers
-- We can't build this with ghc-lib since it interfaces with hie-bios which
-- uses plain ghc types
if flag(ghc-lib)
buildable: False
-- This is needed to prevent a GHC crash when building
-- Development.IDE.Session with stack on 8.10.1 on Windows
if (impl(ghc > 8.9) && os(windows))
ghc-options: -fexternal-interpreter

executable ghcide-test-preprocessor
default-language: Haskell2010
Expand Down Expand Up @@ -277,7 +263,6 @@ executable ghcide
directory,
extra,
filepath,
ghcide-session-loader,
gitrev,
hashable,
haskell-lsp,
Expand Down
2 changes: 0 additions & 2 deletions hie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ cradle:
component: "ghcide:lib:ghcide"
- path: "./exe"
component: "ghcide:exe:ghcide"
- path: "./session-loader"
component: "ghcide:lib:ghcide-session-loader"
- path: "./test"
component: "ghcide:test:ghcide-tests"
- path: "./bench"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE CPP #-}

{-|
The logic for setting up a ghcide session by tapping into hie-bios.
-}
module Development.IDE.Session (loadSession) where
module Development.IDE.Session
#ifndef GHC_LIB
(loadSession)
#endif
where

-- Unfortunately, we cannot use loadSession with ghc-lib since hie-bios uses
-- the real GHC library and the types are incompatible. Furthermore, when
-- building with ghc-lib we need to make this Haskell agnostic, so no hie-bios!
#ifndef GHC_LIB

import Control.Concurrent.Async
import Control.Concurrent.Extra
Expand All @@ -36,24 +39,20 @@ import Data.Version
import Development.IDE.Core.OfInterest
import Development.IDE.Core.Shake
import Development.IDE.GHC.Util
import Development.IDE.Session.VersionCheck
import Development.IDE.Types.Diagnostics
import Development.IDE.Types.Location
import Development.IDE.Types.Logger
import Development.IDE.Types.Options
import Development.Shake (Action)
import GHC.Check
-- Only use this for checking against the compile time GHC libDir!
-- Use getRuntimeGhcLibDir from hie-bios instead for everything else
-- otherwise binaries will not be distributable since paths will be baked into them
import qualified GHC.Paths
import HIE.Bios
import HIE.Bios.Environment hiding (getCacheDir)
import HIE.Bios.Types
import Language.Haskell.LSP.Core
import Language.Haskell.LSP.Messages
import Language.Haskell.LSP.Types
import System.Directory
import System.Environment
import System.FilePath
import System.Info
import System.IO
Expand All @@ -66,10 +65,11 @@ import Module
import NameCache
import Packages

-- | Given a directory, return a Shake 'Action' which setups an 'IdeGhcSession'.
-- | Given a root directory, return a Shake 'Action' which setups an
-- 'IdeGhcSession' given a file.
-- Some of the many things this does:
--
-- * Find the cradle for the directory
-- * Find the cradle for the file
-- * Get the session options,
-- * Get the GHC lib directory
-- * Make sure the GHC compiletime and runtime versions match
Expand Down Expand Up @@ -452,13 +452,13 @@ data ComponentInfo = ComponentInfo
-- | Internal units, such as local libraries, that this component
-- is loaded with. These have been extracted from the original
-- ComponentOptions.
, componentInternalUnits :: [InstalledUnitId]
, _componentInternalUnits :: [InstalledUnitId]
-- | All targets of this components.
, componentTargets :: [Target]
-- | Filepath which caused the creation of this component
, componentFP :: NormalizedFilePath
-- | Component Options used to load the component.
, componentCOptions :: ComponentOptions
, _componentCOptions :: ComponentOptions
-- | Maps cradle dependencies, such as `stack.yaml`, or `.cabal` file
-- to last modification time. See Note [Multi Cradle Dependency Info]
, componentDependencyInfo :: DependencyInfo
Expand Down Expand Up @@ -589,13 +589,8 @@ notifyCradleLoaded fp =
cradleLoadedMethod :: T.Text
cradleLoadedMethod = "ghcide/cradle/loaded"



----------------------------------------------------------------------------------------------------

ghcVersionChecker :: GhcVersionChecker
ghcVersionChecker = $$(makeGhcVersionChecker (fromMaybe GHC.Paths.libdir <$> lookupEnv "NIX_GHC_LIBDIR"))

data PackageSetupException
= PackageSetupException
{ message :: !String
Expand Down Expand Up @@ -643,3 +638,5 @@ showPackageSetupException (PackageCheckFailed BasePackageAbiMismatch{..}) = unwo
renderPackageSetupException :: FilePath -> PackageSetupException -> (NormalizedFilePath, ShowDiagnostic, Diagnostic)
renderPackageSetupException fp e =
ideErrorWithSource (Just "cradle") (Just DsError) (toNormalizedFilePath' fp) (T.pack $ showPackageSetupException e)

#endif
27 changes: 27 additions & 0 deletions src/Development/IDE/Session/VersionCheck.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE CPP #-}

-- | This module exists to circumvent a compile time exception on Windows with
-- Stack and GHC 8.10.1. It's just been pulled out from Development.IDE.Session.
-- See https://github.com/digital-asset/ghcide/pull/697
module Development.IDE.Session.VersionCheck
#ifndef GHC_LIB
(ghcVersionChecker)
#endif

where

#ifndef GHC_LIB

import Data.Maybe
import GHC.Check
-- Only use this for checking against the compile time GHC libDir!
-- Use getRuntimeGhcLibDir from hie-bios instead for everything else
-- otherwise binaries will not be distributable since paths will be baked into them
import qualified GHC.Paths
import System.Environment

ghcVersionChecker :: GhcVersionChecker
ghcVersionChecker = $$(makeGhcVersionChecker (fromMaybe GHC.Paths.libdir <$> lookupEnv "NIX_GHC_LIBDIR"))

#endif

0 comments on commit e1fcb75

Please sign in to comment.