Find the ghc binary path from libdir

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Find the ghc binary path from libdir

Fendor
Hello everyone!

I want to find out the location of the `ghc` (and `ghc-pkg`) executable
given the `$libdir` (obtained by `ghc --print-libdir`).
Is there a platform independent way of doing that, which we can rely on?

E.g. on windows, we found that the ghc executable's location is:

* `$libdir/../bin/ghc`

For NixOs (or when using ghcup), it works with:

* `$libdir/../../bin/ghc`

but I worry that this is a just an accident that is not guaranteed by
the installation process.

I also noticed there seems to be a binary in

* `$libdir/bin/ghc`

Is one of these ways documented to be guaranteed by the ghc installation
process?

(P. S. first time using a mailing list, hope I am doing it correctly)

Best regards,
Fendor

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Find the ghc binary path from libdir

Daniel Gröber
Hi Fendor,

On Mon, Feb 08, 2021 at 07:35:12PM +0100, Fendor wrote:
> I want to find out the location of the `ghc` (and `ghc-pkg`) executable
> given the `$libdir` (obtained by `ghc --print-libdir`).
> Is there a platform independent way of doing that, which we can rely on?

Are you aware of the `ghc --print-libdir` option? I think you'd be much
better off going from ghc binary to libdir instead of the other way around.

Could you explain why you're trying to do it your way?

> (P. S. first time using a mailing list, hope I am doing it correctly)

Seems fine to me :)

--Daniel
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Find the ghc binary path from libdir

Fendor
Hi,

Well the purpose is a bit convoluted, but here it goes:

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`.

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). What we really want
is `cabal-install` to tell us, e.g. with `cabal show-build-info` which
is a command not implemented yet[0].

As long as this command is not implemented, we have to monkey patch it
in order to satisfy our goals. You can execute `cabal exec -- ghc
--print-libdir`, which gives you the `$libdir`, which brings us back to
the original question: can we find the `ghc` executable given `$libdir`
in a platform independent way?

[0] https://github.com/haskell/cabal/pull/6241

Best regards,
Fendor

On 2/8/21 7:48 PM, Daniel Gröber wrote:

> Hi Fendor,
>
> On Mon, Feb 08, 2021 at 07:35:12PM +0100, Fendor wrote:
>> I want to find out the location of the `ghc` (and `ghc-pkg`) executable
>> given the `$libdir` (obtained by `ghc --print-libdir`).
>> Is there a platform independent way of doing that, which we can rely on?
> Are you aware of the `ghc --print-libdir` option? I think you'd be much
> better off going from ghc binary to libdir instead of the other way around.
>
> Could you explain why you're trying to do it your way?
>
>> (P. S. first time using a mailing list, hope I am doing it correctly)
> Seems fine to me :)
>
> --Daniel
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Find the ghc binary path from libdir

Christiaan Baaij
Calling `ghc --print-lib-dir` is the only way because the `$libdir` is actually provided on the cmdline using the -B flag:

That's why the `ghc` you normally execute is a shell-wrapper around the `ghc` executable applied to a `-B` argument set at installation time.
But a user is free to move that `$libdir` dir to any other place after installation and update the `-B` flag accordingly.

On Mon, 8 Feb 2021 at 20:09, Fendor <[hidden email]> wrote:
Hi,

Well the purpose is a bit convoluted, but here it goes:

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`.

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). What we really want
is `cabal-install` to tell us, e.g. with `cabal show-build-info` which
is a command not implemented yet[0].

As long as this command is not implemented, we have to monkey patch it
in order to satisfy our goals. You can execute `cabal exec -- ghc
--print-libdir`, which gives you the `$libdir`, which brings us back to
the original question: can we find the `ghc` executable given `$libdir`
in a platform independent way?

[0] https://github.com/haskell/cabal/pull/6241

Best regards,
Fendor

On 2/8/21 7:48 PM, Daniel Gröber wrote:
> Hi Fendor,
>
> On Mon, Feb 08, 2021 at 07:35:12PM +0100, Fendor wrote:
>> I want to find out the location of the `ghc` (and `ghc-pkg`) executable
>> given the `$libdir` (obtained by `ghc --print-libdir`).
>> Is there a platform independent way of doing that, which we can rely on?
> Are you aware of the `ghc --print-libdir` option? I think you'd be much
> better off going from ghc binary to libdir instead of the other way around.
>
> Could you explain why you're trying to do it your way?
>
>> (P. S. first time using a mailing list, hope I am doing it correctly)
> Seems fine to me :)
>
> --Daniel
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Find the ghc binary path from libdir

Daniel Gröber
In reply to this post by Fendor
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
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs