Index

How to Build PureScript on Raspberry Pi 3b

These are the steps I used to build PureScript on a Raspberry Pi model 3b. Your mileage may vary.

Setting up the Pi

Install Raspbian Stretch from https://www.raspberrypi.org/downloads/raspbian/ to a micro-SD card. The capacity has to be at least 32GB.

Normally there’s only 100MB of swap space on Raspbian; that is not enough. So, do this:

  1. Stop swapping:
    sudo /etc/init.d/dphys-swapfile stop
  2. Change the file /etc/dphys-swapfile to change the size of the swap area by updating the line with CONF_SWAPSIZE to:
    CONF_SWAPSIZE=4096
    (This should give you 4GB of swap space, but it appears you get a maximum of 2GB. That’s sufficient, so let’s go with it.)
  3. Restart swapping:
    sudo /etc/init.d/dphys-swapfile start

Before you build PureScript

PureScript is written in Haskell, so you need the Glasgow Haskell Compiler (GHC):

sudo apt-get install ghc

After this, you can install stack (a tool for developing Haskell projects), as shown at https://docs.haskellstack.org/en/stable/install_and_upgrade/:

wget -qO- https://get.haskellstack.org/ | sh

Then update stack’s package index:

stack update

You will need nodejs and npm later, so:

sudo apt-get install nodejs npm

You will definitely need clang and LLVM 3.9, downloadable from http://releases.llvm.org/download.html#3.9.0; this also needs ncurses 6.0, which you may download at http://ftp.gnu.org/gnu/ncurses/.

Here are the commands for building ncurses:

export CPPFLAGS="-P" # avoids a build error
./configure --with-shared --without-debug --enable-widec # allows UTF-8 support 
make
sudo make install

Building Purescript

Make a clone of PureScript and switch to the directory thus created:

git clone https://github.com/purescript/purescript.git
cd purescript

The version of GHC that you installed is version 8.0.1, but the PureScript build requires version 8.2.1, so stack will need to bring it in (this will take a while to download and install into an isolated location):

stack setup

The build instructions say to use the command stack install, but that will try building in parallel with several jobs at once. You have only one core anyway, so build with this instruction:

stack install --flag purescript:RELEASE --jobs 1

This will take a very long time. When I built PureScript, everything went great up until the following point, with output reformatted to fit on the screen more nicely:

[136 of 149] Compiling Language.PureScript.Ide.Reexports
    ( src/Language/PureScript/Ide/Reexports.hs,
    .stack-work/dist/arm-linux/Cabal-2.0.0.2/build/Language/PureScript/Ide/Reexports.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 8.2.1 for arm-unknown-linux):
        expectJust cpeBody:collect_args
CallStack (from HasCallStack):
  error, called at compiler/utils/Maybes.hs:53:27 in ghc:Maybes
  expectJust, called at compiler/coreSyn/CorePrep.hs:888:32 in ghc:CorePrep
                 
Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
                 
Completed 155 action(s).

--  While building package purescript-0.11.7 using:
      /home/pi/.stack/setup-exe-cache/arm-linux/Cabal-simple_mPHDZzAJ_2.0.0.2_ghc-8.2.1
      --builddir=.stack-work/dist/arm-linux/Cabal-2.0.0.2 build lib:purescript
      exe:purs --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1

Well, fine. I just restarted the build process by issuing the preceding stack install command, and it completed successfully.

Installing pulp

Use npm to install pulp, the build tool for PureScript:

npm install -g pulp

Building psc-package

You will also need to build psc-package, which is the preferred package manager for building PureScript projects. Do a git clone https://github.com/purescript/psc-package and then stack install (this time you don’t need to use a --jobs 1 in this case.

Building Your First PureScript Project

Create a new project skeleton with pulp:

mkdir project
cd project
pulp init

This will create a project, but it will also give you an error:

* Generating project skeleton in /home/pi/project
Initializing new project in current directory
Using the default package set for PureScript compiler version 0.11.7
(Use --source / --set to override this behavior)
warning: Could not find remote branch psc-0.11.7 to clone.
fatal: Remote branch psc-0.11.7 not found in upstream origin
* ERROR: Subcommand terminated with exit code 1

The problem is that you have built PureScript version 0.11.7, but psc-package is at version 0.11.6. Edit the file psc-package.json to change the line with "set" to:

  "set": "psc-0.11.6"

Then update:

psc-package update

You will also need the Console package to build this project, and, if you want to use psci (the PureScript REPL), you will also need its support package:

psc-package install console
psc-package install psci-support
pulp run

If everything went according to plan, you are in business.

You can contact me by email, but this is more of a proof-of-concept at the moment than a full-time project, so I may not be able to assist you with fixing bugs.

Acknowledgments

Thanks to @kritzcreek and @jkachmar in the functionalprogramming Slack channel for helping me get the pulp vs. psc-package problem resolved.