You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.6 KiB

3 years ago
  1. #+title: Installing stack on ARM 64 bit
  2. #+author: Annwan
  3. #+date: 2022:03:04
  4. #+options: h:1 num:nil toc:nil
  5. ** Why stack on ARM
  6. People might want to run Haskell applications on ARM devices like a
  7. Raspberry Pi. The Haskell compiler has supported the architecture
  8. through LLVM for a couple of year now, as well as the builtin dependency
  9. manager, Cabal. However the dependency management of Cabal is
  10. system-wide (or at least user wide) and, because all packages interact
  11. with each other, it can pose problems with compatibility.
  12. That is the problem that =stack= solves by allowing for reproducible,
  13. isolated environment for each project, and a lot of projects now use
  14. stack for their dependency and version management.
  15. However stack does not provide any build for arm systems, we thus need
  16. to install it another way
  17. ** First step, getting a compiler
  18. Whereas =stack= does not provide an ARM build, GHC does. so we first
  19. head to the [[https://www.haskell.org/ghc/][GHC download page]] and get the latest build. Usually the
  20. archive is for Debian, but should work for any GNU libc based
  21. distribution.
  22. #+begin_quote
  23. At time of writing stack lts snapshots don't use GHC 9 yet so the used
  24. version is 8.10.7.
  25. #+end_quote
  26. This should leave you with an archive like
  27. =ghc-8.10.7-aarch64-deb10-linux.tar.xz= (Keep that archive around, we
  28. will need it for stack later on).
  29. We are now going to extract and setup a minimal Haskell environment
  30. #+begin_src shell
  31. tar xvf ghc-8.10.7-aarch64-deb10-linux.tar.xz
  32. cd ghc-8.10.7
  33. ./configure --prefix=$HOME/.cabal
  34. make install
  35. #+end_src
  36. Next grab the latest cabal binary for AArch64 from [[https://www.haskell.org/cabal/download.html][Cabal download page]]
  37. (usually tagged as for Debian but should work on any GNU Libc system).
  38. Put the contained executable in =$HOME/.cabal/bin=
  39. Finally put =$HOME/.cabal/bin= in your PATH.
  40. You now have a minimal Haskell installation in your path, we are now
  41. ready to move to the next step
  42. ** Install a stack bootstrap environment
  43. Now that we can compile some Haskell things, lets install a bootstrap
  44. stack installation. It is not the final one, because this one is tied to
  45. a cabal version instead of a stack snapshot
  46. To do that we simply tell cabal to install stack
  47. #+begin_src shell
  48. cabal install stack
  49. #+end_src
  50. This compilation will take a bunch of memory, and most likely a while, if
  51. on a system with limited RAM, you might want to unmout the tmpfs at
  52. =/tmp= and increase the swap size in order to have around 4GB free
  53. ** Register the compiler with stack
  54. Remember when I said to keep the GHC archive around because we will need
  55. it later, well that later is now. Move that archive to a folder where
  56. you'll most likely not accidentally delete it, here I'll use =~/ghc=
  57. Once the archive is stored in that folder, open your stack configuration
  58. (=~/.stack/config.yaml=) and add the following
  59. #+begin_src yaml
  60. setup-info:
  61. ghc:
  62. linux-aarch64-tinfo6:
  63. 8.10.7:
  64. url: "~/ghc/ghc-8.10.7-aarch64-deb10-linux.tar.xz"
  65. #+end_src
  66. ** Finaly, bootstrap stack with itself
  67. Now we need to reinstall stack with itself, to untie it from the
  68. temporary setup.
  69. #+begin_src shell
  70. stack setup
  71. stack install stack
  72. #+end_src
  73. Once again this will take a lot of both memory and time.
  74. ** Clean up
  75. You can now remove the =~/.cabal/bin= folder and add the =~/.local/bin=
  76. folder to the path, that is where stack will install binaries.
  77. You can also delete the =~/.cabal= as it is no longer needed
  78. Once this is done, you now have a fully functionnal stack setup.
  79. If in the future you need an additionnal compiler version you can add
  80. its archive to the compilers folder and register it with stack the same
  81. way as previously done.