How to specify import paths for a frontend plugin

Derek Lam derek at
Sun Jan 5 06:33:53 UTC 2020

Hi ghc-devs,


I’m making a first attempt to make a frontend plugin, to resolve cabal packages in the GHC API. However I’m running into troubles with module resolution in the GHC API, because I can’t control where it will search for modules at all. I've attached a minimal example, with a frontend plugin definition that can’t find modules (Plugin.hs), and an equivalent standalone program that does (Main.hs). 


Specifically, I'm following a solution Edward Yang published in 2017 (, where the frontend plugin is called through a helper script that passes flags forwarded from `cabal repl`. To test the plugin directly with GHC, I collected the args through the helper script and filtered them to the minimal set that made the plugin run:


  ghc --frontend Plugin -itarget -package-db dist-newstyle/packagedb/ghc-8.6.5 Plugin -plugin-package sandbox -hide-all-packages


This, as well as the full argument set, would complain that it can't find the target module under `./target/A.hs`:


  <no location info>: error: module ‘A’ cannot be found locally


It does when the import path arg `-itarget` is absolute. Still, its `importPaths` are what I expect: [".", "target"], and the standalone program finds the target module with the same `importPaths`. I've tested this in GHC 8.6.5, 8.4.2 and 8.2.2, making me sure I'm just missing something, but I haven’t found help in the docs yet. I really appreciate some help to draw my hours over this to a close!





PS the full invocation of the plugin (with absolute paths swapped with relative ones, except `-itarget` which was relative to begin with) is:


ghc --frontend Plugin -plugin-package sandbox -fbuilding-cabal-package -O0 -outputdir dist-newstyle/build/x86_64-osx/ghc-8.6.5/sandbox- -odir dist-newstyle/build/x86_64-osx/ghc-8.6.5/sandbox- -hidir dist-newstyle/build/x86_64-osx/ghc-8.6.5/sandbox- -stubdir dist-newstyle/build/x86_64-osx/ghc-8.6.5/sandbox- -i -idist-newstyle/build/x86_64-osx/ghc-8.6.5/sandbox- -i. -itarget -idist-newstyle/build/x86_64-osx/ghc-8.6.5/sandbox- -idist-newstyle/build/x86_64-osx/ghc-8.6.5/sandbox- -Idist-newstyle/build/x86_64-osx/ghc-8.6.5/sandbox- -Idist-newstyle/build/x86_64-osx/ghc-8.6.5/sandbox- -Idist-newstyle/build/x86_64-osx/ghc-8.6.5/sandbox- -optP-include -optPdist-newstyle/build/x86_64-osx/ghc-8.6.5/sandbox- -this-unit-id sandbox- -hide-all-packages -Wmissing-home-modules -no-user-package-db -package-db /Users/derek-lam/.cabal/store/ghc-8.6.5/package.db -package-db dist-newstyle/packagedb/ghc-8.6.5 -package-db dist-newstyle/build/x86_64-osx/ghc-8.6.5/sandbox- -package-id base- -package-id ghc-8.6.5 -XHaskell2010 Plugin -hide-all-packages

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plugin.tar.gz
Type: application/x-gzip
Size: 1098 bytes
Desc: not available
URL: <>

More information about the ghc-devs mailing list