3.6 KiB
Installing stack on ARM 64 bit
Why stack on ARM
People might want to run Haskell applications on ARM devices like a Raspberry Pi. The Haskell compiler has supported the architecture through LLVM for a couple of year now, as well as the builtin dependency manager, Cabal. However the dependency management of Cabal is system-wide (or at least user wide) and, because all packages interact with each other, it can pose problems with compatibility.
That is the problem that stack
solves by allowing for reproducible,
isolated environment for each project, and a lot of projects now use
stack for their dependency and version management.
However stack does not provide any build for arm systems, we thus need to install it another way
First step, getting a compiler
Whereas stack
does not provide an ARM build, GHC does. so we first
head to the GHC download page and get the latest build. Usually the
archive is for Debian, but should work for any GNU libc based
distribution.
At time of writing stack lts snapshots don't use GHC 9 yet so the used version is 8.10.7.
This should leave you with an archive like
ghc-8.10.7-aarch64-deb10-linux.tar.xz
(Keep that archive around, we
will need it for stack later on).
We are now going to extract and setup a minimal Haskell environment
tar xvf ghc-8.10.7-aarch64-deb10-linux.tar.xz cd ghc-8.10.7 ./configure --prefix=$HOME/.cabal make install
Next grab the latest cabal binary for AArch64 from Cabal download page
(usually tagged as for Debian but should work on any GNU Libc system).
Put the contained executable in $HOME/.cabal/bin
Finally put $HOME/.cabal/bin
in your PATH.
You now have a minimal Haskell installation in your path, we are now ready to move to the next step
Install a stack bootstrap environment
Now that we can compile some Haskell things, lets install a bootstrap stack installation. It is not the final one, because this one is tied to a cabal version instead of a stack snapshot
To do that we simply tell cabal to install stack
cabal install stack
This compilation will take a bunch of memory, and most likely a while, if
on a system with limited RAM, you might want to unmout the tmpfs at
/tmp
and increase the swap size in order to have around 4GB free
Register the compiler with stack
Remember when I said to keep the GHC archive around because we will need
it later, well that later is now. Move that archive to a folder where
you'll most likely not accidentally delete it, here I'll use ~/ghc
Once the archive is stored in that folder, open your stack configuration
(~/.stack/config.yaml
) and add the following
setup-info: ghc: linux-aarch64-tinfo6: 8.10.7: url: "~/ghc/ghc-8.10.7-aarch64-deb10-linux.tar.xz"
Finaly, bootstrap stack with itself
Now we need to reinstall stack with itself, to untie it from the temporary setup.
stack setup stack install stack
Once again this will take a lot of both memory and time.
Clean up
You can now remove the ~/.cabal/bin
folder and add the ~/.local/bin
folder to the path, that is where stack will install binaries.
You can also delete the ~/.cabal
as it is no longer needed
Once this is done, you now have a fully functionnal stack setup.
If in the future you need an additionnal compiler version you can add its archive to the compilers folder and register it with stack the same way as previously done.