From c6d6deaf873a6f25414e31b345c6f5d6d7141f00 Mon Sep 17 00:00:00 2001 From: Antoine COMBET Date: Fri, 4 Mar 2022 19:09:42 +0100 Subject: [PATCH] Stack on ARM writeup --- stack-arm.org | 99 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 5 deletions(-) diff --git a/stack-arm.org b/stack-arm.org index 319cba6..8e2e2a8 100644 --- a/stack-arm.org +++ b/stack-arm.org @@ -1,11 +1,11 @@ -#+title: Installing stack on ARM64 +#+title: Installing stack on ARM bit #+author: Annwan #+date: 2022:03:04 #+options: h:1 num:nil toc:nil ** Why stack on ARM -People might want to run haskell applications on ARM devices like a +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 @@ -13,13 +13,102 @@ 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 environement for each project, and a lot of projects now use +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 anoter way +to install it another way ** Contents -#+TOC: headlines 1 +#+TOC +** First step, getting a compiler + +Whereas =stack= does not provide an ARM build, GHC does. so we first +head to the [[https://www.haskell.org/ghc/][GHC download page]] and get the latest build. Usually the +archive is for Debian, but should work for any GNU libc based +distribution. +#+begin_quote +At time of writing stack doesn't handle GHC 9 properly yet so the used +version is 8.10.7. +#+end_quote +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 + +#+begin_src shell +tar xvf ghc-8.10.7-aarch64-deb10-linux.tar.xz +cd ghc-8.10.7 +./configure --prefix=$HOME/.cabal +make install +#+end_src + +Next grab the latest cabal binary for AArch64 from [[https://www.haskell.org/cabal/download.html][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 + +#+begin_src shell +cabal install stack +#+end_src + +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 + +#+begin_src yaml +setup-info: + ghc: + linux-aarch64-tinfo6: + 8.10.7: + url: "~/ghc/ghc-8.10.7-aarch64-deb10-linux.tar.xz" +#+end_src + +** Finaly, bootstrap stack with itself + +Now we need to reinstall stack with itself, to untie it from the +temporary setup. + +#+begin_src shell +stack setup +stack install stack +#+end_src + +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.