haskell / haskell/cabal

user option to dump out ghc flags and PATH on compile

Open
#7,055 1 comment 0 reactions 0 assignees View on GitHub
type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

I have written a compiler plugin http://hackage.haskell.org/package/ghcflags that does the following on compile:

1. output the flags that are passed to `ghc` into a `.ghc.flags` file in the root of every source directory
2. output the PATH that is used to invoke `ghc` into a `.ghc.path` file in the root of every source directory

Downstream tools can then make use of these flags to invoke the `ghc` api correctly... it provides flags relevant for package loading, language extensions, CPP, and more. Contrast to `.env` files, which only achieve the package loading aspect and are not enough in most real world cases.

An alternatives to this approach was taken in `hie-bios` which effectively amounts to tricking the build tool into running a faux `ghci` and extracting the flags that way but has many downsides as described in https://github.com/haskell/cabal/issues/6203 (I reimplemented the `hie-bios` approach in a shell script to highlight what tooling authors are being forced to do).

However, installation of a compiler plugin is very cumbersome for users due to https://github.com/haskell/cabal/issues/6307 and therefore the `hie-bios` authors continue to use the approach outlined above, plus it doesn't work for older ghcs that do not support plugins.

If cabal were to support a user option to output the `.ghc.flags` / `.ghc.path` files in the same manner as the `ghcflags` plugin as then it would make sense to add support for these files in `hie-bios` and then all tooling that needs access to the ghc flags would benefit. This would be a competitive advantage for `cabal` over `stack` as it would make user-facing tools such as HIE "just work" in more cases.

This supercedes https://github.com/haskell/cabal/issues/6203

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.