UP | HOME

The Haskell Stack

Fuck this shit.

You need ghc. The sane people back then had just one requiredment - being available in the $PATH.

$PATH is good, because it is a List. One could prepend elements to it, and this is the right thing to do.

There is also /opt. This is the place to store your semantically versioned directories.

You do

./configure --prefix=/opt/blah-blah-x.y.z && make && make install

and then you do

cd /opt
ln -s /opt/blah-blah-x.y.z /opt/blah-blah

And finally, when needed, you just

export PATH=/opt/blah-blah:$PATH

no fucking nix, snapd, flatpack or whatevery fucking degeneracy these idiots are trying to force on you.

Just plain directories and $PATH are still good-enough.

Anyway.

To build GHC you need the LLVM toolchain installed.

The build system is using (assume) ld.lld, ar and nm from LLVM, not from GNU binutils, so you do this:

export PATH=/usr/lib/llvm/15/bin:/usr/bin:$PATH

This is only for this terminal session, of course.

The ghc will use a C preprocessor. By default it will use gcc, but it is much better to reduce the number of dependencies.

export CC=clang
export CXX=clang++
export LD=ld.lld

so the ./configure script from ghc-x.y.z-src.tar.xz will use these (from /usr/lib/llvm/15/bin).

Now there is a problem – you need to have these already installed (in the $PATH):

The GHC toolchain comes with the bundled Cabal library, but without cabal-install (fucking degenerates!)

Modern versions of GHC require the hadrian package for building the GHC sources.

This will be automatically downloaded and built using already installed ghc and cabal. Where will you get these?

Oh, this is such a good question. Most of Linux distributions come with outdated versions of ghc, if at all. Gentoo still has 9.0.2, which is too old.

To build a modern GHC you need at least 9.2.x. So, you might get the binary distribution from the GHC download page.

But wait, the “binary distribution” needs GHC already installed. Surprise! It also needs the LLVM toolchain because it partially rebuilds and relinks itself.

Anyway, here is how you do it (having the proper version of LLVM early in the $PATH is crucial):

tar -xJf ghc-9.6.2-src.tar.xz
cd ghc-9.6.2

export PATH=/usr/lib/llvm/15/bin:/usr/bin:$PATH

export CC=clang
export CXX=clang++
export LD=ld.lld

./configure --prefix=/opt/ghc-9.6.2

hadrian/build binary-dist

Here the --prefix is irrelevant, it will be used when installing a binary distribution.

If you are using some custom CFLAGS and LDFLAGS for hardening, make sure there is no --as-needed and other shady thihgs.

This will produce a binary distribution package, which need to be configured and installed.


in %HOME/.bashrc

export PATH=/opt/ghc-9.6.2/bin:$HOME/.local/bin:/usr/local/bin:$PATH

The GHC compiler suite comes with the bundled set of libs, versioned with fucking hashes. Just as in the Cabal example, you better to use these libs.

Hashes for versioning

I cannot even properly express my boiling rage over this utter stupidity and degeneracy.

Instead of maintaining stable APIs and basic semantic versioning, degens came up with this.

OK, now you have gigabytes of crap sitting on your disk in varions places:

  • .cabal/store
  • .stack/snapshots
  • .stack-work

Try to build and install the haskell-language-server. You will see.

ghcup

There is a tool called ghcup https://www.haskell.org/ghcup/

With this you can get the cabal and stack statically linked binaries, which you will use to bootstrap all the required tools.

The point is to compile everything with your new GHC and the bundled libraries. It is not even possible to run hls any other way.

Stack

You need to check https://stackage.org for the lastest version of the resolver for your GHC.

in $HOME/.stack/config.yaml

system-ghc: true

allow-newer: true

in $HOME/.stack/global-project/stack.yaml

compiler: ghc-9.6.2
packages: []
resolver: nightly-2023-07-04

extra-deps:
- Cabal-3.10.1.0
- Cabal-syntax-3.10.1.0
- cabal-install-solver-3.10.1.0

cabal-install

stack update

stack install cabal-install

stack

stack install stack

This will give you lots of errors, so you have to add extra-deps to the global-project/stack.yaml file.

basic tools

stack install alex happy stylish-haskell fourmolu

haskell-language-server

This fucking abomination never compiles as intendend. Actually, this is a manifestation of what is wrong with the Haskell ecosystem and how everything is completely fucked by Chuds and narcissisitc idiots.

stack install haskell-language-server

At the time of writing shit does not even compile.

Author: <schiptsov@gmail.com>

Email: lngnmn2@yahoo.com

Created: 2023-08-08 Tue 18:37

Emacs 29.1.50 (Org mode 9.7-pre)