-
-
Save acrylic-origami/a3ad7b89419c4a5284e3232be1f4b436 to your computer and use it in GitHub Desktop.
Minimal example of frontend plugin vs. regular GHC API usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- In subdirectory `target/A.hs` | |
module A where |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
cabal build | |
# compare: | |
cabal run sandbox | |
# with: | |
ghc --frontend Plugin -itarget -package-db dist-newstyle/packagedb/ghc-8.6.5 Plugin -plugin-package sandbox -hide-all-packages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import GHC | |
import GhcPlugins | |
import DynFlags | |
import GHC.Paths ( libdir ) | |
main :: IO () | |
main = runGhc (Just libdir) $ do | |
dflags <- getSessionDynFlags | |
setSessionDynFlags $ dflags { | |
importPaths = "target":(importPaths dflags) | |
} | |
target <- guessTarget "A" Nothing | |
setTargets [target] | |
() <$ load LoadAllTargets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Plugin where | |
import GHC | |
import GhcPlugins | |
import DynFlags | |
frontendPlugin :: FrontendPlugin | |
frontendPlugin = defaultFrontendPlugin { | |
frontend = fe | |
} | |
fe :: [String] -> [(String, Maybe Phase)] -> Ghc () | |
fe _ _ = do | |
target <- guessTarget "A" Nothing | |
setTargets [target] | |
() <$ load LoadAllTargets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cabal-version: >=1.10 | |
name: sandbox | |
version: 0.1.0.0 | |
license-file: LICENSE | |
author: Derek Lam | |
maintainer: [email protected] | |
build-type: Simple | |
extra-source-files: CHANGELOG.md | |
library | |
exposed-modules: Plugin | |
build-depends: base >=4.12 && <4.13, ghc | |
default-language: Haskell2010 | |
executable sandbox | |
main-is: Main.hs | |
build-depends: base >=4.12 && <4.13, ghc-paths, ghc | |
default-language: Haskell2010 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment