9

I would like to have different, non-ABI-compatible, builds of the same version of GHC, and use them in different projects.

(In my case, the difference between the builds is integer-simple vs gmp.)

The comments in this issue show how to add a custom flavor of ghc to stack-setup-2.yaml. But how do I specify which ghc build to use in each particular case or project?

I.e. I am looking for one (better yet, both) of:

  1. The ability to specify in stack.yaml whether to use the integer-simple or gmp build.
  2. The ability to specify, at stack build time, which build to produce.
Roman Cheplyaka
  • 37,738
  • 7
  • 72
  • 121
  • You can use the [`ghc-variant` option](https://docs.haskellstack.org/en/stable/yaml_configuration/#ghc-variant) or `--ghc-variant` flag. If you are on Windows and use [the default stack-setup-2.yaml](https://raw.githubusercontent.com/fpco/stackage-content/master/stack/stack-setup-2.yaml), building with `--ghc-variant integersimple` should use a different GHC than if you use `--ghc-variant standard`. – sjakobi Mar 09 '17 at 11:30
  • @sjakobi great, could you post this as an answer? – Roman Cheplyaka Mar 09 '17 at 11:45

4 Answers4

7

You can use the ghc-variant option or --ghc-variant flag.

If you are on Windows and use the default stack-setup-2.yaml, building with --ghc-variant integersimple should use a different GHC than if you use --ghc-variant standard.

sjakobi
  • 3,546
  • 1
  • 25
  • 43
5

The other answers are good, but here's a complete example so that you don't have to puzzle it together from the provided links.

Put this in your stack.yaml file:

resolver: lts-12.20

setup-info:
  ghc:
    linux64-custom-dwarf:
      8.4.4:
        url: "https://downloads.haskell.org/~ghc/8.4.4/ghc-8.4.4-x86_64-deb9-linux-dwarf.tar.xz"
        sha256: f9cac6e402c71d7251f2e22f412fb4abd72c64f34481a1e548cd7f6ff2352a07

ghc-variant: dwarf

Here in the setup-info part I provide the path to the bindist, a checksum (optional but recommended for reproducibility), and then say that I want to use this custom ghc with ghc-variant: dwarf (it seems to turn the dwarf in there into linux64-custom-dwarf by appending the word to linux64-custom-).

If you want to share the definition of that custom ghc across projects, you can also put the setup-info part into $HOME/.stack/config.yaml.


Note for GHC hackers: If you want to hack on ghc itself and iterate quickly on your packages with frequently updated GHC, then this approach where you just override the GHC binary instead of declaring a fully built bindist is better (because you don't have to build a bindist every time you recompile).

nh2
  • 24,526
  • 11
  • 79
  • 128
2

For people who want to try a different ghc version and not an entirely different build alltogether the --compiler flag is useful https://docs.haskellstack.org/en/stable/yaml_configuration/#compiler

Also take a look at this answer https://stackoverflow.com/a/35472448/1833322 which talks about the --ghc-variant flag

And to be complete, here is the talk about the implementation of these flags:

This is useful to know since this stackoverflow question is the first page in google results.

Flip
  • 4,778
  • 1
  • 34
  • 48
1

To whoever needs this again, I'll leave a recipe to install musl bindist using Stack (GHC 8.6.5 on Alpine) — as another example/variation of what OP has asked.

First, locate a bindist (binary distribution) at e.g. https://github.com/commercialhaskell/ghc/releases
I needed to pick the musl libc variant.

Fill that into setup-info section in ~/.stack/config.yaml and specify ghc-variant:

setup-info:
  ghc:
    linux64-custom-musl-ncurses6:
      8.6.5:
        url: "https://github.com/commercialhaskell/ghc/releases/download/ghc-8.6.5-release/ghc-8.6.5-x86_64-unknown-linux-musl.tar.xz"
        content-length: 140167348
        sha1: 3ce575af840e886ba5d2641f68577ace38ac21c6
        sha256: ec6d0417822c3bfafc7aea0b0402294901231bc5d72dd17a2b849e3f44850695

ghc-variant: musl

With that, installing the GHC variant is as simple as:

stack setup \
    --install-ghc \
    --resolver=$RESOLVER_CHOICE \
    --ghc-variant musl \
    8.6.5
ulidtko
  • 14,740
  • 10
  • 56
  • 88