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:
stack.yaml
whether to use the integer-simple or gmp build.stack build
time, which build to produce.stack ghci allows you to load components and files of your project into ghci . It uses the same TARGET syntax as stack build , and can also take options like --test , --bench , and --flag . Similarly to stack build , the default is to load up ghci with all libraries and executables in the project.
You can find these sandboxed GHC installations in the ghc-* directories in the stack path --programs directory. If you would like Stack to use your system GHC installation, use the --system-ghc flag or run stack config set system-ghc --global true to make Stack check your PATH for a suitable GHC by default.
AFAIU stack is handy to quickly work on an existing project. If you start something from scratch, you will certainly have to use cabal.
stack build takes a list of one or more optional targets to be built. The supported syntaxes for targets are: package, e.g. stack build foobar , is the most commonly used target. It will try to find the package in the following locations: local packages, extra deps, snapshots, and package index (e.g. Hackage).
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).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With