Building GHC 8.10.7 on riscv64 Ubuntu

The problem

A problem I discoverd after compiling the cardano-node for the first time is that the node would simply would not start. After some searching I learn there was no SMP support in GHC compiler that comes with the riscv64 version of Unbuntu 21.04 or 21.10.

There is a quick check if you can do to check if you can build a working cardano-node with the following steps.

You create a file named main.hs with the content below.

import Control.Concurrent
main = do
    setNumCapabilities 8
    putStrLn "Done"

Then compile and run it by running:

ghc -threaded main.hs

If you see the message main: setNumCapabilities: not supported on this platform the GHC compiler has no SMP support.

The solution

Luckily I found patches for the missing SMP support with OpenSUSE

  1. Download the GHC 8.10.7 sources from the haskell website.
  2. Download the patches
  3. Run the commands below
xz -d ghc-8.10.7-src.tar.xz
tar xvf ghc-8.10.7-src.tar
cd ghc-8.10.7/
tar xvf ../ghc-8.10.7-riscv-patches.tgz
patch -p 1 < Disable-unboxed-arrays.patch
patch -p 1 < riscv.patch
patch -p 1 < libatomic.patch
patch -p 1 < riscv-tntc.patch
patch -p 1 < riscv-llvm-extend.patch

mkdir $HOME/.local
CLANG=/usr/bin/clang ./configure --prefix=$HOME/.local
make install

Now we can compile the and run the executable again.

export PATH=$HOME/.local/bin:$PATH
ghc -threaded main.hs

You should only see the output Done if it all worked.

Next thing is to actually build the cardano-node by mostly following the instructions on coincashew after building cabal by yourself.

Photo by form PxHere

Related Articles


First Block!

We made our first block Hooray!! For every stake pool operator it&rsquo;s a happy and maybe a bit of a nerve wrecking …

Delegate to RV64 Keeping Cardano decentralized

Centralization has many forms, instruction set architecture is one, currently around x86 and ARM. This pool aims to add the RISC-V ISA as an extra choice.

Delegate to RV64