
Hi Fendor, On Mon, Feb 08, 2021 at 08:08:45PM +0100, Fendor wrote:
Basically, we want to know which `ghc` version `cabal-install` is going to pick for compiling the project in a platform independent way without resorting to linking to `Cabal`.
For v2-build this can be found out by looking at plan.json for which you only need to link to cabal-plan (or a json lib of your choice). You do need to have logic run `cabal --dry-run` (IIRC) to generate plan.json if it's not there. I have some code for that in cabal-helper, it's not very tricky as long as you're assuming the cabal project isn't in a broken state anyway.
You can execute `cabal exec -- ghc` which launches the correct `ghc` version, but as far as we found out, there is no programmatic way of finding the path to the `ghc` executable itself (`cabal exec -- where ghc` or `cabal exec -- which ghc` fails on windows).
Seems to me it would be relatively straightforward to add a "which" mode to whatever executable you're shipping (we're talking about hls, right?) so you can do something like: cabal exec -- $path_to_hls which which then just prints the path to GHC on PATH found using the appropriate library function without running into the problem of not having `which` on windows. --Daniel