Skip to content

Implement 'ghcup run'

Julian Ospald requested to merge issue-137 into master

@RyanGlScott

$ ghcup run --help
Usage: ghcup run [-a|--append] [-i|--install] [--ghc GHC_VERSION]
                 [--cabal CABAL_VERSION] [--hls HLS_VERSION]
                 [--stack STACK_VERSION] [-b|--bindir DIR] [COMMAND]
  Run a command with the given tool in PATH

Available options:
  -a,--append              Append bin/ dir to PATH instead of prepending (this
                           means that e.g. a system installation may take
                           precedence)
  -i,--install             Install the tool, if missing
  --ghc GHC_VERSION        The ghc version
  --cabal CABAL_VERSION    The cabal version
  --hls HLS_VERSION        The HLS version
  --stack STACK_VERSION    The stack version
  -b,--bindir DIR          directory where to create the tool symlinks (default:
                           newly created system temp dir)
  COMMAND                  The command to run, with arguments (use longopts --).
                           If omitted, just prints the created bin/ dir to
                           stdout and exits.
  -h,--help                Show this help text

Discussion:
  Adds the given tools to a dedicated bin/ directory and adds them to PATH, exposing
  the relevant binaries, then executes a command.

Examples:
  # run VSCode with all latest toolchain exposed, installing missing versions if necessary
  ghcup run --ghc latest --cabal latest --hls latest --stack latest --install -- code Setup.hs

  # create a custom toolchain bin/ dir with GHC and cabal that can be manually added to PATH
  ghcup run --ghc 8.10.7 --cabal 3.2.0.0 --bindir $HOME/toolchain/bin

  # run a specific ghc version
  ghcup run --ghc 8.10.7 -- ghc --version

If command/arguments are omitted, it just prints the bindir (which by default is in a system temp dir) and exits. The bin dirs that are created are never cleaned up. Since they just contain symlinks, I think that's ok (ghcup gc -t can be used).

On linux, we use posix exec to spawn the process, which is cleaner.

Edited by Julian Ospald

Merge request reports