1
+ {-# LANGUAGE CPP #-}
1
2
{-# LANGUAGE LambdaCase #-}
2
3
{-# LANGUAGE MultiWayIf #-}
3
4
{-# LANGUAGE OverloadedStrings #-}
29
30
import qualified Data.Binary as Binary
30
31
import qualified Data.Binary.Get as Binary
31
32
import qualified Data.ByteString.Lazy as BL
32
- import Data.FileEmbed (embedFile )
33
33
import Data.Foldable (foldl' )
34
34
import Data.List.NonEmpty (NonEmpty ((:|) ))
35
35
import qualified Data.List.NonEmpty as NE
@@ -42,12 +42,32 @@ import Data.Set (Set)
42
42
import qualified Data.Set as Set
43
43
import Distribution.Types.PackageName (PackageName , mkPackageName , unPackageName )
44
44
import Ormolu.Fixity.Internal
45
+ #if BUNDLE_FIXITIES
46
+ import Data.FileEmbed (embedFile )
47
+ #else
48
+ import qualified Data.ByteString.Unsafe as BU
49
+ import Foreign.Ptr
50
+ import System.Environment (getEnv )
51
+ import System.IO.Unsafe (unsafePerformIO )
52
+ #endif
45
53
46
54
packageToOps :: Map PackageName FixityMap
47
55
packageToPopularity :: Map PackageName Int
56
+ #if BUNDLE_FIXITIES
48
57
HackageInfo packageToOps packageToPopularity =
49
58
Binary. runGet Binary. get $
50
59
BL. fromStrict $ (embedFile " extract-hackage-info/hackage-info.bin" )
60
+ #else
61
+ -- The GHC WASM backend does not yet support Template Haskell, so we instead
62
+ -- pass in the encoded fixity DB at runtime by storing the pointer and length of
63
+ -- the bytes in an environment variable.
64
+ HackageInfo packageToOps packageToPopularity = unsafePerformIO $ do
65
+ (ptr, len) <- read <$> getEnv " ORMOLU_HACKAGE_INFO"
66
+ Binary. runGet Binary. get . BL. fromStrict
67
+ <$> BU. unsafePackMallocCStringLen (intPtrToPtr $ IntPtr ptr, len)
68
+ {-# NOINLINE packageToOps #-}
69
+ {-# NOINLINE packageToPopularity #-}
70
+ #endif
51
71
52
72
-- | List of packages shipped with GHC, for which the download count from
53
73
-- Hackage does not reflect their high popularity.
0 commit comments