ghcup-hs icon indicating copy to clipboard operation
ghcup-hs copied to clipboard

Enhancement: add proxy names redirection for `ghcup` executable

Open evan0greenup opened this issue 1 year ago • 6 comments

ghcup to Haskell is similar to rustup to Rust.

Have a look on https://rust-lang.github.io/rustup/concepts/proxies.html, It would nice to bring this feature in ghcup.

When create a symlink to ghcup executable with a different name for example ghc or stack or cabal, it will automatically redirect the command and arguments to its default related tools.

This would make it much easier for Linux distro maintainer to use ghcup replace all the traditional haskell related toolchain.

evan0greenup avatar Feb 16 '24 03:02 evan0greenup

This is rather easy with e.g. ghcup run --ghc recommended -- ghc "$@".

However, there's a complication on windows:

  1. symlinks are not enabled on all systems
  2. windows doesn't seem to have a proper exec function that stops the current process and lets the child process take fully over (at least not in process package)? That means it's subtly different from invoking ghc directly

hasufell avatar Feb 16 '24 04:02 hasufell

@hasufell ,

The problem of why not using ghcup run --ghc recommended -- ghc "$@" as shell script is:

If the shell script which is installed as /usr/bin/ghc. Then it will fall into infinite shell recursion.

Because /usr/bin is also a path where ghcup search paths.

evan0greenup avatar Feb 19 '24 12:02 evan0greenup

I don't see why that would be the case. The new ghc binary location is prepended to PATH and the shell picks the first occurence.

hasufell avatar Feb 21 '24 02:02 hasufell

[hasufell@localhost:~]
$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin
[hasufell@localhost:~]
$ cat /usr/bin/ghc
#!/bin/sh

$HOME/.ghcup/bin/ghcup run --ghc recommended -- ghc "$@"

[hasufell@localhost:~]
$ which ghc
/usr/bin/ghc
[hasufell@localhost:~]
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.4.8

hasufell avatar Feb 21 '24 08:02 hasufell

@hasufell , as a packager, I want to make ghcup a system package.

Modifying user's .bashrc or .bash_profile is definitely not a good practice.

Want to just add new files in system-level instead of modifying any file or do options on user home directory.

Because for multiple users system, when new user added, the effect do against old user will not apply to new user.

Add name proxies for ghcup executable will make thing a lot easier. Hope you can understand.

evan0greenup avatar Mar 14 '24 03:03 evan0greenup

@evan0greenup you can already do what you want with shell wrappers. See ghcup run --help.

Note that you'll have to make a choice whether those shell wrappers should install the tool when it's missing, which can affect the first invocation and trigger a metadata download (see ghcup run --install).

I'd keep it off and print more verbose instructions.

hasufell avatar Mar 14 '24 03:03 hasufell